Skip to contentSkip to conversation

usb: gadget: compress return logic into one line

PATCH New Gustavo A. R. Silva 1 participant 2 messages Jul 10, 2017 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 usb: gadget: compress return logic into one line

Simplify return logic to avoid unnecessary variable declaration and assignment.

This issue was detected using Coccinelle and the following semantic patch:

@@
local idexpression ret;
expression e;
@@

-ret =
+return

     e;

-return ret;

---
 drivers/usb/gadget/config.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/gadget/config.c +1 -3
index 17a6077..23bfa7d 100644
@@ -207,7 +207,6 @@ EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
 struct usb_descriptor_header *usb_otg_descriptor_alloc(
 				struct usb_gadget *gadget)
 {
-	struct usb_descriptor_header *otg_desc;
 	unsigned length = 0;
 
 	if (gadget->otg_caps && (gadget->otg_caps->otg_rev >= 0x0200))
@@ -215,8 +214,7 @@ struct usb_descriptor_header *usb_otg_descriptor_alloc(
 	else
 		length = sizeof(struct usb_otg_descriptor);
 
-	otg_desc = kzalloc(length, GFP_KERNEL);
-	return otg_desc;
+	return kzalloc(length, GFP_KERNEL);
 }
 EXPORT_SYMBOL_GPL(usb_otg_descriptor_alloc);
 
Signature · 1 line
2.5.0
#1 lore raw

PATCH 2/2 usb: gadget: use unsigned int instead of unsigned in usb_otg_descriptor_alloc()

Prefer unsigned int to bare use of unsigned.

---
 drivers/usb/gadget/config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/config.c +1 -1
index 23bfa7d..968179d 100644
@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
 struct usb_descriptor_header *usb_otg_descriptor_alloc(
 				struct usb_gadget *gadget)
 {
-	unsigned length = 0;
+	unsigned int length = 0;
 
 	if (gadget->otg_caps && (gadget->otg_caps->otg_rev >= 0x0200))
 		length = sizeof(struct usb_otg20_descriptor);
Signature · 1 line
2.5.0