Skip to contentSkip to conversation

staging: media: bcm2048: remove unused variable

PATCH In review Aya Mahfouz 2 participants 3 messages Feb 18, 2015

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

PATCH 1/1 staging: media: bcm2048: remove unused variable

This patch removes the variable value since it is used only to store return values and check their values. The pattern of storing return values was found using the following coccinelle script:

@@
expression ret;
identifier f;
@@

-ret =
+return

     f(...);

-return ret;

---
v1: bdev is also a candidate for removal. Is there a guideline for such cases?

 drivers/staging/media/bcm2048/radio-bcm2048.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/media/bcm2048/radio-bcm2048.c +2 -6
index 60a57b2..6e0b83e 100644
@@ -1987,17 +1987,13 @@ static ssize_t bcm2048_##prop##_read(struct device *dev,		\
 					char *buf)			\
 {									\
 	struct bcm2048_device *bdev = dev_get_drvdata(dev);		\
-	int value;							\
 									\
 	if (!bdev)							\
 		return -ENODEV;						\
 									\
-	value = bcm2048_get_##prop(bdev);				\
-									\
-	if (value >= 0)							\
-		value = sprintf(buf, mask "\n", value);			\
+	if (bcm2048_get_##prop(bdev) >= 0)				\
+		return sprintf(buf, mask "\n", value);			\
 									\
-	return value;							\
 }
 
 #define property_signed_read(prop, size, mask)				\
Signature · 1 line
1.9.3
#1 lore raw
Quoted 15 lines · Aya Mahfouz

This patch removes the variable value since it is used only to store return values and check their values. The pattern of storing return values was found using the following coccinelle script:

@@
expression ret;
identifier f;
@@

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

---
v1: bdev is also a candidate for removal. Is there a guideline for such cases?

Kernel code tends not to nest function calls very much. Also then you would have to call dev_get_drvdata twice, for the test and for the subsequent call to bcm2048_get_##prop.

Some developers are not enthusiastic about function calls in local variable declaration lists. As here, the call and the test are separated. You could use grep to see what is commonly done for this function.

julia

Quoted 14 lines
 drivers/staging/media/bcm2048/radio-bcm2048.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/media/bcm2048/radio-bcm2048.c +0 -1
index 60a57b2..6e0b83e 100644
@@ -1987,17 +1987,13 @@ static ssize_t bcm2048_##prop##_read(struct device *dev,		\
 					char *buf)			\
 {									\
 	struct bcm2048_device *bdev = dev_get_drvdata(dev);		\
-	int value;							\
 									\
 	if (!bdev)							\

drivers/staging/media/bcm2048/radio-bcm2048.c static ssize_t bcm2048_##prop##_read(struct device *dev, \ · line 2000

Quoted 10 lines
drivers/staging/media/bcm2048/radio-bcm2048.c +2 -5
 		return -ENODEV;						\
 									\
-	value = bcm2048_get_##prop(bdev);				\
-									\
-	if (value >= 0)							\
-		value = sprintf(buf, mask "\n", value);			\
+	if (bcm2048_get_##prop(bdev) >= 0)				\
+		return sprintf(buf, mask "\n", value);			\
 									\
-	return value;							\

This doesn't look corect. You need to return something in this case.

Quoted 13 lines
drivers/staging/media/bcm2048/radio-bcm2048.c +0 -0
 }
 
 #define property_signed_read(prop, size, mask)				\
Signature · 8 lines
1.9.3

-- 
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/20150218013353.GA17840%40localhost.localdomain.
For more options, visit https://groups.google.com/d/optout.
#2 lore raw
Quoted 26 lines · Julia Lawall
Quoted 15 lines · Aya Mahfouz

This patch removes the variable value since it is used only to store return values and check their values. The pattern of storing return values was found using the following coccinelle script:

@@
expression ret;
identifier f;
@@

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

---
v1: bdev is also a candidate for removal. Is there a guideline for such cases?

Kernel code tends not to nest function calls very much. Also then you would have to call dev_get_drvdata twice, for the test and for the subsequent call to bcm2048_get_##prop.

Quoted 6 lines

Some developers are not enthusiastic about function calls in local variable declaration lists. As here, the call and the test are separated. You could use grep to see what is commonly done for this function.

julia

ok, thanks for your comments. I guess I need to read more before carrying out further changes.

Kind Regards,
Aya Saif El-yazal Mahfouz

Quoted 40 lines
Quoted 14 lines
 drivers/staging/media/bcm2048/radio-bcm2048.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/staging/media/bcm2048/radio-bcm2048.c +0 -1
index 60a57b2..6e0b83e 100644
@@ -1987,17 +1987,13 @@ static ssize_t bcm2048_##prop##_read(struct device *dev,		\
 					char *buf)			\
 {									\
 	struct bcm2048_device *bdev = dev_get_drvdata(dev);		\
-	int value;							\
 									\
 	if (!bdev)							\

drivers/staging/media/bcm2048/radio-bcm2048.c static ssize_t bcm2048_##prop##_read(struct device *dev, \ · line 2000

Quoted 10 lines
drivers/staging/media/bcm2048/radio-bcm2048.c +2 -5
 		return -ENODEV;						\
 									\
-	value = bcm2048_get_##prop(bdev);				\
-									\
-	if (value >= 0)							\
-		value = sprintf(buf, mask "\n", value);			\
+	if (bcm2048_get_##prop(bdev) >= 0)				\
+		return sprintf(buf, mask "\n", value);			\
 									\
-	return value;							\

This doesn't look corect. You need to return something in this case.

Quoted 13 lines
drivers/staging/media/bcm2048/radio-bcm2048.c +0 -0
 }
 
 #define property_signed_read(prop, size, mask)				\
Signature · 8 lines
1.9.3

-- 
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/20150218013353.GA17840%40localhost.localdomain.
For more options, visit https://groups.google.com/d/optout.