Skip to contentSkip to conversation

staging: media: davinci_vpfe: remove ret variable in switch statements

PATCH In review Thaissa Falbo 2 participants 4 messages Feb 18, 2016 – Feb 20, 2016

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

PATCH 1/1 staging: media: davinci_vpfe: remove ret variable in switch statements

Remove ret variable in functions that used it to determine the return. Simplified the return logic for these functions.

Found with Coccinelle script:

@@
local idexpression ret;
expression c,d;
identifier label;
@@

switch ( ... ) {
case label :
...
- ret = c;
- break;
+ return c;
...
default:
...
- ret = d;
+ return d;
...
}
... when != ret
- return ret;

@@
type T; identifier i;
@@
- T i;
... when != i

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 11 +++--------
 drivers/staging/media/davinci_vpfe/dm365_isif.c  | 11 +++--------
 2 files changed, 6 insertions(+), 16 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.c +3 -8
index ac78ed2..ff47a8f3 100644
@@ -1350,21 +1350,16 @@ error:
  */
 static long ipipe_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-	int ret = 0;
-
 	switch (cmd) {
 	case VIDIOC_VPFE_IPIPE_S_CONFIG:
-		ret = ipipe_s_config(sd, arg);
-		break;
+		return ipipe_s_config(sd, arg);
 
 	case VIDIOC_VPFE_IPIPE_G_CONFIG:
-		ret = ipipe_g_config(sd, arg);
-		break;
+		return ipipe_g_config(sd, arg);
 
 	default:
-		ret = -ENOIOCTLCMD;
+		return -ENOIOCTLCMD;
 	}
-	return ret;
 }
 
 void vpfe_ipipe_enable(struct vpfe_device *vpfe_dev, int en)
drivers/staging/media/davinci_vpfe/dm365_isif.c +3 -8
index cfad426..71d3314 100644
@@ -625,21 +625,16 @@ static int isif_set_params(struct v4l2_subdev *sd, void *params)
  */
 static long isif_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-	int ret;
-
 	switch (cmd) {
 	case VIDIOC_VPFE_ISIF_S_RAW_PARAMS:
-		ret = isif_set_params(sd, arg);
-		break;
+		return isif_set_params(sd, arg);
 
 	case VIDIOC_VPFE_ISIF_G_RAW_PARAMS:
-		ret = isif_get_params(sd, arg);
-		break;
+		return isif_get_params(sd, arg);
 
 	default:
-		ret = -ENOIOCTLCMD;
+		return -ENOIOCTLCMD;
 	}
-	return ret;
 }
 
 static void isif_config_gain_offset(struct vpfe_isif_device *isif)
Signature · 1 line
2.1.4
#1 lore raw
Quoted 12 lines · Thaissa Falbo

Remove ret variable in functions that used it to determine the return. Simplified the return logic for these functions.

Found with Coccinelle script:

@@
local idexpression ret;
expression c,d;
identifier label;
@@

Quoted 15 lines

switch ( ... ) {
case label :
...
- ret = c;
- break;
+ return c;
...
default:
...
- ret = d;
+ return d;
...
}
... when != ret
- return ret;

Perhaps this is OK for this example, but it doesn't seem like a generlly useful rule. There could be some cleanup code that is executed between the end of the switch and the return ret that is not getting executed.

Quoted 83 lines

@@
type T; identifier i;
@@
- T i;
... when != i

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 11 +++--------
 drivers/staging/media/davinci_vpfe/dm365_isif.c  | 11 +++--------
 2 files changed, 6 insertions(+), 16 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.c +3 -8
index ac78ed2..ff47a8f3 100644
@@ -1350,21 +1350,16 @@ error:
  */
 static long ipipe_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-	int ret = 0;
