Skip to contentSkip to conversation

Radeon backlight: Adjustments for radeonfb_bl_init()

PATCH New SF Markus Elfring 1 participant 6 messages Nov 27, 2017

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

cover Radeon backlight: Adjustments for radeonfb_bl_init()

From: Markus Elfring <[email protected]>
Date: Mon, 27 Nov 2017 22:14:04 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
Delete an error message for a failed memory allocation Improve a size determination
Delete an unnecessary return statement
Return directly after a failed kmalloc() Delete a jump target

 drivers/video/fbdev/aty/radeon_backlight.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
Signature · 1 line
2.15.0
#1 lore raw

PATCH 1/5 radeon_backlight: Delete an error message for a failed memory allocation in radeonfb_bl_init()

From: Markus Elfring <[email protected]>
Date: Mon, 27 Nov 2017 21:27:51 +0100

Omit an extra message for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/aty/radeon_backlight.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/video/fbdev/aty/radeon_backlight.c +1 -3
index 301d6d6aeead..ce5b22d710b3 100644
@@ -144,10 +144,8 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
 #endif
 
 	pdata = kmalloc(sizeof(struct radeon_bl_privdata), GFP_KERNEL);
-	if (!pdata) {
-		printk("radeonfb: Memory allocation failed\n");
+	if (!pdata)
 		goto error;
-	}
 
 	snprintf(name, sizeof(name), "radeonbl%d", rinfo->info->node);
 
Signature · 1 line
2.15.0
#2 lore raw

PATCH 2/5 radeon_backlight: Improve a size determination in radeonfb_bl_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 27 Nov 2017 21:30:06 +0100

Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

This issue was detected by using the Coccinelle software.

---
 drivers/video/fbdev/aty/radeon_backlight.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/aty/radeon_backlight.c +1 -1
index ce5b22d710b3..78c36c8d5e57 100644
@@ -143,7 +143,7 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
 		return;
 #endif
 
-	pdata = kmalloc(sizeof(struct radeon_bl_privdata), GFP_KERNEL);
+	pdata = kmalloc(sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		goto error;
 
Signature · 1 line
2.15.0
#3 lore raw

PATCH 3/5 radeon_backlight: Delete an unnecessary return statement in radeonfb_bl_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 27 Nov 2017 21:37:52 +0100

The script "checkpatch.pl" pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement in the affected function.

---
 drivers/video/fbdev/aty/radeon_backlight.c | 1 -
 1 file changed, 1 deletion(-)
drivers/video/fbdev/aty/radeon_backlight.c +0 -1
index 78c36c8d5e57..c5e0e3557cc2 100644
@@ -193,7 +193,6 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
 
 error:
 	kfree(pdata);
-	return;
 }
 
 void radeonfb_bl_exit(struct radeonfb_info *rinfo)
Signature · 1 line
2.15.0
#4 lore raw

PATCH 4/5 radeon_backlight: Return directly after a failed kmalloc() in radeonfb_bl_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 27 Nov 2017 21:50:28 +0100

Return directly after a call of the function "kmalloc" failed at the beginning.

---
 drivers/video/fbdev/aty/radeon_backlight.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/aty/radeon_backlight.c +1 -1
index c5e0e3557cc2..7f7ed6f72ddb 100644
@@ -145,7 +145,7 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
 
 	pdata = kmalloc(sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
-		goto error;
+		return;
 
 	snprintf(name, sizeof(name), "radeonbl%d", rinfo->info->node);
 
Signature · 1 line
2.15.0
#5 lore raw

PATCH 5/5 radeon_backlight: Delete a jump target in radeonfb_bl_init()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Mon, 27 Nov 2017 22:03:03 +0100

* Replace a goto statement by a direct call of the function "kfree" in an if branch.

* Delete the jump label "error" which became unnecessary with this refactoring.

---
 drivers/video/fbdev/aty/radeon_backlight.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/video/fbdev/aty/radeon_backlight.c +2 -6
index 7f7ed6f72ddb..3c5b8291e773 100644
@@ -157,7 +157,8 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
 	if (IS_ERR(bd)) {
 		rinfo->info->bl_dev = NULL;
 		printk("radeonfb: Backlight registration failed\n");
-		goto error;
+		kfree(pdata);
+		return;
 	}
 
 	pdata->rinfo = rinfo;
@@ -188,11 +189,6 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
 	backlight_update_status(bd);
 
 	printk("radeonfb: Backlight initialized (%s)\n", name);
-
-	return;
-
-error:
-	kfree(pdata);
 }
 
 void radeonfb_bl_exit(struct radeonfb_info *rinfo)
Signature · 1 line
2.15.0