Skip to contentSkip to conversation

Staging/octeon-usb/octeon-hcd.c: Compression of lines for immediate return This patch compresses two lines in to a single line in file octeon-hcd.c

PATCH In review Nadim almas 3 participants 3 messages Jul 22, 2016 – Jul 23, 2016

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

PATCH 32/32 Staging/octeon-usb/octeon-hcd.c: Compression of lines for immediate return This patch compresses two lines in to a single line in file octeon-hcd.c

if immediate return statement is found. It also removes variable bytes_written as
it is no longer needed.

It is done using script Coccinelle. And coccinelle uses following semantic
patch for this compression function:

@@
expression ret;
identifier f;
@@

-ret =
+return

     f(...);

-return ret;

---
 Makefile                                |  2 +-
 drivers/staging/octeon-usb/octeon-hcd.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
Makefile +1 -1
index 4fb6bea..3d9d77a6 100644
@@ -1,7 +1,7 @@
 VERSION = 4
 PATCHLEVEL = 7
 SUBLEVEL = 0
-EXTRAVERSION = -rc4
+EXTRAVERSION = -eudyptula-rc4
 NAME = Psychotic Stoned Sheep
 
 # *DOCUMENTATION*
drivers/staging/octeon-usb/octeon-hcd.c +8 -8
index 17442b3..b801c8a 100644
@@ -508,15 +508,15 @@ static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 {
 	int ret;
 
-	ret = octeon_alloc_temp_buffer(urb, mem_flags);
-	if (ret)
-		return ret;
+     
+	if (octeon_alloc_temp_buffer(urb, mem_flags))
+		return octeon_alloc_temp_buffer(urb, mem_flags);
 
-	ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
-	if (ret)
+
+	if (usb_hcd_map_urb_for_dma(hcd, urb, mem_flags))
 		octeon_free_temp_buffer(urb);
 
-	return ret;
+	return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
 }
 
 /**
@@ -542,8 +542,8 @@ static void octeon_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
  */
 static inline u32 cvmx_usb_read_csr32(struct octeon_hcd *usb, u64 address)
 {
-	u32 result = cvmx_read64_uint32(address ^ 4);
-	return result;
+	 
+	return cvmx_read64_uint32(address ^ 4);
 }
 
 /**
Signature · 1 line
2.7.4
#1 lore raw

Nadim,

several points stand out in your patch:

Quoted 13 lines · Nadim almas

if immediate return statement is found. It also removes variable bytes_written as
it is no longer needed.

It is done using script Coccinelle. And coccinelle uses following semantic
patch for this compression function:

@@
expression ret;
identifier f;
@@

Review

Quoted 4 lines
(quoted diff) +1 -2
-ret =
+return
     f(...);
-return ret;

The commit message is malformed. Start a new paragraph for the longer description of what you are doing after the short one.

Quoted 3 lines

If Julia acked this patch she probably should be copied on this mail.

Quoted 10 lines
---
 Makefile                                |  2 +-
 drivers/staging/octeon-usb/octeon-hcd.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
Makefile +0 -0
index 4fb6bea..3d9d77a6 100644

Makefile line 4

Quoted 5 lines
Makefile +1 -1
@@ -1,7 +1,7 @@
 VERSION = 4
 PATCHLEVEL = 7
 SUBLEVEL = 0
-EXTRAVERSION = -rc4
+EXTRAVERSION = -eudyptula-rc4

No need to change this.

Quoted 8 lines
Makefile +0 -0
 NAME = Psychotic Stoned Sheep
 
 # *DOCUMENTATION*
drivers/staging/octeon-usb/octeon-hcd.c +0 -0
index 17442b3..b801c8a 100644

drivers/staging/octeon-usb/octeon-hcd.c static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · line 513

Quoted 9 lines
drivers/staging/octeon-usb/octeon-hcd.c +3 -3
@@ -508,15 +508,15 @@ static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 {
 	int ret;
 
-	ret = octeon_alloc_temp_buffer(urb, mem_flags);
-	if (ret)
-		return ret;
+     
+	if (octeon_alloc_temp_buffer(urb, mem_flags))
+		return octeon_alloc_temp_buffer(urb, mem_flags);

This cannot possibly be correct! You are calling a function with side effects twice. The first call in the condition might fail while the call in the return statement might succeed, never minding the wastefulness of two identical calls. Besides, the original code here seems fine to me.

drivers/staging/octeon-usb/octeon-hcd.c static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · line 520

Quoted 10 lines
drivers/staging/octeon-usb/octeon-hcd.c +3 -3
-	ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
-	if (ret)
+
+	if (usb_hcd_map_urb_for_dma(hcd, urb, mem_flags))
 		octeon_free_temp_buffer(urb);
 
-	return ret;
+	return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
 }

Same here.

Quoted 4 lines
drivers/staging/octeon-usb/octeon-hcd.c +0 -0
 /**

drivers/staging/octeon-usb/octeon-hcd.c static void octeon_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) · line 549

Quoted 10 lines
drivers/staging/octeon-usb/octeon-hcd.c +2 -2
@@ -542,8 +542,8 @@ static void octeon_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
  */
 static inline u32 cvmx_usb_read_csr32(struct octeon_hcd *usb, u64 address)
 {
-	u32 result = cvmx_read64_uint32(address ^ 4);
-	return result;
+	 
+	return cvmx_read64_uint32(address ^ 4);
 }
 
 /**

This change looks fine, though.

Automatically generating patches does not free you from validating each of them manually.

Regards,
Markus

#2 lore raw
Quoted 27 lines · Markus Böhme

Nadim,

several points stand out in your patch:

Quoted 13 lines · Nadim almas

if immediate return statement is found. It also removes variable bytes_written as
it is no longer needed.

It is done using script Coccinelle. And coccinelle uses following semantic
patch for this compression function:

@@
expression ret;
identifier f;
@@

Review

Quoted 4 lines
(quoted diff) +1 -2
-ret =
+return
     f(...);
-return ret;

The commit message is malformed. Start a new paragraph for the longer description of what you are doing after the short one.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

If Julia acked this patch she probably should be copied on this mail.

No, I haven't seen it... And I don't think the above semantic patch should have made these changes.

julia

Quoted 78 lines
Quoted 11 lines
---
 Makefile                                |  2 +-
 drivers/staging/octeon-usb/octeon-hcd.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
Makefile +0 -0
index 4fb6bea..3d9d77a6 100644

Makefile line 4

Quoted 5 lines
Makefile +1 -1
@@ -1,7 +1,7 @@
 VERSION = 4
 PATCHLEVEL = 7
 SUBLEVEL = 0
-EXTRAVERSION = -rc4
+EXTRAVERSION = -eudyptula-rc4

No need to change this.

Quoted 8 lines
Makefile +0 -0
 NAME = Psychotic Stoned Sheep
 
 # *DOCUMENTATION*
drivers/staging/octeon-usb/octeon-hcd.c +0 -0
index 17442b3..b801c8a 100644

drivers/staging/octeon-usb/octeon-hcd.c static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · line 513

Quoted 9 lines
drivers/staging/octeon-usb/octeon-hcd.c +3 -3
@@ -508,15 +508,15 @@ static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 {
 	int ret;
 
-	ret = octeon_alloc_temp_buffer(urb, mem_flags);
-	if (ret)
-		return ret;
+
+	if (octeon_alloc_temp_buffer(urb, mem_flags))
+		return octeon_alloc_temp_buffer(urb, mem_flags);

This cannot possibly be correct! You are calling a function with side effects twice. The first call in the condition might fail while the call in the return statement might succeed, never minding the wastefulness of two identical calls. Besides, the original code here seems fine to me.

drivers/staging/octeon-usb/octeon-hcd.c static int octeon_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · line 520

Quoted 10 lines
drivers/staging/octeon-usb/octeon-hcd.c +3 -3
-	ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
-	if (ret)
+
+	if (usb_hcd_map_urb_for_dma(hcd, urb, mem_flags))
 		octeon_free_temp_buffer(urb);
 
-	return ret;
+	return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
 }

Same here.

Quoted 4 lines
drivers/staging/octeon-usb/octeon-hcd.c +0 -0
 /**

drivers/staging/octeon-usb/octeon-hcd.c static void octeon_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) · line 549

Quoted 10 lines
drivers/staging/octeon-usb/octeon-hcd.c +2 -2
@@ -542,8 +542,8 @@ static void octeon_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
  */
 static inline u32 cvmx_usb_read_csr32(struct octeon_hcd *usb, u64 address)
 {
-	u32 result = cvmx_read64_uint32(address ^ 4);
-	return result;
+
+	return cvmx_read64_uint32(address ^ 4);
 }
 
 /**

This change looks fine, though.

Automatically generating patches does not free you from validating each of them manually.

Regards,
Markus