Re: [PATCH 4.4 125/190] [media] cx25840: fix unchecked return values

From: Ben Hutchings
Date: Tue May 15 2018 - 21:10:57 EST


On Wed, 2018-04-11 at 20:36 +0200, Greg Kroah-Hartman wrote:
> 4.4-stable review patch.ÂÂIf anyone has any objections, please let me know.
>
> ------------------
>
> From: Pan Bian <bianpan2016@xxxxxxx>
>
>
> [ Upstream commit 35378ce143071c2a6bad4b59a000e9b9f8f6ea67 ]
>
> In functions cx25840_initialize(), cx231xx_initialize(), and
> cx23885_initialize(), the return value of create_singlethread_workqueue()
> is used without validation. This may result in NULL dereference and cause
> kernel crash. This patch fixes it.
[...]
> --- a/drivers/media/i2c/cx25840/cx25840-core.c
> +++ b/drivers/media/i2c/cx25840/cx25840-core.c
> @@ -420,11 +420,13 @@ static void cx25840_initialize(struct i2
> Â INIT_WORK(&state->fw_work, cx25840_work_handler);
> Â init_waitqueue_head(&state->fw_wait);
> Â q = create_singlethread_workqueue("cx25840_fw");
> - prepare_to_wait(&state->fw_wait, &wait, TASK_UNINTERRUPTIBLE);
> - queue_work(q, &state->fw_work);
> - schedule();
> - finish_wait(&state->fw_wait, &wait);
> - destroy_workqueue(q);
> + if (q) {
> + prepare_to_wait(&state->fw_wait, &wait, TASK_UNINTERRUPTIBLE);
> + queue_work(q, &state->fw_work);
> + schedule();
> + finish_wait(&state->fw_wait, &wait);
> + destroy_workqueue(q);
> + }
[...]

Why is the error "handled" by skipping part of the initialisation
process? Shouldn't we abort and return an error?

Why even create a private workqueue, when we don't do anything that
wouldn't work with one of the global workqueues?

Why even use a workqueue, if we immediately block waiting for the work
to finish? This makes no sense to me.

Ben.

--
Ben Hutchings
Software Developer, Codethink Ltd.