Skip to content

Commit 1159c66

Browse files
author
Uwe Kleine-König
committed
staging: greybus: pwm: Make use of devm_pwmchip_alloc() function
This prepares the greybus pwm driver to further changes of the pwm core outlined in the commit introducing pwmchip_alloc(). There is no intended semantical change and the driver should behave as before. Reviewed-by: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/r/3206ab7f49c2c1704ea69446f3b7a7d1e71200fa.1707900770.git.u.kleine-koenig@pengutronix.de Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent e0d3277 commit 1159c66

File tree

1 file changed

+15
-18
lines changed
  • drivers/staging/greybus

1 file changed

+15
-18
lines changed

drivers/staging/greybus/pwm.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,11 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
249249
struct pwm_chip *chip;
250250
int ret, npwm;
251251

252-
pwmc = kzalloc(sizeof(*pwmc), GFP_KERNEL);
253-
if (!pwmc)
254-
return -ENOMEM;
255-
256252
connection = gb_connection_create(gbphy_dev->bundle,
257253
le16_to_cpu(gbphy_dev->cport_desc->id),
258254
NULL);
259-
if (IS_ERR(connection)) {
260-
ret = PTR_ERR(connection);
261-
goto exit_pwmc_free;
262-
}
263-
264-
pwmc->connection = connection;
265-
gb_gbphy_set_data(gbphy_dev, chip);
255+
if (IS_ERR(connection))
256+
return PTR_ERR(connection);
266257

267258
ret = gb_connection_enable(connection);
268259
if (ret)
@@ -274,28 +265,34 @@ static int gb_pwm_probe(struct gbphy_device *gbphy_dev,
274265
goto exit_connection_disable;
275266
npwm = ret;
276267

277-
chip = &pwmc->chip;
268+
chip = pwmchip_alloc(&gbphy_dev->dev, npwm, sizeof(*pwmc));
269+
if (IS_ERR(chip)) {
270+
ret = PTR_ERR(chip);
271+
goto exit_connection_disable;
272+
}
273+
gb_gbphy_set_data(gbphy_dev, chip);
274+
275+
pwmc = pwm_chip_to_gb_pwm_chip(chip);
276+
pwmc->connection = connection;
278277

279-
chip->dev = &gbphy_dev->dev;
280278
chip->ops = &gb_pwm_ops;
281-
chip->npwm = npwm;
282279

283280
ret = pwmchip_add(chip);
284281
if (ret) {
285282
dev_err(&gbphy_dev->dev,
286283
"failed to register PWM: %d\n", ret);
287-
goto exit_connection_disable;
284+
goto exit_pwmchip_put;
288285
}
289286

290287
gbphy_runtime_put_autosuspend(gbphy_dev);
291288
return 0;
292289

290+
exit_pwmchip_put:
291+
pwmchip_put(chip);
293292
exit_connection_disable:
294293
gb_connection_disable(connection);
295294
exit_connection_destroy:
296295
gb_connection_destroy(connection);
297-
exit_pwmc_free:
298-
kfree(pwmc);
299296
return ret;
300297
}
301298

@@ -311,9 +308,9 @@ static void gb_pwm_remove(struct gbphy_device *gbphy_dev)
311308
gbphy_runtime_get_noresume(gbphy_dev);
312309

313310
pwmchip_remove(chip);
311+
pwmchip_put(chip);
314312
gb_connection_disable(connection);
315313
gb_connection_destroy(connection);
316-
kfree(pwmc);
317314
}
318315

319316
static const struct gbphy_device_id gb_pwm_id_table[] = {

0 commit comments

Comments
 (0)