Skip to contentSkip to conversation

reset: sti: kzalloc + kcalloc to kzalloc

PATCH Applied Rosen Penev 3 participants 3 messages Mar 20

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

PATCH 1/1 reset: sti: kzalloc + kcalloc to kzalloc

Simplify allocation.

---
 drivers/reset/sti/reset-syscfg.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/reset/sti/reset-syscfg.c +2 -7
index 2324060b747c..38f78d78fa4f 100644
@@ -41,7 +41,7 @@ struct syscfg_reset_channel {
 struct syscfg_reset_controller {
 	struct reset_controller_dev rst;
 	bool active_low;
-	struct syscfg_reset_channel *channels;
+	struct syscfg_reset_channel channels[];
 };
 
 #define to_syscfg_reset_controller(_rst) \
@@ -135,15 +135,10 @@ static int syscfg_reset_controller_register(struct device *dev,
 	struct syscfg_reset_controller *rc;
 	int i, err;
 
-	rc = devm_kzalloc(dev, sizeof(*rc), GFP_KERNEL);
+	rc = devm_kzalloc(dev, struct_size(rc, channels, data->nr_channels), GFP_KERNEL);
 	if (!rc)
 		return -ENOMEM;
 
-	rc->channels = devm_kcalloc(dev, data->nr_channels,
-				    sizeof(*rc->channels), GFP_KERNEL);
-	if (!rc->channels)
-		return -ENOMEM;
-
 	rc->rst.ops = &syscfg_reset_ops;
 	rc->rst.of_node = dev->of_node;
 	rc->rst.nr_resets = data->nr_channels;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Rosen Penev

Simplify allocation.

---
 drivers/reset/sti/reset-syscfg.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/reset/sti/reset-syscfg.c +2 -2
index 2324060b747c..38f78d78fa4f 100644
@@ -41,7 +41,7 @@ struct syscfg_reset_channel {
 struct syscfg_reset_controller {
 	struct reset_controller_dev rst;
 	bool active_low;
-	struct syscfg_reset_channel *channels;
+	struct syscfg_reset_channel channels[];
 };
 
 #define to_syscfg_reset_controller(_rst) \
@@ -135,15 +135,10 @@ static int syscfg_reset_controller_register(struct device *dev,
 	struct syscfg_reset_controller *rc;
 	int i, err;
 
-	rc = devm_kzalloc(dev, sizeof(*rc), GFP_KERNEL);
+	rc = devm_kzalloc(dev, struct_size(rc, channels, data->nr_channels), GFP_KERNEL);
 	if (!rc)

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

Quoted 10 lines
drivers/reset/sti/reset-syscfg.c +0 -5
 		return -ENOMEM;
 
-	rc->channels = devm_kcalloc(dev, data->nr_channels,
-				    sizeof(*rc->channels), GFP_KERNEL);
-	if (!rc->channels)
-		return -ENOMEM;
-
 	rc->rst.ops = &syscfg_reset_ops;
 	rc->rst.of_node = dev->of_node;
 	rc->rst.nr_resets = data->nr_channels;

Hi Rosen

Thanks
Patrice