Skip to contentSkip to conversation

staging: most: usb: Remove variable frame_size

PATCH In review Nishka Dasgupta 3 participants 4 messages May 23, 2019 – May 24, 2019

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

PATCH 1/1 staging: most: usb: Remove variable frame_size

Remove variable frame_size as its multiple usages are all independent of each other and so can be returned separately.
Issue found with Coccinelle.

---
 drivers/staging/most/usb/usb.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/staging/most/usb/usb.c +6 -10
index 360cb5b7a10b..751e82cf66c5 100644
@@ -186,32 +186,28 @@ static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep)
  */
 static unsigned int get_stream_frame_size(struct most_channel_config *cfg)
 {
-	unsigned int frame_size = 0;
 	unsigned int sub_size = cfg->subbuffer_size;
 
 	if (!sub_size) {
 		pr_warn("Misconfig: Subbuffer size zero.\n");
-		return frame_size;
+		return 0;
 	}
 	switch (cfg->data_type) {
 	case MOST_CH_ISOC:
-		frame_size = AV_PACKETS_PER_XACT * sub_size;
-		break;
+		return AV_PACKETS_PER_XACT * sub_size;
 	case MOST_CH_SYNC:
 		if (cfg->packets_per_xact == 0) {
 			pr_warn("Misconfig: Packets per XACT zero\n");
-			frame_size = 0;
+			return 0;
 		} else if (cfg->packets_per_xact == 0xFF) {
-			frame_size = (USB_MTU / sub_size) * sub_size;
+			return (USB_MTU / sub_size) * sub_size;
 		} else {
-			frame_size = cfg->packets_per_xact * sub_size;
+			return cfg->packets_per_xact * sub_size;
 		}
-		break;
 	default:
 		pr_warn("Query frame size of non-streaming channel\n");
-		break;
+		return 0;
 	}
-	return frame_size;
 }
 
 /**
Signature · 1 line
2.19.1
maintainer
#1 lore raw
Quoted 40 lines · Nishka Dasgupta

Remove variable frame_size as its multiple usages are all independent of each other and so can be returned separately.
Issue found with Coccinelle.

---
 drivers/staging/most/usb/usb.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/staging/most/usb/usb.c +4 -7
index 360cb5b7a10b..751e82cf66c5 100644
@@ -186,32 +186,28 @@ static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep)
  */
 static unsigned int get_stream_frame_size(struct most_channel_config *cfg)
 {
-	unsigned int frame_size = 0;
 	unsigned int sub_size = cfg->subbuffer_size;
 
 	if (!sub_size) {
 		pr_warn("Misconfig: Subbuffer size zero.\n");
-		return frame_size;
+		return 0;
 	}
 	switch (cfg->data_type) {
 	case MOST_CH_ISOC:
-		frame_size = AV_PACKETS_PER_XACT * sub_size;
-		break;
+		return AV_PACKETS_PER_XACT * sub_size;
 	case MOST_CH_SYNC:
 		if (cfg->packets_per_xact == 0) {
 			pr_warn("Misconfig: Packets per XACT zero\n");
-			frame_size = 0;
+			return 0;
 		} else if (cfg->packets_per_xact == 0xFF) {
-			frame_size = (USB_MTU / sub_size) * sub_size;
+			return (USB_MTU / sub_size) * sub_size;
 		} else {
-			frame_size = cfg->packets_per_xact * sub_size;

drivers/staging/most/usb/usb.c static inline int start_sync_ep(struct usb_device *usb_dev, u16 ep) · line 211

Quoted 10 lines
drivers/staging/most/usb/usb.c +2 -3
+			return cfg->packets_per_xact * sub_size;
 		}
-		break;
 	default:
 		pr_warn("Query frame size of non-streaming channel\n");
-		break;
+		return 0;
 	}
-	return frame_size;
 }

