rtc: rework rtc_register_device() resource management

rtc_register_device() is a managed interface but it doesn't use devres
by itself - instead it marks an rtc_device as "registered" and the devres
callback for devm_rtc_allocate_device() takes care of resource release.

This doesn't correspond with the design behind devres where managed
structures should not be aware of being managed. The correct solution
here is to register a separate devres callback for unregistering the
device.

While at it: rename rtc_register_device() to devm_rtc_register_device()
and add it to the list of managed interfaces in devres.rst. This way we
can avoid any potential confusion of driver developers who may expect
there to exist a corresponding unregister function.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20201109163409.24301-8-brgl@bgdev.pl
This commit is contained in:
Bartosz Golaszewski
2020-11-19 12:50:12 +01:00
committed by Alexandre Belloni
parent 6746bc095b
commit fdcfd85433
114 changed files with 123 additions and 127 deletions
@@ -414,6 +414,7 @@ RESET
RTC RTC
devm_rtc_device_register() devm_rtc_device_register()
devm_rtc_allocate_device() devm_rtc_allocate_device()
devm_rtc_register_device()
devm_rtc_nvmem_register() devm_rtc_nvmem_register()
SERDEV SERDEV
+1 -1
View File
@@ -216,6 +216,6 @@ alpha_rtc_init(void)
rtc->ops = &remote_rtc_ops; rtc->ops = &remote_rtc_ops;
#endif #endif
return rtc_register_device(rtc); return devm_rtc_register_device(rtc);
} }
device_initcall(alpha_rtc_init); device_initcall(alpha_rtc_init);
+1 -1
View File
@@ -1119,7 +1119,7 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m)
menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control); menelaus_write_reg(MENELAUS_RTC_CTRL, m->rtc_control);
} }
err = rtc_register_device(m->rtc); err = devm_rtc_register_device(m->rtc);
if (err) { if (err) {
if (alarm) { if (alarm) {
menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ); menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ);
+9 -10
View File
@@ -321,8 +321,10 @@ static void rtc_device_get_offset(struct rtc_device *rtc)
* *
* @rtc: the RTC class device to destroy * @rtc: the RTC class device to destroy
*/ */
static void rtc_device_unregister(struct rtc_device *rtc) static void devm_rtc_unregister_device(void *data)
{ {
struct rtc_device *rtc = data;
mutex_lock(&rtc->ops_lock); mutex_lock(&rtc->ops_lock);
/* /*
* Remove innards of this RTC, then disable it, before * Remove innards of this RTC, then disable it, before
@@ -339,10 +341,7 @@ static void devm_rtc_release_device(struct device *dev, void *res)
{ {
struct rtc_device *rtc = *(struct rtc_device **)res; struct rtc_device *rtc = *(struct rtc_device **)res;
if (rtc->registered) put_device(&rtc->dev);
rtc_device_unregister(rtc);
else
put_device(&rtc->dev);
} }
struct rtc_device *devm_rtc_allocate_device(struct device *dev) struct rtc_device *devm_rtc_allocate_device(struct device *dev)
@@ -383,7 +382,7 @@ exit_ida:
} }
EXPORT_SYMBOL_GPL(devm_rtc_allocate_device); EXPORT_SYMBOL_GPL(devm_rtc_allocate_device);
int __rtc_register_device(struct module *owner, struct rtc_device *rtc) int __devm_rtc_register_device(struct module *owner, struct rtc_device *rtc)
{ {
struct rtc_wkalrm alrm; struct rtc_wkalrm alrm;
int err; int err;
@@ -413,7 +412,6 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
rtc_proc_add_device(rtc); rtc_proc_add_device(rtc);
rtc->registered = true;
dev_info(rtc->dev.parent, "registered as %s\n", dev_info(rtc->dev.parent, "registered as %s\n",
dev_name(&rtc->dev)); dev_name(&rtc->dev));
@@ -422,9 +420,10 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
rtc_hctosys(rtc); rtc_hctosys(rtc);
#endif #endif
return 0; return devm_add_action_or_reset(rtc->dev.parent,
devm_rtc_unregister_device, rtc);
} }
EXPORT_SYMBOL_GPL(__rtc_register_device); EXPORT_SYMBOL_GPL(__devm_rtc_register_device);
/** /**
* devm_rtc_device_register - resource managed rtc_device_register() * devm_rtc_device_register - resource managed rtc_device_register()
@@ -454,7 +453,7 @@ struct rtc_device *devm_rtc_device_register(struct device *dev,
rtc->ops = ops; rtc->ops = ops;
err = __rtc_register_device(owner, rtc); err = __devm_rtc_register_device(owner, rtc);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
+1 -1
View File
@@ -294,7 +294,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
info->rtc_dev->ops = &pm80x_rtc_ops; info->rtc_dev->ops = &pm80x_rtc_ops;
info->rtc_dev->range_max = U32_MAX; info->rtc_dev->range_max = U32_MAX;
ret = rtc_register_device(info->rtc_dev); ret = devm_rtc_register_device(info->rtc_dev);
if (ret) if (ret)
goto out_rtc; goto out_rtc;
+1 -1
View File
@@ -307,7 +307,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
info->rtc_dev->ops = &pm860x_rtc_ops; info->rtc_dev->ops = &pm860x_rtc_ops;
info->rtc_dev->range_max = U32_MAX; info->rtc_dev->range_max = U32_MAX;
ret = rtc_register_device(info->rtc_dev); ret = devm_rtc_register_device(info->rtc_dev);
if (ret) if (ret)
return ret; return ret;
+1 -1
View File
@@ -892,7 +892,7 @@ static int abb5zes3_probe(struct i2c_client *client,
} }
} }
ret = rtc_register_device(data->rtc); ret = devm_rtc_register_device(data->rtc);
err: err:
if (ret && data->irq) if (ret && data->irq)
+1 -1
View File
@@ -420,7 +420,7 @@ static int abeoz9_probe(struct i2c_client *client,
data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000; data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
data->rtc->range_max = RTC_TIMESTAMP_END_2099; data->rtc->range_max = RTC_TIMESTAMP_END_2099;
ret = rtc_register_device(data->rtc); ret = devm_rtc_register_device(data->rtc);
if (ret) if (ret)
return ret; return ret;
+1 -1
View File
@@ -238,7 +238,7 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
return rtc_register_device(rtc); return devm_rtc_register_device(rtc);
} }
static struct platform_driver ab3100_rtc_driver = { static struct platform_driver ab3100_rtc_driver = {
+1 -1
View File
@@ -404,7 +404,7 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
if (err) if (err)
return err; return err;
return rtc_register_device(rtc); return devm_rtc_register_device(rtc);
} }
static int ab8500_rtc_remove(struct platform_device *pdev) static int ab8500_rtc_remove(struct platform_device *pdev)
+1 -1
View File
@@ -851,7 +851,7 @@ static int abx80x_probe(struct i2c_client *client,
return err; return err;
} }
return rtc_register_device(priv->rtc); return devm_rtc_register_device(priv->rtc);
} }
static const struct i2c_device_id abx80x_id[] = { static const struct i2c_device_id abx80x_id[] = {
+1 -1
View File
@@ -610,7 +610,7 @@ static int ac100_rtc_probe(struct platform_device *pdev)
if (ret) if (ret)
return ret; return ret;
return rtc_register_device(chip->rtc); return devm_rtc_register_device(chip->rtc);
} }
static int ac100_rtc_remove(struct platform_device *pdev) static int ac100_rtc_remove(struct platform_device *pdev)
+1 -1
View File
@@ -556,7 +556,7 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev)
rtc->rtc_dev->range_max = U32_MAX; rtc->rtc_dev->range_max = U32_MAX;
return rtc_register_device(rtc->rtc_dev); return devm_rtc_register_device(rtc->rtc_dev);
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
+1 -1
View File
@@ -104,7 +104,7 @@ static int aspeed_rtc_probe(struct platform_device *pdev)
rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900; rtc->rtc_dev->range_min = RTC_TIMESTAMP_BEGIN_1900;
rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */ rtc->rtc_dev->range_max = 38814989399LL; /* 3199-12-31 23:59:59 */
return rtc_register_device(rtc->rtc_dev); return devm_rtc_register_device(rtc->rtc_dev);
} }
static const struct of_device_id aspeed_rtc_match[] = { static const struct of_device_id aspeed_rtc_match[] = {
+1 -1
View File
@@ -538,7 +538,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
rtc->range_min = RTC_TIMESTAMP_BEGIN_1900; rtc->range_min = RTC_TIMESTAMP_BEGIN_1900;
rtc->range_max = RTC_TIMESTAMP_END_2099; rtc->range_max = RTC_TIMESTAMP_END_2099;
ret = rtc_register_device(rtc); ret = devm_rtc_register_device(rtc);
if (ret) if (ret)
goto err_clk; goto err_clk;
+1 -1
View File
@@ -431,7 +431,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
dev_warn(&pdev->dev, "%s: SET TIME!\n", dev_warn(&pdev->dev, "%s: SET TIME!\n",
dev_name(&rtc->rtcdev->dev)); dev_name(&rtc->rtcdev->dev));
return rtc_register_device(rtc->rtcdev); return devm_rtc_register_device(rtc->rtcdev);
err_clk: err_clk:
clk_disable_unprepare(rtc->sclk); clk_disable_unprepare(rtc->sclk);
+1 -1
View File
@@ -104,7 +104,7 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, rtcdev); platform_set_drvdata(pdev, rtcdev);
return rtc_register_device(rtcdev); return devm_rtc_register_device(rtcdev);
} }
static struct platform_driver au1xrtc_driver = { static struct platform_driver au1xrtc_driver = {
+1 -1
View File
@@ -604,7 +604,7 @@ static int bd70528_probe(struct platform_device *pdev)
} }
} }
return rtc_register_device(rtc); return devm_rtc_register_device(rtc);
} }
static const struct platform_device_id bd718x7_rtc_id[] = { static const struct platform_device_id bd718x7_rtc_id[] = {
+1 -1
View File
@@ -252,7 +252,7 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev)
timer->rtc->ops = &brcmstb_waketmr_ops; timer->rtc->ops = &brcmstb_waketmr_ops;
timer->rtc->range_max = U32_MAX; timer->rtc->range_max = U32_MAX;
ret = rtc_register_device(timer->rtc); ret = devm_rtc_register_device(timer->rtc);
if (ret) if (ret)
goto err_notifier; goto err_notifier;
+1 -1
View File
@@ -336,7 +336,7 @@ static int cdns_rtc_probe(struct platform_device *pdev)
writel(0, crtc->regs + CDNS_RTC_HMR); writel(0, crtc->regs + CDNS_RTC_HMR);
writel(CDNS_RTC_KRTCR_KRTC, crtc->regs + CDNS_RTC_KRTCR); writel(CDNS_RTC_KRTCR_KRTC, crtc->regs + CDNS_RTC_KRTCR);
ret = rtc_register_device(crtc->rtc_dev); ret = devm_rtc_register_device(crtc->rtc_dev);
if (ret) if (ret)
goto err_disable_wakeup; goto err_disable_wakeup;

Some files were not shown because too many files have changed in this diff Show More