* [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers
@ 2023-08-26 3:54 Jinjie Ruan
2023-08-26 3:54 ` [PATCH -next 1/2] iio: adc: mt6577_auxadc: Simplify with dev_err_probe() Jinjie Ruan
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Jinjie Ruan @ 2023-08-26 3:54 UTC (permalink / raw)
To: jic23, lars, matthias.bgg, angelogioacchino.delregno, linux-iio,
linux-arm-kernel, linux-mediatek
Cc: ruanjinjie
Use the dev_err_probe() helper to simplify error handling during probe.
This also handle scenario, when EDEFER is returned and useless
error is printed.
And use devm_add_action_or_reset() and devm_iio_device_register()
to simplify the code.
Jinjie Ruan (2):
iio: adc: mt6577_auxadc: Simplify with dev_err_probe()
iio: adc: mt6577_auxadc: Simplify with device managed function
drivers/iio/adc/mt6577_auxadc.c | 60 +++++++++++++--------------------
1 file changed, 23 insertions(+), 37 deletions(-)
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH -next 1/2] iio: adc: mt6577_auxadc: Simplify with dev_err_probe() 2023-08-26 3:54 [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers Jinjie Ruan @ 2023-08-26 3:54 ` Jinjie Ruan 2023-09-13 8:56 ` AngeloGioacchino Del Regno 2023-08-26 3:54 ` [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function Jinjie Ruan 2023-08-27 17:07 ` [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers Jonathan Cameron 2 siblings, 1 reply; 8+ messages in thread From: Jinjie Ruan @ 2023-08-26 3:54 UTC (permalink / raw) To: jic23, lars, matthias.bgg, angelogioacchino.delregno, linux-iio, linux-arm-kernel, linux-mediatek Cc: ruanjinjie Use the dev_err_probe() helper to simplify error handling during probe. This also handle scenario, when EDEFER is returned and useless error is printed. Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Suggested-by: Jonathan Cameron <jic23@kernel.org> --- drivers/iio/adc/mt6577_auxadc.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c index ea42fd7a8c99..935cf560e238 100644 --- a/drivers/iio/adc/mt6577_auxadc.c +++ b/drivers/iio/adc/mt6577_auxadc.c @@ -265,22 +265,18 @@ static int mt6577_auxadc_probe(struct platform_device *pdev) indio_dev->num_channels = ARRAY_SIZE(mt6577_auxadc_iio_channels); adc_dev->reg_base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(adc_dev->reg_base)) { - dev_err(&pdev->dev, "failed to get auxadc base address\n"); - return PTR_ERR(adc_dev->reg_base); - } + if (IS_ERR(adc_dev->reg_base)) + return dev_err_probe(&pdev->dev, PTR_ERR(adc_dev->reg_base), + "failed to get auxadc base address\n"); adc_dev->adc_clk = devm_clk_get_enabled(&pdev->dev, "main"); - if (IS_ERR(adc_dev->adc_clk)) { - dev_err(&pdev->dev, "failed to enable auxadc clock\n"); - return PTR_ERR(adc_dev->adc_clk); - } + if (IS_ERR(adc_dev->adc_clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(adc_dev->adc_clk), + "failed to enable auxadc clock\n"); adc_clk_rate = clk_get_rate(adc_dev->adc_clk); - if (!adc_clk_rate) { - dev_err(&pdev->dev, "null clock rate\n"); - return -EINVAL; - } + if (!adc_clk_rate) + return dev_err_probe(&pdev->dev, -EINVAL, "null clock rate\n"); adc_dev->dev_comp = device_get_match_data(&pdev->dev); -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH -next 1/2] iio: adc: mt6577_auxadc: Simplify with dev_err_probe() 2023-08-26 3:54 ` [PATCH -next 1/2] iio: adc: mt6577_auxadc: Simplify with dev_err_probe() Jinjie Ruan @ 2023-09-13 8:56 ` AngeloGioacchino Del Regno 0 siblings, 0 replies; 8+ messages in thread From: AngeloGioacchino Del Regno @ 2023-09-13 8:56 UTC (permalink / raw) To: Jinjie Ruan, jic23, lars, matthias.bgg, linux-iio, linux-arm-kernel, linux-mediatek Il 26/08/23 05:54, Jinjie Ruan ha scritto: > Use the dev_err_probe() helper to simplify error handling during probe. > This also handle scenario, when EDEFER is returned and useless error > is printed. > > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> > Suggested-by: Jonathan Cameron <jic23@kernel.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function 2023-08-26 3:54 [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers Jinjie Ruan 2023-08-26 3:54 ` [PATCH -next 1/2] iio: adc: mt6577_auxadc: Simplify with dev_err_probe() Jinjie Ruan @ 2023-08-26 3:54 ` Jinjie Ruan 2023-08-27 17:04 ` Jonathan Cameron 2023-09-13 8:56 ` AngeloGioacchino Del Regno 2023-08-27 17:07 ` [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers Jonathan Cameron 2 siblings, 2 replies; 8+ messages in thread From: Jinjie Ruan @ 2023-08-26 3:54 UTC (permalink / raw) To: jic23, lars, matthias.bgg, angelogioacchino.delregno, linux-iio, linux-arm-kernel, linux-mediatek Cc: ruanjinjie Add a device managed hook, via devm_add_action_or_reset() and mt6577_power_off(), to power off on device detach. Replace iio_device_register() by devm_iio_device_register() and remove the mt6577_auxadc_remove() function used to unregister the device and power off the device. Remove platform_set_drvdata() from the probe function, since platform_get_drvdata() is not used anymore. Remove mt6577_auxadc_mod_reg() call from the probe function error path. Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Suggested-by: Jonathan Cameron <jic23@kernel.org> --- drivers/iio/adc/mt6577_auxadc.c | 40 +++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c index 935cf560e238..c8f7bfa59146 100644 --- a/drivers/iio/adc/mt6577_auxadc.c +++ b/drivers/iio/adc/mt6577_auxadc.c @@ -246,6 +246,14 @@ static int mt6577_auxadc_suspend(struct device *dev) return 0; } +static void mt6577_power_off(void *data) +{ + struct mt6577_auxadc_device *adc_dev = data; + + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, + 0, MT6577_AUXADC_PDN_EN); +} + static int mt6577_auxadc_probe(struct platform_device *pdev) { struct mt6577_auxadc_device *adc_dev; @@ -286,31 +294,14 @@ static int mt6577_auxadc_probe(struct platform_device *pdev) MT6577_AUXADC_PDN_EN, 0); mdelay(MT6577_AUXADC_POWER_READY_MS); - platform_set_drvdata(pdev, indio_dev); - - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(&pdev->dev, "failed to register iio device\n"); - goto err_power_off; - } - - return 0; + ret = devm_add_action_or_reset(&pdev->dev, mt6577_power_off, adc_dev); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Failed to add action to managed power off: %d\n", ret); -err_power_off: - mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, - 0, MT6577_AUXADC_PDN_EN); - return ret; -} - -static int mt6577_auxadc_remove(struct platform_device *pdev) -{ - struct iio_dev *indio_dev = platform_get_drvdata(pdev); - struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev); - - iio_device_unregister(indio_dev); - - mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, - 0, MT6577_AUXADC_PDN_EN); + ret = devm_iio_device_register(&pdev->dev, indio_dev); + if (ret < 0) + return dev_err_probe(&pdev->dev, ret, "failed to register iio device\n"); return 0; } @@ -337,7 +328,6 @@ static struct platform_driver mt6577_auxadc_driver = { .pm = pm_sleep_ptr(&mt6577_auxadc_pm_ops), }, .probe = mt6577_auxadc_probe, - .remove = mt6577_auxadc_remove, }; module_platform_driver(mt6577_auxadc_driver); -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function 2023-08-26 3:54 ` [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function Jinjie Ruan @ 2023-08-27 17:04 ` Jonathan Cameron 2023-09-13 8:56 ` AngeloGioacchino Del Regno 1 sibling, 0 replies; 8+ messages in thread From: Jonathan Cameron @ 2023-08-27 17:04 UTC (permalink / raw) To: Jinjie Ruan Cc: lars, matthias.bgg, angelogioacchino.delregno, linux-iio, linux-arm-kernel, linux-mediatek On Sat, 26 Aug 2023 11:54:02 +0800 Jinjie Ruan <ruanjinjie@huawei.com> wrote: > Add a device managed hook, via devm_add_action_or_reset() and > mt6577_power_off(), to power off on device detach. > > Replace iio_device_register() by devm_iio_device_register() and remove > the mt6577_auxadc_remove() function used to unregister the device and > power off the device. > > Remove platform_set_drvdata() from the probe function, since > platform_get_drvdata() is not used anymore. > > Remove mt6577_auxadc_mod_reg() call from the probe function error path. > > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> > Suggested-by: Jonathan Cameron <jic23@kernel.org> > --- > drivers/iio/adc/mt6577_auxadc.c | 40 +++++++++++++-------------------- > 1 file changed, 15 insertions(+), 25 deletions(-) > > diff --git a/drivers/iio/adc/mt6577_auxadc.c b/drivers/iio/adc/mt6577_auxadc.c > index 935cf560e238..c8f7bfa59146 100644 > --- a/drivers/iio/adc/mt6577_auxadc.c > +++ b/drivers/iio/adc/mt6577_auxadc.c > @@ -246,6 +246,14 @@ static int mt6577_auxadc_suspend(struct device *dev) > return 0; > } > > +static void mt6577_power_off(void *data) > +{ > + struct mt6577_auxadc_device *adc_dev = data; > + > + mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, > + 0, MT6577_AUXADC_PDN_EN); > +} > + > static int mt6577_auxadc_probe(struct platform_device *pdev) > { > struct mt6577_auxadc_device *adc_dev; > @@ -286,31 +294,14 @@ static int mt6577_auxadc_probe(struct platform_device *pdev) > MT6577_AUXADC_PDN_EN, 0); > mdelay(MT6577_AUXADC_POWER_READY_MS); > > - platform_set_drvdata(pdev, indio_dev); > - > - ret = iio_device_register(indio_dev); > - if (ret < 0) { > - dev_err(&pdev->dev, "failed to register iio device\n"); > - goto err_power_off; > - } > - > - return 0; > + ret = devm_add_action_or_reset(&pdev->dev, mt6577_power_off, adc_dev); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, > + "Failed to add action to managed power off: %d\n", ret); The return code is already printed when dev_err_probe() formats the line, so I've dropped that last bit whilst applying. The way these two patches were separated is a little odd as you ignore a few dev_err() cases in patch 1 because they don't make sense until patch 2. I think this would have made more sense with the two patches reversed. Still that's a very small thing (and I might be wrong as I didn't try it ;) Applied to the togreg branch of iio.git and pushed out as testing for 0-day etc to play with this. I'll be rebasing on rc1 and it won't hit linux-next until after that. Thanks, Jonathan > > -err_power_off: > - mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, > - 0, MT6577_AUXADC_PDN_EN); > - return ret; > -} > - > -static int mt6577_auxadc_remove(struct platform_device *pdev) > -{ > - struct iio_dev *indio_dev = platform_get_drvdata(pdev); > - struct mt6577_auxadc_device *adc_dev = iio_priv(indio_dev); > - > - iio_device_unregister(indio_dev); > - > - mt6577_auxadc_mod_reg(adc_dev->reg_base + MT6577_AUXADC_MISC, > - 0, MT6577_AUXADC_PDN_EN); > + ret = devm_iio_device_register(&pdev->dev, indio_dev); > + if (ret < 0) > + return dev_err_probe(&pdev->dev, ret, "failed to register iio device\n"); > > return 0; > } > @@ -337,7 +328,6 @@ static struct platform_driver mt6577_auxadc_driver = { > .pm = pm_sleep_ptr(&mt6577_auxadc_pm_ops), > }, > .probe = mt6577_auxadc_probe, > - .remove = mt6577_auxadc_remove, > }; > module_platform_driver(mt6577_auxadc_driver); > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function 2023-08-26 3:54 ` [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function Jinjie Ruan 2023-08-27 17:04 ` Jonathan Cameron @ 2023-09-13 8:56 ` AngeloGioacchino Del Regno 2023-09-13 19:17 ` Jonathan Cameron 1 sibling, 1 reply; 8+ messages in thread From: AngeloGioacchino Del Regno @ 2023-09-13 8:56 UTC (permalink / raw) To: Jinjie Ruan, jic23, lars, matthias.bgg, linux-iio, linux-arm-kernel, linux-mediatek Il 26/08/23 05:54, Jinjie Ruan ha scritto: > Add a device managed hook, via devm_add_action_or_reset() and > mt6577_power_off(), to power off on device detach. > > Replace iio_device_register() by devm_iio_device_register() and remove > the mt6577_auxadc_remove() function used to unregister the device and > power off the device. > > Remove platform_set_drvdata() from the probe function, since > platform_get_drvdata() is not used anymore. > > Remove mt6577_auxadc_mod_reg() call from the probe function error path. > > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> > Suggested-by: Jonathan Cameron <jic23@kernel.org> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function 2023-09-13 8:56 ` AngeloGioacchino Del Regno @ 2023-09-13 19:17 ` Jonathan Cameron 0 siblings, 0 replies; 8+ messages in thread From: Jonathan Cameron @ 2023-09-13 19:17 UTC (permalink / raw) To: AngeloGioacchino Del Regno Cc: Jinjie Ruan, lars, matthias.bgg, linux-iio, linux-arm-kernel, linux-mediatek On Wed, 13 Sep 2023 10:56:28 +0200 AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> wrote: > Il 26/08/23 05:54, Jinjie Ruan ha scritto: > > Add a device managed hook, via devm_add_action_or_reset() and > > mt6577_power_off(), to power off on device detach. > > > > Replace iio_device_register() by devm_iio_device_register() and remove > > the mt6577_auxadc_remove() function used to unregister the device and > > power off the device. > > > > Remove platform_set_drvdata() from the probe function, since > > platform_get_drvdata() is not used anymore. > > > > Remove mt6577_auxadc_mod_reg() call from the probe function error path. > > > > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> > > Suggested-by: Jonathan Cameron <jic23@kernel.org> > > Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> > Just missed. I finally pushed this out as non rebasing (rebased on rc1) on Monday. Still the patches have a link back to here I think so people can see this if they come looking! Thanks Jonathan _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers 2023-08-26 3:54 [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers Jinjie Ruan 2023-08-26 3:54 ` [PATCH -next 1/2] iio: adc: mt6577_auxadc: Simplify with dev_err_probe() Jinjie Ruan 2023-08-26 3:54 ` [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function Jinjie Ruan @ 2023-08-27 17:07 ` Jonathan Cameron 2 siblings, 0 replies; 8+ messages in thread From: Jonathan Cameron @ 2023-08-27 17:07 UTC (permalink / raw) To: Jinjie Ruan Cc: lars, matthias.bgg, angelogioacchino.delregno, linux-iio, linux-arm-kernel, linux-mediatek On Sat, 26 Aug 2023 11:54:00 +0800 Jinjie Ruan <ruanjinjie@huawei.com> wrote: > Use the dev_err_probe() helper to simplify error handling during probe. > This also handle scenario, when EDEFER is returned and useless > error is printed. Just a quick note to the driver maintainers. Whilst I've applied this, I won't be pushing that out as a non rebasing tree for a few weeks. As such I'm very happy to add tags, or indeed to drop it if you see any changes you would like. Taking it quickly is mostly because I have a huge backlog having been away and want to get the simple stuff off that list! Thanks, Jonathan > > And use devm_add_action_or_reset() and devm_iio_device_register() > to simplify the code. > > Jinjie Ruan (2): > iio: adc: mt6577_auxadc: Simplify with dev_err_probe() > iio: adc: mt6577_auxadc: Simplify with device managed function > > drivers/iio/adc/mt6577_auxadc.c | 60 +++++++++++++-------------------- > 1 file changed, 23 insertions(+), 37 deletions(-) > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-09-13 19:18 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-26 3:54 [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers Jinjie Ruan 2023-08-26 3:54 ` [PATCH -next 1/2] iio: adc: mt6577_auxadc: Simplify with dev_err_probe() Jinjie Ruan 2023-09-13 8:56 ` AngeloGioacchino Del Regno 2023-08-26 3:54 ` [PATCH -next 2/2] iio: adc: mt6577_auxadc: Simplify with device managed function Jinjie Ruan 2023-08-27 17:04 ` Jonathan Cameron 2023-09-13 8:56 ` AngeloGioacchino Del Regno 2023-09-13 19:17 ` Jonathan Cameron 2023-08-27 17:07 ` [PATCH -next 0/2] iio: adc: mt6577_auxadc: Cleanup with the helpers Jonathan Cameron
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox