Message ID | fbfb1852838820c198d55bc74940a74f1d0b53ed.1521794177.git.sean.wang@mediatek.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
On 23/03/2018 at 17:15:06 +0800, sean.wang@mediatek.com wrote: > From: Sean Wang <sean.wang@mediatek.com> > > Use device managed operation to simplify error handling, reduce source > code size, and reduce the likelyhood of bugs, and remove our removal > callback which contains anything already done by device managed functions. > > Signed-off-by: Sean Wang <sean.wang@mediatek.com> > --- > drivers/rtc/rtc-mt6397.c | 31 ++++++++----------------------- > 1 file changed, 8 insertions(+), 23 deletions(-) > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c > index cefb83b..bfc5d6f 100644 > --- a/drivers/rtc/rtc-mt6397.c > +++ b/drivers/rtc/rtc-mt6397.c > @@ -14,6 +14,7 @@ > > #include <linux/delay.h> > #include <linux/init.h> > +#include <linux/interrupt.h> > #include <linux/module.h> > #include <linux/regmap.h> > #include <linux/rtc.h> > @@ -328,10 +329,10 @@ static int mtk_rtc_probe(struct platform_device *pdev) > > platform_set_drvdata(pdev, rtc); > > - ret = request_threaded_irq(rtc->irq, NULL, > - mtk_rtc_irq_handler_thread, > - IRQF_ONESHOT | IRQF_TRIGGER_HIGH, > - "mt6397-rtc", rtc); > + ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, > + mtk_rtc_irq_handler_thread, > + IRQF_ONESHOT | IRQF_TRIGGER_HIGH, > + "mt6397-rtc", rtc); > if (ret) { > dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", > rtc->irq, ret); > @@ -340,30 +341,15 @@ static int mtk_rtc_probe(struct platform_device *pdev) > > device_init_wakeup(&pdev->dev, 1); > > - rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev, > - &mtk_rtc_ops, THIS_MODULE); > + rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "mt6397-rtc", > + &mtk_rtc_ops, THIS_MODULE); You should probably switch to devm_rtc_allocate_device() and rtc_register_device instead of devm_rtc_device_register. > if (IS_ERR(rtc->rtc_dev)) { > dev_err(&pdev->dev, "register rtc device failed\n"); > ret = PTR_ERR(rtc->rtc_dev); > - goto out_free_irq; > + return ret; ret doesn't seem necessary anymore here.
On Fri, 2018-03-23 at 11:50 +0100, Alexandre Belloni wrote: > On 23/03/2018 at 17:15:06 +0800, sean.wang@mediatek.com wrote: > > From: Sean Wang <sean.wang@mediatek.com> > > > > Use device managed operation to simplify error handling, reduce source > > code size, and reduce the likelyhood of bugs, and remove our removal > > callback which contains anything already done by device managed functions. > > > > Signed-off-by: Sean Wang <sean.wang@mediatek.com> > > --- > > drivers/rtc/rtc-mt6397.c | 31 ++++++++----------------------- > > 1 file changed, 8 insertions(+), 23 deletions(-) > > > > diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c > > index cefb83b..bfc5d6f 100644 > > --- a/drivers/rtc/rtc-mt6397.c > > +++ b/drivers/rtc/rtc-mt6397.c > > @@ -14,6 +14,7 @@ > > > > #include <linux/delay.h> > > #include <linux/init.h> > > +#include <linux/interrupt.h> > > #include <linux/module.h> > > #include <linux/regmap.h> > > #include <linux/rtc.h> > > @@ -328,10 +329,10 @@ static int mtk_rtc_probe(struct platform_device *pdev) > > > > platform_set_drvdata(pdev, rtc); > > > > - ret = request_threaded_irq(rtc->irq, NULL, > > - mtk_rtc_irq_handler_thread, > > - IRQF_ONESHOT | IRQF_TRIGGER_HIGH, > > - "mt6397-rtc", rtc); > > + ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, > > + mtk_rtc_irq_handler_thread, > > + IRQF_ONESHOT | IRQF_TRIGGER_HIGH, > > + "mt6397-rtc", rtc); > > if (ret) { > > dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", > > rtc->irq, ret); > > @@ -340,30 +341,15 @@ static int mtk_rtc_probe(struct platform_device *pdev) > > > > device_init_wakeup(&pdev->dev, 1); > > > > - rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev, > > - &mtk_rtc_ops, THIS_MODULE); > > + rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "mt6397-rtc", > > + &mtk_rtc_ops, THIS_MODULE); > > You should probably switch to devm_rtc_allocate_device() and > rtc_register_device instead of devm_rtc_device_register. > Just would like to know something details It seems you just encourage me to switch into the new registration method and currently devm_rtc_device_register I used for the driver shouldn't cause any harm. right? > > if (IS_ERR(rtc->rtc_dev)) { > > dev_err(&pdev->dev, "register rtc device failed\n"); > > ret = PTR_ERR(rtc->rtc_dev); > > - goto out_free_irq; > > + return ret; > > ret doesn't seem necessary anymore here. okay, it'll be removed > >
On 26/03/2018 at 12:07:45 +0800, Sean Wang wrote: > > > - rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev, > > > - &mtk_rtc_ops, THIS_MODULE); > > > + rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "mt6397-rtc", > > > + &mtk_rtc_ops, THIS_MODULE); > > > > You should probably switch to devm_rtc_allocate_device() and > > rtc_register_device instead of devm_rtc_device_register. > > > > Just would like to know something details > > It seems you just encourage me to switch into the new registration > method and currently devm_rtc_device_register I used for the driver > shouldn't cause any harm. right? > It will work but it will have to be converted to rtc_register_device later anyway.
diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c index cefb83b..bfc5d6f 100644 --- a/drivers/rtc/rtc-mt6397.c +++ b/drivers/rtc/rtc-mt6397.c @@ -14,6 +14,7 @@ #include <linux/delay.h> #include <linux/init.h> +#include <linux/interrupt.h> #include <linux/module.h> #include <linux/regmap.h> #include <linux/rtc.h> @@ -328,10 +329,10 @@ static int mtk_rtc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, rtc); - ret = request_threaded_irq(rtc->irq, NULL, - mtk_rtc_irq_handler_thread, - IRQF_ONESHOT | IRQF_TRIGGER_HIGH, - "mt6397-rtc", rtc); + ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, + mtk_rtc_irq_handler_thread, + IRQF_ONESHOT | IRQF_TRIGGER_HIGH, + "mt6397-rtc", rtc); if (ret) { dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", rtc->irq, ret); @@ -340,30 +341,15 @@ static int mtk_rtc_probe(struct platform_device *pdev) device_init_wakeup(&pdev->dev, 1); - rtc->rtc_dev = rtc_device_register("mt6397-rtc", &pdev->dev, - &mtk_rtc_ops, THIS_MODULE); + rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "mt6397-rtc", + &mtk_rtc_ops, THIS_MODULE); if (IS_ERR(rtc->rtc_dev)) { dev_err(&pdev->dev, "register rtc device failed\n"); ret = PTR_ERR(rtc->rtc_dev); - goto out_free_irq; + return ret; } return 0; - -out_free_irq: - free_irq(rtc->irq, rtc->rtc_dev); - - return ret; -} - -static int mtk_rtc_remove(struct platform_device *pdev) -{ - struct mt6397_rtc *rtc = platform_get_drvdata(pdev); - - rtc_device_unregister(rtc->rtc_dev); - free_irq(rtc->irq, rtc->rtc_dev); - - return 0; } #ifdef CONFIG_PM_SLEEP @@ -405,7 +391,6 @@ static struct platform_driver mtk_rtc_driver = { .pm = &mt6397_pm_ops, }, .probe = mtk_rtc_probe, - .remove = mtk_rtc_remove, }; module_platform_driver(mtk_rtc_driver);