Skip to contentSkip to conversation

reset: sti: Use devm_kcalloc() in syscfg_reset_controller_register()

PATCH In review SF Markus Elfring 2 participants 3 messages Apr 26, 2017

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

PATCH 1/1 reset: sti: Use devm_kcalloc() in syscfg_reset_controller_register()

From: Markus Elfring <[email protected]>
Date: Wed, 26 Apr 2017 09:50:34 +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_kcalloc".

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

* Delete the local variable "size" which became unnecessary with this refactoring.

---
 drivers/reset/sti/reset-syscfg.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/reset/sti/reset-syscfg.c +2 -4
index 9bd57a5eee72..7e0f2aa55ba7 100644
@@ -145,16 +145,14 @@ static int syscfg_reset_controller_register(struct device *dev,
 				const struct syscfg_reset_controller_data *data)
 {
 	struct syscfg_reset_controller *rc;
-	size_t size;
 	int i, err;
 
 	rc = devm_kzalloc(dev, sizeof(*rc), GFP_KERNEL);
 	if (!rc)
 		return -ENOMEM;
 
-	size = sizeof(struct syscfg_reset_channel) * data->nr_channels;
-
-	rc->channels = devm_kzalloc(dev, size, GFP_KERNEL);
+	rc->channels = devm_kcalloc(dev, data->nr_channels,
+				    sizeof(*rc->channels), GFP_KERNEL);
 	if (!rc->channels)
 		return -ENOMEM;
 
Signature · 1 line
2.12.2
maintainer
#1 lore raw
Quoted 32 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Wed, 26 Apr 2017 09:50:34 +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_kcalloc".

* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.

* Delete the local variable "size" which became unnecessary with this refactoring.

---
 drivers/reset/sti/reset-syscfg.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/reset/sti/reset-syscfg.c +0 -1
index 9bd57a5eee72..7e0f2aa55ba7 100644
@@ -145,16 +145,14 @@ static int syscfg_reset_controller_register(struct device *dev,
 				const struct syscfg_reset_controller_data *data)
 {
 	struct syscfg_reset_controller *rc;
-	size_t size;
 	int i, err;
 
 	rc = devm_kzalloc(dev, sizeof(*rc), GFP_KERNEL);
 	if (!rc)

drivers/reset/sti/reset-syscfg.c static int syscfg_reset_controller_register(struct device *dev, · line 158

Quoted 10 lines
drivers/reset/sti/reset-syscfg.c +2 -3
 		return -ENOMEM;
 
-	size = sizeof(struct syscfg_reset_channel) * data->nr_channels;
-
-	rc->channels = devm_kzalloc(dev, size, GFP_KERNEL);
+	rc->channels = devm_kcalloc(dev, data->nr_channels,
+				    sizeof(*rc->channels), GFP_KERNEL);
 	if (!rc->channels)
 		return -ENOMEM;
 

Thank you, I have applied this to the reset/next branch. The same change could be made in the ti-syscon reset driver.

regards
Philipp

#2 lore raw

Re: reset: Use devm_kcalloc() in ti_syscon_reset_probe()?

Quoted 1 line

Thank you, I have applied this to the reset/next branch.

Thanks for your acceptance.

Quoted 1 line

The same change could be made in the ti-syscon reset driver.

I was unsure if a similar source code adjustments would be worthwhile there. If you would like to be more strict with consistent usage of Linux functions for array allocations, there are various further update candidates to consider.

Regards,
Markus