gspca: correctly checked failed allocation
Subsystems (2)
PATCH 1/1 gspca: correctly checked failed allocation
create_singlethread_workqueue can be failed in memory pressue. So, check return value and return -ENOMEM
Signed-off-by Insu Yun <[email protected]>
--- drivers/media/usb/gspca/sq905.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/usb/gspca/sq905.c +2 -0
@@ -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 ;
Signature · 1 line
1.9.1
Hi,
Quoted 13 lines · Insu Yun
create_singlethread_workqueuecan be failed in memory pressue. So, check return value and return-ENOMEMSigned-off-by Insu Yun <[email protected]>--- drivers/media/usb/gspca/sq905.c | 2 ++ 1 file changed, 2 insertions(+)drivers/media/usb/gspca/sq905.c +0
-0
drivers/media/usb/gspca/sq905.c static int sd_start(struct gspca_dev *gspca_dev) · line 399
Quoted 8 lines
drivers/media/usb/gspca/sq905.c +2
-0@@ -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