-
 	switch (cmd) {
 	case VIDIOC_VPFE_IPIPE_S_CONFIG:
-		ret = ipipe_s_config(sd, arg);
-		break;
+		return ipipe_s_config(sd, arg);
 
 	case VIDIOC_VPFE_IPIPE_G_CONFIG:
-		ret = ipipe_g_config(sd, arg);
-		break;
+		return ipipe_g_config(sd, arg);
 
 	default:
-		ret = -ENOIOCTLCMD;
+		return -ENOIOCTLCMD;
 	}
-	return ret;
 }
 
 void vpfe_ipipe_enable(struct vpfe_device *vpfe_dev, int en)
drivers/staging/media/davinci_vpfe/dm365_isif.c +3 -9
index cfad426..71d3314 100644
@@ -625,21 +625,16 @@ static int isif_set_params(struct v4l2_subdev *sd, void *params)
  */
 static long isif_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-	int ret;
-
 	switch (cmd) {
 	case VIDIOC_VPFE_ISIF_S_RAW_PARAMS:
-		ret = isif_set_params(sd, arg);
-		break;
+		return isif_set_params(sd, arg);
 
 	case VIDIOC_VPFE_ISIF_G_RAW_PARAMS:
-		ret = isif_get_params(sd, arg);
-		break;
+		return isif_get_params(sd, arg);
 
 	default:
-		ret = -ENOIOCTLCMD;
+		return -ENOIOCTLCMD;
 	}
-	return ret;
 }
 
 static void isif_config_gain_offset(struct vpfe_isif_device *isif)
--

2.1.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1455830274-15956-1-git-send-email-thaissa.falbo%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw

2016-02-19 1:16 GMT-02:00 Julia Lawall <[email protected]>:

Quoted 110 lines · Thaissa Falbo
Quoted 13 lines

Remove ret variable in functions that used it to determine the return. Simplified the return logic for these functions.

Found with Coccinelle script:

@@
local idexpression ret;
expression c,d;
identifier label;
@@

Quoted 15 lines

switch ( ... ) {
case label :
...
- ret = c;
- break;
+ return c;
...
default:
...
- ret = d;
+ return d;
...
}
... when != ret
- return ret;

Perhaps this is OK for this example, but it doesn't seem like a generlly useful rule. There could be some cleanup code that is executed between the end of the switch and the return ret that is not getting executed.

Quoted 76 lines

@@
type T; identifier i;
@@
- T i;
... when != i

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 11 +++--------
 drivers/staging/media/davinci_vpfe/dm365_isif.c  | 11 +++--------
 2 files changed, 6 insertions(+), 16 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.c +3 -8
index ac78ed2..ff47a8f3 100644
@@ -1350,21 +1350,16 @@ error:
  */
 static long ipipe_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-     int ret = 0;
-
      switch (cmd) {
      case VIDIOC_VPFE_IPIPE_S_CONFIG:
-             ret = ipipe_s_config(sd, arg);
-             break;
+             return ipipe_s_config(sd, arg);
 
      case VIDIOC_VPFE_IPIPE_G_CONFIG:
-             ret = ipipe_g_config(sd, arg);
-             break;
+             return ipipe_g_config(sd, arg);
 
      default:
-             ret = -ENOIOCTLCMD;
+             return -ENOIOCTLCMD;
      }
-     return ret;
 }
 
 void vpfe_ipipe_enable(struct vpfe_device *vpfe_dev, int en)
drivers/staging/media/davinci_vpfe/dm365_isif.c +3 -9
index cfad426..71d3314 100644
@@ -625,21 +625,16 @@ static int isif_set_params(struct v4l2_subdev *sd, void *params)
  */
 static long isif_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-     int ret;
-
      switch (cmd) {
      case VIDIOC_VPFE_ISIF_S_RAW_PARAMS:
-             ret = isif_set_params(sd, arg);
-             break;
+             return isif_set_params(sd, arg);
 
      case VIDIOC_VPFE_ISIF_G_RAW_PARAMS:
-             ret = isif_get_params(sd, arg);
-             break;
+             return isif_get_params(sd, arg);
 
      default:
-             ret = -ENOIOCTLCMD;
+             return -ENOIOCTLCMD;
      }
