Skip to contentSkip to conversation

usb: move assignment out of if condition

PATCH Superseded Kris Borer 4 participants 4 messages Jun 30, 2015 USB

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Kris Borer

author
#0 lore raw

PATCH 1/1 usb: move assignment out of if condition

Fix four occurrences of the checkpatch.pl error:

ERROR: do not use assignment in if condition

---
 drivers/usb/core/hcd.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/core/hcd.c +8 -5
index be5b207..e268c45 100644
@@ -2683,12 +2683,13 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	 * bottom up so that hcds can customize the root hubs before hub_wq
 	 * starts talking to them.  (Note, bus id is assigned early too.)
 	 */
-	if ((retval = hcd_buffer_create(hcd)) != 0) {
+	retval = hcd_buffer_create(hcd);
+	if (retval != 0) {
 		dev_dbg(hcd->self.controller, "pool alloc failed\n");
 		goto err_create_buf;
 	}
-
-	if ((retval = usb_register_bus(&hcd->self)) < 0)
+	retval = usb_register_bus(&hcd->self);
+	if (retval < 0)
 		goto err_register_bus;
 
 	rhdev = usb_alloc_dev(NULL, &hcd->self, 0);
@@ -2734,7 +2735,8 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	/* "reset" is misnamed; its role is now one-time init. the controller
 	 * should already have been reset (and boot firmware kicked off etc).
 	 */
-	if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
+	retval = hcd->driver->reset(hcd);
+	if (hcd->driver->reset && retval < 0) {
 		dev_err(hcd->self.controller, "can't setup: %d\n", retval);
 		goto err_hcd_driver_setup;
 	}
@@ -2766,7 +2768,8 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	}
 
 	/* starting here, usbcore will pay attention to this root hub */
-	if ((retval = register_root_hub(hcd)) != 0)
+	retval = register_root_hub(hcd);
+	if (retval != 0)
 		goto err_register_root_hub;
 
 	retval = sysfs_create_group(&rhdev->dev.kobj, &usb_bus_attr_group);
Signature · 1 line
1.9.1
#1 lore raw

Hello.

Quoted 13 lines · Kris Borer

Fix four occurrences of the checkpatch.pl error:

ERROR: do not use assignment in if condition

---
  drivers/usb/core/hcd.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/core/hcd.c +0 -0
index be5b207..e268c45 100644

[...]

drivers/usb/core/hcd.c int usb_add_hcd(struct usb_hcd *hcd, · line 2739

Quoted 7 lines
drivers/usb/core/hcd.c +2 -1
@@ -2734,7 +2735,8 @@ int usb_add_hcd(struct usb_hcd *hcd,
  	/* "reset" is misnamed; its role is now one-time init. the controller
  	 * should already have been reset (and boot firmware kicked off etc).
  	 */
-	if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
+	retval = hcd->driver->reset(hcd);
+	if (hcd->driver->reset && retval < 0) {

If hcd->driver->reset() is NULL, this change warrants a kernel oops.

[...]

WBR, Sergei

#2 lore raw
In reply to Kris Borer
Quoted 5 lines · Kris Borer

Fix four occurrences of the checkpatch.pl error:

ERROR: do not use assignment in if condition

Sorry, but NACK!
Those patches are totally broken.

Quoted 26 lines
---
 drivers/usb/core/hcd.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/usb/core/hcd.c +4 -3
index be5b207..e268c45 100644
@@ -2683,12 +2683,13 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	 * bottom up so that hcds can customize the root hubs before hub_wq
 	 * starts talking to them.  (Note, bus id is assigned early too.)
 	 */
-	if ((retval = hcd_buffer_create(hcd)) != 0) {
+	retval = hcd_buffer_create(hcd);
+	if (retval != 0) {
 		dev_dbg(hcd->self.controller, "pool alloc failed\n");
 		goto err_create_buf;
 	}
-
-	if ((retval = usb_register_bus(&hcd->self)) < 0)
+	retval = usb_register_bus(&hcd->self);
+	if (retval < 0)
 		goto err_register_bus;
 
 	rhdev = usb_alloc_dev(NULL, &hcd->self, 0);

drivers/usb/core/hcd.c int usb_add_hcd(struct usb_hcd *hcd, · line 2738

Quoted 5 lines
drivers/usb/core/hcd.c +1 -1
@@ -2734,7 +2735,8 @@ int usb_add_hcd(struct usb_hcd *hcd,
 	/* "reset" is misnamed; its role is now one-time init. the controller
 	 * should already have been reset (and boot firmware kicked off etc).
 	 */
-	if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
+	retval = hcd->driver->reset(hcd);

You happily follow the NULL pointer.

Regards
Oliver

maintainer
#3 lore raw
In reply to Kris Borer
Quoted 3 lines · Kris Borer

Fix four occurrences of the checkpatch.pl error:

ERROR: do not use assignment in if condition

If you are going to do stuff like this, use Coccinelle so you are sure you don't break the code.

Also always test your changes, if possible.

greg k-h