Skip to contentSkip to conversation

m5602: correctly check failed thread creation

PATCH In review Insu Yun 2 participants 2 messages Oct 19, 2015 – Oct 20, 2015

Subsystems (3)
lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 m5602: correctly check failed thread creation

Since thread creation can be failed, check return value of kthread_create and handle an error.

---
 drivers/media/usb/gspca/m5602/m5602_s5k83a.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/usb/gspca/m5602/m5602_s5k83a.c +7 -1
index bf6b215..76b40d1 100644
@@ -221,6 +221,10 @@ int s5k83a_start(struct sd *sd)
 	   to assume that there is no better way of accomplishing this */
 	sd->rotation_thread = kthread_create(rotation_thread_function,
 					     sd, "rotation thread");
+	if (IS_ERR(sd->rotation_thread)) {
+		err = PTR_ERR(sd->rotation_thread);
+		goto fail;
+	}
 	wake_up_process(sd->rotation_thread);
 
 	/* Preinit the sensor */
@@ -234,9 +238,11 @@ int s5k83a_start(struct sd *sd)
 				data[0]);
 	}
 	if (err < 0)
-		return err;
+		goto fail;
 
 	return s5k83a_set_led_indication(sd, 1);
+fail:
+	return err;
 }
 
 int s5k83a_stop(struct sd *sd)
Signature · 1 line
1.9.1
#1 lore raw

Hi,

Quoted 13 lines · Insu Yun

Since thread creation can be failed, check return value of kthread_create and handle an error.

---
  drivers/media/usb/gspca/m5602/m5602_s5k83a.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/usb/gspca/m5602/m5602_s5k83a.c +0 -0
index bf6b215..76b40d1 100644

drivers/media/usb/gspca/m5602/m5602_s5k83a.c int s5k83a_start(struct sd *sd) · line 227

Quoted 7 lines
drivers/media/usb/gspca/m5602/m5602_s5k83a.c +4 -0
@@ -221,6 +221,10 @@ int s5k83a_start(struct sd *sd)
  	   to assume that there is no better way of accomplishing this */
  	sd->rotation_thread = kthread_create(rotation_thread_function,
  					     sd, "rotation thread");
+	if (IS_ERR(sd->rotation_thread)) {
+		err = PTR_ERR(sd->rotation_thread);
+		goto fail;
+	}

There is no need to use a goto here you can simply directly return the error.

drivers/media/usb/gspca/m5602/m5602_s5k83a.c int s5k83a_start(struct sd *sd) · line 241

Quoted 9 lines
drivers/media/usb/gspca/m5602/m5602_s5k83a.c +1 -1
  	wake_up_process(sd->rotation_thread);
 
  	/* Preinit the sensor */
@@ -234,9 +238,11 @@ int s5k83a_start(struct sd *sd)
  				data[0]);
  	}
  	if (err < 0)
-		return err;
+		goto fail;

No need for introducing a goto here either.

drivers/media/usb/gspca/m5602/m5602_s5k83a.c int s5k83a_start(struct sd *sd) · line 248

Quoted 7 lines
drivers/media/usb/gspca/m5602/m5602_s5k83a.c +2 -0
  	return s5k83a_set_led_indication(sd, 1);
+fail:
+	return err;
  }
 
  int s5k83a_stop(struct sd *sd)

Regards,

Hans