You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
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:
committed by
Alexandre Belloni
parent
6746bc095b
commit
fdcfd85433
@@ -414,6 +414,7 @@ RESET
|
||||
RTC
|
||||
devm_rtc_device_register()
|
||||
devm_rtc_allocate_device()
|
||||
devm_rtc_register_device()
|
||||
devm_rtc_nvmem_register()
|
||||
|
||||
SERDEV
|
||||
|
||||
@@ -216,6 +216,6 @@ alpha_rtc_init(void)
|
||||
rtc->ops = &remote_rtc_ops;
|
||||
#endif
|
||||
|
||||
return rtc_register_device(rtc);
|
||||
return devm_rtc_register_device(rtc);
|
||||
}
|
||||
device_initcall(alpha_rtc_init);
|
||||
|
||||
@@ -1119,7 +1119,7 @@ static inline void menelaus_rtc_init(struct menelaus_chip *m)
|
||||
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 (alarm) {
|
||||
menelaus_remove_irq_work(MENELAUS_RTCALM_IRQ);
|
||||
|
||||
@@ -321,8 +321,10 @@ static void rtc_device_get_offset(struct rtc_device *rtc)
|
||||
*
|
||||
* @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);
|
||||
/*
|
||||
* 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;
|
||||
|
||||
if (rtc->registered)
|
||||
rtc_device_unregister(rtc);
|
||||
else
|
||||
put_device(&rtc->dev);
|
||||
put_device(&rtc->dev);
|
||||
}
|
||||
|
||||
struct rtc_device *devm_rtc_allocate_device(struct device *dev)
|
||||
@@ -383,7 +382,7 @@ exit_ida:
|
||||
}
|
||||
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;
|
||||
int err;
|
||||
@@ -413,7 +412,6 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
|
||||
|
||||
rtc_proc_add_device(rtc);
|
||||
|
||||
rtc->registered = true;
|
||||
dev_info(rtc->dev.parent, "registered as %s\n",
|
||||
dev_name(&rtc->dev));
|
||||
|
||||
@@ -422,9 +420,10 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc)
|
||||
rtc_hctosys(rtc);
|
||||
#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()
|
||||
@@ -454,7 +453,7 @@ struct rtc_device *devm_rtc_device_register(struct device *dev,
|
||||
|
||||
rtc->ops = ops;
|
||||
|
||||
err = __rtc_register_device(owner, rtc);
|
||||
err = __devm_rtc_register_device(owner, rtc);
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
|
||||
info->rtc_dev->ops = &pm80x_rtc_ops;
|
||||
info->rtc_dev->range_max = U32_MAX;
|
||||
|
||||
ret = rtc_register_device(info->rtc_dev);
|
||||
ret = devm_rtc_register_device(info->rtc_dev);
|
||||
if (ret)
|
||||
goto out_rtc;
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
|
||||
info->rtc_dev->ops = &pm860x_rtc_ops;
|
||||
info->rtc_dev->range_max = U32_MAX;
|
||||
|
||||
ret = rtc_register_device(info->rtc_dev);
|
||||
ret = devm_rtc_register_device(info->rtc_dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
||||
@@ -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:
|
||||
if (ret && data->irq)
|
||||
|
||||
@@ -420,7 +420,7 @@ static int abeoz9_probe(struct i2c_client *client,
|
||||
data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
|
||||
data->rtc->range_max = RTC_TIMESTAMP_END_2099;
|
||||
|
||||
ret = rtc_register_device(data->rtc);
|
||||
ret = devm_rtc_register_device(data->rtc);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
|
||||
|
||||
platform_set_drvdata(pdev, rtc);
|
||||
|
||||
return rtc_register_device(rtc);
|
||||
return devm_rtc_register_device(rtc);
|
||||
}
|
||||
|
||||
static struct platform_driver ab3100_rtc_driver = {
|
||||
|
||||
@@ -404,7 +404,7 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return rtc_register_device(rtc);
|
||||
return devm_rtc_register_device(rtc);
|
||||
}
|
||||
|
||||
static int ab8500_rtc_remove(struct platform_device *pdev)
|
||||
|
||||
@@ -851,7 +851,7 @@ static int abx80x_probe(struct i2c_client *client,
|
||||
return err;
|
||||
}
|
||||
|
||||
return rtc_register_device(priv->rtc);
|
||||
return devm_rtc_register_device(priv->rtc);
|
||||
}
|
||||
|
||||
static const struct i2c_device_id abx80x_id[] = {
|
||||
|
||||
@@ -610,7 +610,7 @@ static int ac100_rtc_probe(struct platform_device *pdev)
|
||||
if (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)
|
||||
|
||||
@@ -556,7 +556,7 @@ static __init int armada38x_rtc_probe(struct platform_device *pdev)
|
||||
|
||||
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
|
||||
|
||||
@@ -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_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[] = {
|
||||
|
||||
@@ -538,7 +538,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
|
||||
|
||||
rtc->range_min = RTC_TIMESTAMP_BEGIN_1900;
|
||||
rtc->range_max = RTC_TIMESTAMP_END_2099;
|
||||
ret = rtc_register_device(rtc);
|
||||
ret = devm_rtc_register_device(rtc);
|
||||
if (ret)
|
||||
goto err_clk;
|
||||
|
||||
|
||||
@@ -431,7 +431,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
|
||||
dev_warn(&pdev->dev, "%s: SET TIME!\n",
|
||||
dev_name(&rtc->rtcdev->dev));
|
||||
|
||||
return rtc_register_device(rtc->rtcdev);
|
||||
return devm_rtc_register_device(rtc->rtcdev);
|
||||
|
||||
err_clk:
|
||||
clk_disable_unprepare(rtc->sclk);
|
||||
|
||||
@@ -104,7 +104,7 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
|
||||
|
||||
platform_set_drvdata(pdev, rtcdev);
|
||||
|
||||
return rtc_register_device(rtcdev);
|
||||
return devm_rtc_register_device(rtcdev);
|
||||
}
|
||||
|
||||
static struct platform_driver au1xrtc_driver = {
|
||||
|
||||
@@ -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[] = {
|
||||
|
||||
@@ -252,7 +252,7 @@ static int brcmstb_waketmr_probe(struct platform_device *pdev)
|
||||
timer->rtc->ops = &brcmstb_waketmr_ops;
|
||||
timer->rtc->range_max = U32_MAX;
|
||||
|
||||
ret = rtc_register_device(timer->rtc);
|
||||
ret = devm_rtc_register_device(timer->rtc);
|
||||
if (ret)
|
||||
goto err_notifier;
|
||||
|
||||
|
||||
@@ -336,7 +336,7 @@ static int cdns_rtc_probe(struct platform_device *pdev)
|
||||
writel(0, crtc->regs + CDNS_RTC_HMR);
|
||||
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)
|
||||
goto err_disable_wakeup;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user