Skip to content

Commit 896c450

Browse files
Uwe Kleine-Königthierryreding
authored andcommitted
pwm: cros-ec: Simplify using devm_pwmchip_add() and dev_err_probe()
Using devm_pwmchip_add() allows to drop pwmchip_remove() from the remove function which makes this function empty. Then there is no user of drvdata left and platform_set_drvdata() can be dropped, too. Further simplify and improve error returning using dev_err_probe(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 9608405 commit 896c450

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

drivers/pwm/pwm-cros-ec.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,8 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
265265
struct pwm_chip *chip;
266266
int ret;
267267

268-
if (!ec) {
269-
dev_err(dev, "no parent EC device\n");
270-
return -EINVAL;
271-
}
268+
if (!ec)
269+
return dev_err_probe(dev, -EINVAL, "no parent EC device\n");
272270

273271
ec_pwm = devm_kzalloc(dev, sizeof(*ec_pwm), GFP_KERNEL);
274272
if (!ec_pwm)
@@ -289,10 +287,8 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
289287
chip->npwm = CROS_EC_PWM_DT_COUNT;
290288
} else {
291289
ret = cros_ec_num_pwms(ec_pwm);
292-
if (ret < 0) {
293-
dev_err(dev, "Couldn't find PWMs: %d\n", ret);
294-
return ret;
295-
}
290+
if (ret < 0)
291+
return dev_err_probe(dev, ret, "Couldn't find PWMs\n");
296292
chip->npwm = ret;
297293
}
298294

@@ -303,23 +299,11 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
303299

304300
dev_dbg(dev, "Probed %u PWMs\n", chip->npwm);
305301

306-
ret = pwmchip_add(chip);
307-
if (ret < 0) {
308-
dev_err(dev, "cannot register PWM: %d\n", ret);
309-
return ret;
310-
}
311-
312-
platform_set_drvdata(pdev, ec_pwm);
313-
314-
return ret;
315-
}
316-
317-
static void cros_ec_pwm_remove(struct platform_device *dev)
318-
{
319-
struct cros_ec_pwm_device *ec_pwm = platform_get_drvdata(dev);
320-
struct pwm_chip *chip = &ec_pwm->chip;
302+
ret = devm_pwmchip_add(dev, chip);
303+
if (ret < 0)
304+
return dev_err_probe(dev, ret, "cannot register PWM\n");
321305

322-
pwmchip_remove(chip);
306+
return 0;
323307
}
324308

325309
#ifdef CONFIG_OF
@@ -333,7 +317,6 @@ MODULE_DEVICE_TABLE(of, cros_ec_pwm_of_match);
333317

334318
static struct platform_driver cros_ec_pwm_driver = {
335319
.probe = cros_ec_pwm_probe,
336-
.remove_new = cros_ec_pwm_remove,
337320
.driver = {
338321
.name = "cros-ec-pwm",
339322
.of_match_table = of_match_ptr(cros_ec_pwm_of_match),

0 commit comments

Comments
 (0)