Skip to contentSkip to conversation

char-bsr: Adjustments for two function implementations

PATCH New SF Markus Elfring 1 participant 4 messages Oct 15, 2017

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

cover char-bsr: Adjustments for two function implementations

From: Markus Elfring <[email protected]>
Date: Sun, 15 Oct 2017 22:02:34 +0200

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

Markus Elfring (3):
Delete an error message for a failed memory allocation in bsr_add_node() Improve a size determination in bsr_add_node()
Adjust one function call together with a variable assignment

 drivers/char/bsr.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
Signature · 1 line
2.14.2
#1 lore raw

PATCH 1/3 char/bsr: Delete an error message for a failed memory allocation in bsr_add_node()

From: Markus Elfring <[email protected]>
Date: Sun, 15 Oct 2017 21:12:34 +0200

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

This issue was detected by using the Coccinelle software.

---
 drivers/char/bsr.c | 1 -
 1 file changed, 1 deletion(-)
drivers/char/bsr.c +0 -1
index a6cef548e01e..865eb457e539 100644
@@ -203,7 +203,6 @@ static int bsr_add_node(struct device_node *bn)
 		int result;
 
 		if (!cur) {
-			printk(KERN_ERR "Unable to alloc bsr dev\n");
 			ret = -ENOMEM;
 			goto out_err;
 		}
Signature · 1 line
2.14.2
#2 lore raw

PATCH 2/3 char/bsr: Improve a size determination in bsr_add_node()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 15 Oct 2017 21:25:46 +0200

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.

---
 drivers/char/bsr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/char/bsr.c +1 -2
index 865eb457e539..d0597dfa4d88 100644
@@ -197,8 +197,7 @@ static int bsr_add_node(struct device_node *bn)
 	num_bsr_devs = bsr_bytes_len / sizeof(u32);
 
 	for (i = 0 ; i < num_bsr_devs; i++) {
-		struct bsr_dev *cur = kzalloc(sizeof(struct bsr_dev),
-					      GFP_KERNEL);
+		struct bsr_dev *cur = kzalloc(sizeof(*cur), GFP_KERNEL);
 		struct resource res;
 		int result;
 
Signature · 1 line
2.14.2
#3 lore raw

PATCH 3/3 char/bsr: Adjust one function call together with a variable assignment

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 15 Oct 2017 21:55:26 +0200

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

ERROR: do not use assignment in if condition

Thus fix the affected source code place.

---
 drivers/char/bsr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/char/bsr.c +2 -1
index d0597dfa4d88..f11df210294a 100644
@@ -320,7 +320,8 @@ static int __init bsr_init(void)
 		goto out_err_2;
 	}
 
-	if ((ret = bsr_create_devs(np)) < 0) {
+	ret = bsr_create_devs(np);
+	if (ret < 0) {
 		np = NULL;
 		goto out_err_3;
 	}
Signature · 1 line
2.14.2