Skip to content

Commit 72db889

Browse files
whamesre
authored andcommitted
power: supply: wm97xx: Use devm_kcalloc()
Instead of handling the memory allocation manually, use the automatic `devres` variant `devm_kcalloc()`. This is less error prone and eliminates the `goto`-path. Signed-off-by: Waqar Hameed <waqar.hameed@axis.com> Link: https://patch.msgid.link/5ac93f5b0fa417bb5d9e93b9302a18f2c04d4077.1769158280.git.waqar.hameed@axis.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 2306725 commit 72db889

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

drivers/power/supply/wm97xx_battery.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int wm97xx_bat_probe(struct platform_device *dev)
192192
if (pdata->min_voltage >= 0)
193193
props++; /* POWER_SUPPLY_PROP_VOLTAGE_MIN */
194194

195-
prop = kcalloc(props, sizeof(*prop), GFP_KERNEL);
195+
prop = devm_kcalloc(&dev->dev, props, sizeof(*prop), GFP_KERNEL);
196196
if (!prop)
197197
return -ENOMEM;
198198

@@ -224,12 +224,10 @@ static int wm97xx_bat_probe(struct platform_device *dev)
224224
bat_psy_desc.num_properties = props;
225225

226226
bat_psy = power_supply_register(&dev->dev, &bat_psy_desc, &cfg);
227-
if (!IS_ERR(bat_psy)) {
228-
schedule_work(&bat_work);
229-
} else {
230-
ret = PTR_ERR(bat_psy);
231-
goto free;
232-
}
227+
if (IS_ERR(bat_psy))
228+
return PTR_ERR(bat_psy);
229+
230+
schedule_work(&bat_work);
233231

234232
if (charge_gpiod) {
235233
ret = request_irq(gpiod_to_irq(charge_gpiod), wm97xx_chrg_irq,
@@ -246,9 +244,6 @@ static int wm97xx_bat_probe(struct platform_device *dev)
246244
unregister:
247245
power_supply_unregister(bat_psy);
248246

249-
free:
250-
kfree(prop);
251-
252247
return ret;
253248
}
254249

@@ -258,7 +253,6 @@ static void wm97xx_bat_remove(struct platform_device *dev)
258253
free_irq(gpiod_to_irq(charge_gpiod), dev);
259254
cancel_work_sync(&bat_work);
260255
power_supply_unregister(bat_psy);
261-
kfree(prop);
262256
}
263257

264258
static struct platform_driver wm97xx_bat_driver = {

0 commit comments

Comments
 (0)