Skip to contentSkip to conversation

sr: dwc2/gadget: remove unneccessary if

PATCH In review Pavel Machek 2 participants 4 messages Jun 6, 2020 – Jun 9, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sr: dwc2/gadget: remove unneccessary if

We don't really need if/else to set variable to 1/0.

drivers/usb/dwc2/gadget.c +1 -4
index 12b98b466287..f9f6fd470c81 100644
@@ -1761,10 +1761,7 @@ static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg,
 	case USB_RECIP_DEVICE:
 		switch (wValue) {
 		case USB_DEVICE_REMOTE_WAKEUP:
-			if (set)
-				hsotg->remote_wakeup_allowed = 1;
-			else
-				hsotg->remote_wakeup_allowed = 0;
+			hsotg->remote_wakeup_allowed = set;
 			break;
 
 		case USB_DEVICE_TEST_MODE:
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#1 lore raw

Hi Pavel,

Quoted 11 lines · Pavel Machek

We don't really need if/else to set variable to 1/0.

drivers/usb/dwc2/gadget.c +0 -0
index 12b98b466287..f9f6fd470c81 100644
@@ -1761,10 +1761,7 @@ static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg,
  	case USB_RECIP_DEVICE:

drivers/usb/dwc2/gadget.c static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, · line 1767

Quoted 10 lines
drivers/usb/dwc2/gadget.c +1 -4
  		switch (wValue) {
  		case USB_DEVICE_REMOTE_WAKEUP:
-			if (set)
-				hsotg->remote_wakeup_allowed = 1;
-			else
-				hsotg->remote_wakeup_allowed = 0;
+			hsotg->remote_wakeup_allowed = set;
  			break;
 
  		case USB_DEVICE_TEST_MODE:

It's good catch, but 'set' declared as 'bool' while 'remote_wakeup_allowed' is 'unsigned int'. Maybe update 'set' type to same.

Thanks,
Minas

#2 lore raw

Hi!

Quoted 19 lines
Quoted 19 lines

We don't really need if/else to set variable to 1/0.

drivers/usb/dwc2/gadget.c +1 -4
index 12b98b466287..f9f6fd470c81 100644
@@ -1761,10 +1761,7 @@ static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg,
  	case USB_RECIP_DEVICE:
  		switch (wValue) {
  		case USB_DEVICE_REMOTE_WAKEUP:
-			if (set)
-				hsotg->remote_wakeup_allowed = 1;
-			else
-				hsotg->remote_wakeup_allowed = 0;
+			hsotg->remote_wakeup_allowed = set;
  			break;
 
Quoted 5 lines

drivers/usb/dwc2/gadget.c static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, · line 1767

Quoted 2 lines
drivers/usb/dwc2/gadget.c +0 -0
  		case USB_DEVICE_TEST_MODE:

It's good catch, but 'set' declared as 'bool' while 'remote_wakeup_allowed' is 'unsigned int'. Maybe update 'set' type to same.

I know set is bool. But that should not matter, code is okay and compiler will do the right thing:

pavel@amd:/tmp$ cat delme.c
#include <stdbool.h>

void main(void)
{

  bool a = false;
    int b = a;
 }
 pavel@amd:/tmp$ gcc -std=c99 -Wall delme.c
    delme.c:3:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
     void main(void)
           ^
	   delme.c: In function ‘main’:
 delme.c:6:7: warning: unused variable ‘b’
 [-Wunused-variable]
	      int b = a;
	             ^

Best regards,
Pavel

Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#3 lore raw

Hi,

Quoted 48 lines · Pavel Machek

Hi!

Quoted 19 lines
Quoted 19 lines

We don't really need if/else to set variable to 1/0.

drivers/usb/dwc2/gadget.c +1 -4
index 12b98b466287..f9f6fd470c81 100644
@@ -1761,10 +1761,7 @@ static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg,
   	case USB_RECIP_DEVICE:
   		switch (wValue) {
   		case USB_DEVICE_REMOTE_WAKEUP:
-			if (set)
-				hsotg->remote_wakeup_allowed = 1;
-			else
-				hsotg->remote_wakeup_allowed = 0;
+			hsotg->remote_wakeup_allowed = set;
   			break;
 
Quoted 5 lines

drivers/usb/dwc2/gadget.c static int dwc2_hsotg_process_req_feature(struct dwc2_hsotg *hsotg, · line 1767

Quoted 2 lines
drivers/usb/dwc2/gadget.c +0 -0
   		case USB_DEVICE_TEST_MODE:

It's good catch, but 'set' declared as 'bool' while 'remote_wakeup_allowed' is 'unsigned int'. Maybe update 'set' type to same.

I know set is bool. But that should not matter, code is okay and compiler will do the right thing:

pavel@amd:/tmp$ cat delme.c
#include <stdbool.h>

void main(void)

{
   bool a = false;
     int b = a;
  }
  pavel@amd:/tmp$ gcc -std=c99 -Wall delme.c
     delme.c:3:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
      void main(void)
            ^
	   delme.c: In function ‘main’:
  delme.c:6:7: warning: unused variable ‘b’
  [-Wunused-variable]
	      int b = a;
	             ^
Quoted 3 lines

Best regards,
Pavel

To avoid any possible check patch issues update type of "set" from bool to same as "remote_wakeup_allowed".
Please update your patch topic to "usb: dwc2: gadget: remove unnecessary if" and resubmit.

Thanks,
Minas