-     return ret;
 }
 
 static void isif_config_gain_offset(struct vpfe_isif_device *isif)
--

2.1.4

Quoted 7 lines
Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1455830274-15956-1-git-send-email-thaissa.falbo%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hi!

Yes, I was afraid of the coccinelle script not working for more examples because there could be more handling of the ret variable. I thought the line "... when != ret" would catch?

Anyways, is this patch ok?

Thaissa

#3 lore raw
Quoted 121 lines · Thaíssa Falbo

2016-02-19 1:16 GMT-02:00 Julia Lawall <[email protected]>:

Quoted 110 lines · Thaissa Falbo
Quoted 13 lines

Remove ret variable in functions that used it to determine the return. Simplified the return logic for these functions.

Found with Coccinelle script:

@@
local idexpression ret;
expression c,d;
identifier label;
@@

Quoted 15 lines

switch ( ... ) {
case label :
...
- ret = c;
- break;
+ return c;
...
default:
...
- ret = d;
+ return d;
...
}
... when != ret
- return ret;

Perhaps this is OK for this example, but it doesn't seem like a generlly useful rule. There could be some cleanup code that is executed between the end of the switch and the return ret that is not getting executed.

Quoted 76 lines

@@
type T; identifier i;
@@
- T i;
... when != i

---
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c | 11 +++--------
 drivers/staging/media/davinci_vpfe/dm365_isif.c  | 11 +++--------
 2 files changed, 6 insertions(+), 16 deletions(-)
drivers/staging/media/davinci_vpfe/dm365_ipipe.c +3 -8
index ac78ed2..ff47a8f3 100644
@@ -1350,21 +1350,16 @@ error:
  */
 static long ipipe_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-     int ret = 0;
-
      switch (cmd) {
      case VIDIOC_VPFE_IPIPE_S_CONFIG:
-             ret = ipipe_s_config(sd, arg);
-             break;
+             return ipipe_s_config(sd, arg);
 
      case VIDIOC_VPFE_IPIPE_G_CONFIG:
-             ret = ipipe_g_config(sd, arg);
-             break;
+             return ipipe_g_config(sd, arg);
 
      default:
-             ret = -ENOIOCTLCMD;
+             return -ENOIOCTLCMD;
      }
-     return ret;
 }
 
 void vpfe_ipipe_enable(struct vpfe_device *vpfe_dev, int en)
drivers/staging/media/davinci_vpfe/dm365_isif.c +3 -9
index cfad426..71d3314 100644
@@ -625,21 +625,16 @@ static int isif_set_params(struct v4l2_subdev *sd, void *params)
  */
 static long isif_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
 {
-     int ret;
-
      switch (cmd) {
      case VIDIOC_VPFE_ISIF_S_RAW_PARAMS:
-             ret = isif_set_params(sd, arg);
-             break;
+             return isif_set_params(sd, arg);
 
      case VIDIOC_VPFE_ISIF_G_RAW_PARAMS:
-             ret = isif_get_params(sd, arg);
-             break;
+             return isif_get_params(sd, arg);
 
      default:
-             ret = -ENOIOCTLCMD;
+             return -ENOIOCTLCMD;
      }
-     return ret;
 }
 
 static void isif_config_gain_offset(struct vpfe_isif_device *isif)
--

2.1.4

Quoted 7 lines
Quoted 7 lines

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1455830274-15956-1-git-send-email-thaissa.falbo%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hi!

Quoted 3 lines

Yes, I was afraid of the coccinelle script not working for more examples because there could be more handling of the ret variable. I thought the line "... when != ret" would catch?

The error handling will probably not involve ret. It may free something that has previousy been allocated. The changes look ok, though, because there is nothing before the return.

julia

Quoted 13 lines

Anyways, is this patch ok?

Thaissa

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAKqL7ZW0%2BC-GuoJgnJ-pX-8cWjEnBNVWF_64fw7OTHAne6DkgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.