Skip to contentSkip to conversation

regulator: s2mps11: Fine-tuning for s2mps11_pmic_probe()

PATCH In review SF Markus Elfring 2 participants 5 messages Apr 14, 2017 – Apr 15, 2017

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

cover regulator: s2mps11: Fine-tuning for s2mps11_pmic_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 14 Apr 2017 22:55:22 +0200

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

Markus Elfring (2):
Use kcalloc()
Use devm_kmalloc_array()

 drivers/regulator/s2mps11.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/2 regulator: s2mps11: Use kcalloc() in s2mps11_pmic_probe()

From: Markus Elfring <[email protected]>
Date: Fri, 14 Apr 2017 22:00:35 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

---
 drivers/regulator/s2mps11.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/s2mps11.c +1 -1
index 7726b874e539..b4e588cce03d 100644
@@ -1162,7 +1162,7 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
 		}
 	}
 
-	rdata = kzalloc(sizeof(*rdata) * rdev_num, GFP_KERNEL);
+	rdata = kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
 	if (!rdata)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2
#4 lore raw

PATCH 2/2 regulator: s2mps11: Use devm_kmalloc_array() in s2mps11_pmic_probe()

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 14 Apr 2017 22:40:19 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "devm_kmalloc_array".

This issue was detected by using the Coccinelle software.

---
 drivers/regulator/s2mps11.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/regulator/s2mps11.c +5 -3
index b4e588cce03d..b397a2e0bcd1 100644
@@ -1139,9 +1139,11 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
-			sizeof(*s2mps11->ext_control_gpio) * rdev_num,
-			GFP_KERNEL);
+	s2mps11->ext_control_gpio
+		= devm_kmalloc_array(&pdev->dev,
+				     rdev_num,
+				     sizeof(*s2mps11->ext_control_gpio),
+				     GFP_KERNEL);
 	if (!s2mps11->ext_control_gpio)
 		return -ENOMEM;
 	/*
Signature · 1 line
2.12.2
#2 lore raw

Re: [PATCH 1/2] regulator: s2mps11: Use kcalloc() in s2mps11_pmic_probe()

In reply to SF Markus Elfring
Quoted 8 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 14 Apr 2017 22:00:35 +0200

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

Unfortunately you write mostly cryptic commit messages. This does not answer for the main question - why this change is needed. Code looks okay, but you should explain in simple words why this is needed.

Best regards,
Krzysztof

Quoted 22 lines
---
 drivers/regulator/s2mps11.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/s2mps11.c +1 -1
index 7726b874e539..b4e588cce03d 100644
@@ -1162,7 +1162,7 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
 		}
 	}
 
-	rdata = kzalloc(sizeof(*rdata) * rdev_num, GFP_KERNEL);
+	rdata = kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
 	if (!rdata)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2
#3 lore raw

Re: regulator: s2mps11: Use kcalloc() in s2mps11_pmic_probe()

Quoted 7 lines
Quoted 5 lines

A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kcalloc".

This issue was detected by using the Coccinelle software.

Unfortunately you write mostly cryptic commit messages.

Thanks for your feedback.

Quoted 1 line

This does not answer for the main question - why this change is needed.

My update suggestion affects an aspect for the coding style.

Quoted 1 line

Code looks okay,

There can be different opinions about related implementation details.

Quoted 1 line

but you should explain in simple words why this is needed.

Do you find the following wording from the script “checkpatch.pl” better to understand?

WARNING: Prefer kcalloc over kzalloc with multiply

Regards,
Markus