linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gspca: correctly checked failed allocation
@ 2015-10-19 16:43 Insu Yun
  2015-10-20  8:20 ` Hans de Goede
  0 siblings, 1 reply; 2+ messages in thread
From: Insu Yun @ 2015-10-19 16:43 UTC (permalink / raw)
  To: hdegoede, mchehab, linux-media, linux-kernel
  Cc: taesoo, yeongjin.jang, insu, changwoo, Insu Yun

create_singlethread_workqueue can be failed in memory pressue.
So, check return value and return -ENOMEM

Signed-off-by: Insu Yun <wuninsu@gmail.com>
---
 drivers/media/usb/gspca/sq905.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/usb/gspca/sq905.c b/drivers/media/usb/gspca/sq905.c
index a7ae0ec..b1c25d9a 100644
--- a/drivers/media/usb/gspca/sq905.c
+++ b/drivers/media/usb/gspca/sq905.c
@@ -392,6 +392,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
 	}
 	/* Start the workqueue function to do the streaming */
 	dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
+	if (!dev->work_thread)
+		return -ENOMEM;
 	queue_work(dev->work_thread, &dev->work_struct);
 
 	return 0;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gspca: correctly checked failed allocation
  2015-10-19 16:43 [PATCH] gspca: correctly checked failed allocation Insu Yun
@ 2015-10-20  8:20 ` Hans de Goede
  0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2015-10-20  8:20 UTC (permalink / raw)
  To: Insu Yun, mchehab, linux-media, linux-kernel
  Cc: taesoo, yeongjin.jang, insu, changwoo

Hi,

On 19-10-15 18:43, Insu Yun wrote:
> create_singlethread_workqueue can be failed in memory pressue.
> So, check return value and return -ENOMEM
>
> Signed-off-by: Insu Yun <wuninsu@gmail.com>
> ---
>   drivers/media/usb/gspca/sq905.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/media/usb/gspca/sq905.c b/drivers/media/usb/gspca/sq905.c
> index a7ae0ec..b1c25d9a 100644
> --- a/drivers/media/usb/gspca/sq905.c
> +++ b/drivers/media/usb/gspca/sq905.c
> @@ -392,6 +392,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
>   	}
>   	/* Start the workqueue function to do the streaming */
>   	dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
> +	if (!dev->work_thread)
> +		return -ENOMEM;
>   	queue_work(dev->work_thread, &dev->work_struct);
>
>   	return 0;

If the thread creation fails we should not send the start command,
so the create_singlethread_workqueue call should be moved
up in the function, while keeping the queue_work at the end.

And if the sq905_command fails then the workqueue should
be destroyed and dev->work_thread should be set to NULL
before returning the sq905_command failure to the caller.

Regards,

Hans

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-20  8:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-19 16:43 [PATCH] gspca: correctly checked failed allocation Insu Yun
2015-10-20  8:20 ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).