Now it just feels like you are doing "busy work" :(

frame_size makes sense here, right? Why change this code?

Remember, code is written for developers first, the compiler second. Reading this with frame_size makes it much more obvious what this code does when you read it again in 5-10 years. Why change this, you have not made it faster, or smaller at all.

So no, I would not accept this, sorry.

We have so many _real_ things to do in the drivers/staging/ directory if you are looking for stuff to clean up. Don't try to micro-optimize things that do not matter at the expense of understanding.

thanks,

greg k-h

#2 lore raw
Quoted 67 lines · Greg KH

External E-Mail

Quoted 58 lines · Nishka Dasgupta

Remove variable frame_size as its multiple usages are all independent of
each other and so can be returned separately. Issue found with Coccinelle.

---
 drivers/staging/most/usb/usb.c | 16 ++++++----------

 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/staging/most/usb/usb.c +0 -0
index 360cb5b7a10b..751e82cf66c5 100644
@@ -186,32 +186,28 @@ static inline int start_sync_ep(struct
 usb_device *usb_dev, u16 ep)
   */

 static unsigned int get_stream_frame_size(struct
most_channel_config *cfg)
 {

drivers/staging/most/usb/usb.c +0 -1
-	unsigned int frame_size = 0;

  unsigned int sub_size = cfg->subbuffer_size;
  if (!sub_size) {
  pr_warn("Misconfig: Subbuffer size zero.\n");

drivers/staging/most/usb/usb.c +1 -1
-		return frame_size;
+		return 0;

  }
  switch (cfg->data_type) {
  case MOST_CH_ISOC:

drivers/staging/most/usb/usb.c +1 -2
-		frame_size = AV_PACKETS_PER_XACT * sub_size;
-		break;
+		return AV_PACKETS_PER_XACT * sub_size;

  case MOST_CH_SYNC:
  if (cfg->packets_per_xact == 0) { pr_warn("Misconfig: Packets per XACT zero\n");

drivers/staging/most/usb/usb.c +1 -1
-			frame_size = 0;
+			return 0;

  } else if (cfg->packets_per_xact == 0xFF) {

drivers/staging/most/usb/usb.c +0 -1
-			frame_size = (USB_MTU / sub_size) *

sub_size;

drivers/staging/most/usb/usb.c +1 -0
+			return (USB_MTU / sub_size) * sub_size;

  } else {

drivers/staging/most/usb/usb.c +0 -1
-			frame_size = cfg->packets_per_xact *

sub_size;

drivers/staging/most/usb/usb.c +1 -0
+			return cfg->packets_per_xact * sub_size;

  }

drivers/staging/most/usb/usb.c +0 -1
-		break;

  default:
  pr_warn("Query frame size of non-streaming channel\n");

drivers/staging/most/usb/usb.c +1 -1
-		break;
+		return 0;

  }

drivers/staging/most/usb/usb.c +0 -1
-	return frame_size;
Quoted 1 line

 }

Now it just feels like you are doing "busy work" :(

frame_size makes sense here, right?  Why change this code?

Quoted 7 lines

Remember, code is written for developers first, the compiler second. Reading this with frame_size makes it much more obvious what this code
does when you read it again in 5-10 years.  Why change this, you have not made it faster, or smaller at all.

So no, I would not accept this, sorry.

I haven't seen this on time. So please ignore my acknowledge I've sent. Good to know that you favor readability over compactness.

Sorry for the noise,
Chris

Quoted 10 lines

We have so many _real_ things to do in the drivers/staging/ directory if
you are looking for stuff to clean up.  Don't try to micro-optimize things that do not matter at the expense of understanding.

thanks,

greg k-h

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Nishka Dasgupta
Quoted 9 lines · Nishka Dasgupta

External E-Mail

Remove variable frame_size as its multiple usages are all independent of
each other and so can be returned separately.
Issue found with Coccinelle.

Quoted 54 lines

---
 drivers/staging/most/usb/usb.c | 16 ++++++----------

 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/staging/most/usb/usb.c +0 -0
index 360cb5b7a10b..751e82cf66c5 100644
@@ -186,32 +186,28 @@ static inline int start_sync_ep(struct
 usb_device *usb_dev, u16 ep)
   */

 static unsigned int get_stream_frame_size(struct most_channel_config *cfg)
 {

drivers/staging/most/usb/usb.c +0 -1
-	unsigned int frame_size = 0;

  unsigned int sub_size = cfg->subbuffer_size;
  if (!sub_size) {
  pr_warn("Misconfig: Subbuffer size zero.\n");

drivers/staging/most/usb/usb.c +1 -1
-		return frame_size;
+		return 0;

  }
  switch (cfg->data_type) {
  case MOST_CH_ISOC:

drivers/staging/most/usb/usb.c +1 -2
-		frame_size = AV_PACKETS_PER_XACT * sub_size;
-		break;
+		return AV_PACKETS_PER_XACT * sub_size;

  case MOST_CH_SYNC:
  if (cfg->packets_per_xact == 0) { pr_warn("Misconfig: Packets per XACT zero\n");

drivers/staging/most/usb/usb.c +1 -1
-			frame_size = 0;
+			return 0;

  } else if (cfg->packets_per_xact == 0xFF) {

drivers/staging/most/usb/usb.c +0 -1
-			frame_size = (USB_MTU / sub_size) *

sub_size;

drivers/staging/most/usb/usb.c +1 -0
+			return (USB_MTU / sub_size) * sub_size;

  } else {

drivers/staging/most/usb/usb.c +0 -1
-			frame_size = cfg->packets_per_xact *

sub_size;

drivers/staging/most/usb/usb.c +1 -0
+			return cfg->packets_per_xact * sub_size;

  }

drivers/staging/most/usb/usb.c +0 -1
-		break;

  default:
  pr_warn("Query frame size of non-streaming channel\n");

drivers/staging/most/usb/usb.c +1 -1
-		break;
+		return 0;

  }

drivers/staging/most/usb/usb.c +0 -1
-	return frame_size;

 }

 /**