Skip to contentSkip to conversation

pwm: core: Use devm_kcalloc instead of kzalloc

PATCH New Xiubo Li 1 participant 1 message Jan 7, 2014 PWM

lore
Share & tools
lore

Xiubo Li

author
#0 lore raw

PATCH v2 1/1 pwm: core: Use devm_kcalloc instead of kzalloc

Use devm_kcalloc instead of kzalloc to free automatically and make the cleanup paths simpler and the code slightly shorter.

---

Changed in v2:
- Use devm_kcalloc instead of devm_kzalloc.

Changed in v1:
- Use devm_kzalloc instead of kzalloc.

 drivers/pwm/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pwm/core.c +2 -2
index 2ca9504..75220e8 100644
@@ -80,7 +80,6 @@ static void free_pwms(struct pwm_chip *chip)
 
 	bitmap_clear(allocated_pwms, chip->base, chip->npwm);
 
-	kfree(chip->pwms);
 	chip->pwms = NULL;
 }
 
@@ -245,7 +244,8 @@ int pwmchip_add(struct pwm_chip *chip)
 	if (ret < 0)
 		goto out;
 
-	chip->pwms = kzalloc(chip->npwm * sizeof(*pwm), GFP_KERNEL);
+	chip->pwms = devm_kcalloc(chip->dev, chip->npwm,
+				  sizeof(*pwm), GFP_KERNEL);
 	if (!chip->pwms) {
 		ret = -ENOMEM;
 		goto out;
Signature · 1 line
1.8.4