Add and use DEVM soc_device_register helper
Subsystems (11)
cover Add and use DEVM soc_device_register helper
Hello all,
Add device managed devm_soc_device_register() to automatically unregister soc_devices thus leading to simplified SOC driver code.
Use this new helper for drivers which currently unregister manually and have a device to tie to this new automatic unregistration.
Thanks,
Andrew
Andrew Davis (12):
base: soc: Implement devm_soc_device_register() helper function
soc: ep93xx: Use devm_soc_device_register() helper
soc: imx8m: Use devm_soc_device_register() helper
soc: imx9: Use devm_soc_device_register() helper
soc: loongson: Use devm_soc_device_register() helper
soc: mediatek: mtk-socinfo: Use devm_soc_device_register() helper
soc: qcom: socinfo: Use devm_soc_device_register() helper
soc: renesas: rz-sysc: Use devm_soc_device_register() helper
soc: samsung: exynos-chipid: Use devm_soc_device_register() helper
soc: ti: k3-socinfo: Use devm_soc_device_register() helper
soc: versatile: realview: Use devm_soc_device_register() helper
soc: vt8500: Use devm_soc_device_register() helper
drivers/base/soc.c | 23 +++++++++++++++++++++++ drivers/soc/cirrus/soc-ep93xx.c | 2 +- drivers/soc/imx/soc-imx8m.c | 11 +---------- drivers/soc/imx/soc-imx9.c | 2 +- drivers/soc/loongson/loongson2_guts.c | 10 ++-------- drivers/soc/mediatek/mtk-socinfo.c | 17 ++++------------- drivers/soc/qcom/socinfo.c | 4 +--- drivers/soc/renesas/rz-sysc.c | 2 +- drivers/soc/samsung/exynos-chipid.c | 12 +----------- drivers/soc/ti/k3-socinfo.c | 2 +- drivers/soc/versatile/soc-realview.c | 14 +------------- drivers/soc/vt8500/wmt-socinfo.c | 11 +---------- include/linux/sys_soc.h | 16 ++++++++++++++++ 13 files changed, 54 insertions(+), 72 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/12 base: soc: Implement devm_soc_device_register() helper function
Add device managed devm_soc_device_register() to automatically unregister soc_devices thus leading to simplified SOC driver code.
--- drivers/base/soc.c | 23 +++++++++++++++++++++++ include/linux/sys_soc.h | 16 ++++++++++++++++ 2 files changed, 39 insertions(+)
drivers/base/soc.c +23 -0
@@ -189,6 +189,29 @@ void soc_device_unregister(struct soc_device *soc_dev) }EXPORT_SYMBOL_GPL (soc_device_unregister); +static void devm_soc_device_unregister (void *soc_dev) +{ +soc_device_unregister (soc_dev); +} + +struct soc_device *devm_soc_device_register (struct device *dev, +struct soc_device_attribute *soc_dev_attr) +{ +struct soc_device *soc_dev; +int ret; + + soc_dev =soc_device_register (soc_dev_attr); +if (IS_ERR_OR_NULL (soc_dev)) +return soc_dev; + + ret =devm_add_action_or_reset (dev, devm_soc_device_unregister, soc_dev); +if (ret) +return ERR_PTR (ret); + +return soc_dev; +} +EXPORT_SYMBOL_GPL (devm_soc_device_register); +static int __init soc_bus_register (void ) {struct soc_device *soc_dev;
include/linux/sys_soc.h +16 -0
@@ -36,6 +36,22 @@ struct soc_device *soc_device_register(*/ void soc_device_unregister (struct soc_device *soc_dev); +/** +* devm_soc_device_register - Resource-managed soc_device_register() +* @dev: Device to register soc_dev for. +* @soc_plat_dev_attr: Attributes passed from platform to be attributed to a SoC +* +* Managed soc_device_register. soc_dev registered with this function is +* automatically unregistered on driver detach. +* +* Returns: +* - %NULL if the SoC bus is not yet registered; +* - on success, the newly allocated &struct soc_device pointer; +* - on failure, a negative error code as an ERR_PTR(). +*/ +struct soc_device *devm_soc_device_register (struct device *dev, +struct soc_device_attribute *soc_dev_attr); +/** * soc_device_to_device - helper function to fetch struct device * @soc: Previously registered SoC device container
Signature · 1 line
2.43.0
PATCH 2/12 soc: ep93xx: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/cirrus/soc-ep93xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/cirrus/soc-ep93xx.c +1 -1
@@ -199,7 +199,7 @@ static int __init ep93xx_syscon_probe(struct platform_device *pdev) attrs->family ="Cirrus Logic EP93xx" ; attrs->revision =ep93xx_get_soc_rev (rev); - soc_dev =soc_device_register (attrs); + soc_dev =devm_soc_device_register (dev, attrs);if (IS_ERR (soc_dev))return PTR_ERR (soc_dev);
Signature · 1 line
2.43.0
PATCH 3/12 soc: imx8m: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/imx/soc-imx8m.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/soc/imx/soc-imx8m.c +1 -10
@@ -209,11 +209,6 @@ static __maybe_unused const struct of_device_id imx8_soc_match[] = { devm_kasprintf((dev), GFP_KERNEL, "%d.%d", ((soc_rev) >> 4) & 0xf, (soc_rev) & 0xf) : \ "unknown" -static void imx8m_unregister_soc(void *data) -{ -soc_device_unregister (data); -} - static void imx8m_unregister_cpufreq(void *data) {platform_device_unregister (data);
@@ -284,14 +279,10 @@ static int imx8m_soc_probe(struct platform_device *pdev)if (!soc_dev_attr->serial_number)return -ENOMEM ; - soc_dev =soc_device_register (soc_dev_attr); + soc_dev =devm_soc_device_register (dev, soc_dev_attr);if (IS_ERR (soc_dev))return PTR_ERR (soc_dev); - ret =devm_add_action (dev, imx8m_unregister_soc, soc_dev); -if (ret) -return ret; -pr_info ("SoC: %s revision %s\n" , soc_dev_attr->soc_id, soc_dev_attr->revision);
Signature · 1 line
2.43.0
PATCH 4/12 soc: imx9: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/imx/soc-imx9.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/imx/soc-imx9.c +1 -1
@@ -67,7 +67,7 @@ static int imx9_soc_probe(struct platform_device *pdev)if (!attr->serial_number)return -ENOMEM ; - sdev =soc_device_register (attr); + sdev =devm_soc_device_register (dev, attr);if (IS_ERR (sdev))return dev_err_probe (dev,PTR_ERR (sdev),"%s failed to register SoC as a device\n" , __func__);
Signature · 1 line
2.43.0
PATCH 5/12 soc: loongson: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/loongson/loongson2_guts.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/soc/loongson/loongson2_guts.c +2 -8
@@ -13,7 +13,6 @@#include <linux/platform_device.h> static struct soc_device_attribute soc_dev_attr; -static struct soc_device *soc_dev;/* * Global Utility Registers.
@@ -95,6 +94,7 @@ static int loongson2_guts_probe(struct platform_device *pdev)struct device *dev = &pdev->dev;struct device_node *np = pdev->dev.of_node;const struct loongson2_soc_die_attr *soc_die; +struct soc_device *soc_dev;const char *machine;u32 svr;
@@ -136,7 +136,7 @@ static int loongson2_guts_probe(struct platform_device *pdev)if (!soc_dev_attr.revision)return -ENOMEM ; - soc_dev =soc_device_register (&soc_dev_attr); + soc_dev =devm_soc_device_register (dev, &soc_dev_attr);if (IS_ERR (soc_dev))return PTR_ERR (soc_dev);
@@ -148,11 +148,6 @@ static int loongson2_guts_probe(struct platform_device *pdev)return 0 ; } -static void loongson2_guts_remove (struct platform_device *dev) -{ -soc_device_unregister (soc_dev); -} -/* * Table for matching compatible strings, for device tree * guts node, for Loongson-2 SoCs.
@@ -169,7 +164,6 @@ static struct platform_driver loongson2_guts_driver = { .of_match_table = loongson2_guts_of_match, }, .probe = loongson2_guts_probe, - .remove = loongson2_guts_remove, };static int __init loongson2_guts_init (void )
Signature · 1 line
2.43.0
PATCH 6/12 soc: mediatek: mtk-socinfo: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/mediatek/mtk-socinfo.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
drivers/soc/mediatek/mtk-socinfo.c +4 -13
@@ -30,7 +30,6 @@ struct mtk_socinfo {struct device *dev;struct name_data *name_data;struct socinfo_data *socinfo_data; -struct soc_device *soc_dev; };struct socinfo_data {
@@ -71,6 +70,7 @@ static int mtk_socinfo_create_socinfo_node(struct mtk_socinfo *mtk_socinfop)struct soc_device_attribute *attrs;struct socinfo_data *data = mtk_socinfop->socinfo_data;static const char *soc_manufacturer ="MediaTek" ; +struct soc_device *soc_dev; attrs =devm_kzalloc_obj (mtk_socinfop->dev, *attrs);if (!attrs)
@@ -91,9 +91,9 @@ static int mtk_socinfo_create_socinfo_node(struct mtk_socinfo *mtk_socinfop)* name from board DTS (if available). **/ - mtk_socinfop->soc_dev =soc_device_register (attrs); -if (IS_ERR (mtk_socinfop->soc_dev)) -return PTR_ERR (mtk_socinfop->soc_dev); + soc_dev =devm_soc_device_register (mtk_socinfop->dev, attrs); +if (IS_ERR (soc_dev)) +return PTR_ERR (soc_dev);dev_info (mtk_socinfop->dev,"%s (%s) SoC detected.\n" , attrs->family, attrs->soc_id);return 0 ;
@@ -191,20 +191,11 @@ static int mtk_socinfo_probe(struct platform_device *pdev)if (ret)return dev_err_probe (mtk_socinfop->dev, ret,"Cannot create node\n" ); -platform_set_drvdata (pdev, mtk_socinfop);return 0 ; } -static void mtk_socinfo_remove (struct platform_device *pdev) -{ -struct mtk_socinfo *mtk_socinfop =platform_get_drvdata (pdev); - -soc_device_unregister (mtk_socinfop->soc_dev); -} -static struct platform_driver mtk_socinfo = { .probe = mtk_socinfo_probe, - .remove = mtk_socinfo_remove, .driver = { .name ="mtk-socinfo" , },
Signature · 1 line
2.43.0
PATCH 7/12 soc: qcom: socinfo: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/qcom/socinfo.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/soc/qcom/socinfo.c +1 -3
@@ -931,7 +931,7 @@ static int qcom_socinfo_probe(struct platform_device *pdev)return -ENOMEM ; } - qs->soc_dev =soc_device_register (&qs->attr); + qs->soc_dev =devm_soc_device_register (&pdev->dev, &qs->attr);if (IS_ERR (qs->soc_dev))return PTR_ERR (qs->soc_dev);
@@ -949,8 +949,6 @@ static void qcom_socinfo_remove(struct platform_device *pdev) {struct qcom_socinfo *qs =platform_get_drvdata (pdev); -soc_device_unregister (qs->soc_dev); -socinfo_debugfs_exit (qs); }
Signature · 1 line
2.43.0
PATCH 8/12 soc: renesas: rz-sysc: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/renesas/rz-sysc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/renesas/rz-sysc.c +1 -1
@@ -78,7 +78,7 @@ static int rz_sysc_soc_init(struct rz_sysc *sysc, const struct of_device_id *mat soc_dev_attr->family, soc_dev_attr->soc_id, soc_dev_attr->revision); } - soc_dev =soc_device_register (soc_dev_attr); + soc_dev =devm_soc_device_register (sysc->dev, soc_dev_attr);if (IS_ERR (soc_dev))return PTR_ERR (soc_dev);
Signature · 1 line
2.43.0
PATCH 9/12 soc: samsung: exynos-chipid: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/samsung/exynos-chipid.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/soc/samsung/exynos-chipid.c +1 -11
@@ -146,11 +146,6 @@ static struct regmap *exynos_chipid_get_efuse_regmap(struct platform_device *pdereturn devm_regmap_init_mmio_clk (&pdev->dev,"pclk" , base, ®_config); } -static void exynos_chipid_unregister_soc (void *data) -{ -soc_device_unregister (data); -} -static int exynos_chipid_probe (struct platform_device *pdev) {const struct exynos_chipid_variant *drv_data;
@@ -200,16 +195,11 @@ static int exynos_chipid_probe(struct platform_device *pdev)return dev_err_probe (dev, -ENODEV ,"Unknown SoC\n" );/* please note that the actual registration will be deferred */ - soc_dev =soc_device_register (soc_dev_attr); + soc_dev =devm_soc_device_register (dev, soc_dev_attr);if (IS_ERR (soc_dev))return dev_err_probe (dev,PTR_ERR (soc_dev),"failed to register to the soc interface\n" ); - ret =devm_add_action_or_reset (dev, exynos_chipid_unregister_soc, - soc_dev); -if (ret) -return dev_err_probe (dev, ret,"failed to add devm action\n" ); - ret =exynos_asv_init (dev, regmap);if (ret)return ret;
Signature · 1 line
2.43.0
PATCH 10/12 soc: ti: k3-socinfo: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/ti/k3-socinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/ti/k3-socinfo.c +1 -1
@@ -218,7 +218,7 @@ static int k3_chipinfo_probe(struct platform_device *pdev)of_property_read_string (node,"model" , &soc_dev_attr->machine);of_node_put (node); - soc_dev =soc_device_register (soc_dev_attr); + soc_dev =devm_soc_device_register (dev, soc_dev_attr);if (IS_ERR (soc_dev)) { ret =PTR_ERR (soc_dev); goto err_free_rev;
Signature · 1 line
2.43.0
PATCH 11/12 soc: versatile: realview: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/versatile/soc-realview.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/soc/versatile/soc-realview.c +1 -13
@@ -82,13 +82,6 @@ static struct attribute *realview_attrs[] = {ATTRIBUTE_GROUPS (realview); -static void realview_soc_socdev_release (void *data) -{ -struct soc_device *soc_dev = data; - -soc_device_unregister (soc_dev); -} -static int realview_soc_probe (struct platform_device *pdev) {struct regmap *syscon_regmap;
@@ -113,15 +106,10 @@ static int realview_soc_probe(struct platform_device *pdev) soc_dev_attr->machine ="RealView" ; soc_dev_attr->family ="Versatile" ; soc_dev_attr->custom_attr_group = realview_groups[0 ]; - soc_dev =soc_device_register (soc_dev_attr); + soc_dev =devm_soc_device_register (&pdev->dev, soc_dev_attr);if (IS_ERR (soc_dev))return -ENODEV ; - ret =devm_add_action_or_reset (&pdev->dev, realview_soc_socdev_release, - soc_dev); -if (ret) -return ret; - ret =regmap_read (syscon_regmap,REALVIEW_SYS_ID_OFFSET , &realview_coreid);if (ret)
Signature · 1 line
2.43.0
PATCH 12/12 soc: vt8500: Use devm_soc_device_register() helper
In reply to Andrew DavisUse the device lifecycle managed register function. This helps prevent mistakes like unregistering out of order in cleanup functions and forgetting to unregister on error paths.
--- drivers/soc/vt8500/wmt-socinfo.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/soc/vt8500/wmt-socinfo.c +1 -10
@@ -84,7 +84,7 @@ static int wmt_socinfo_probe(struct platform_device *pdev)if (!attrs->revision || !attrs->soc_id)return -ENOMEM ; - soc_dev =soc_device_register (attrs); + soc_dev =devm_soc_device_register (&pdev->dev, attrs);if (IS_ERR (soc_dev))return PTR_ERR (soc_dev);
@@ -94,17 +94,9 @@ static int wmt_socinfo_probe(struct platform_device *pdev) attrs->revision, attrs->soc_id); -platform_set_drvdata (pdev, soc_dev);return 0 ; } -static void wmt_socinfo_remove (struct platform_device *pdev) -{ -struct soc_device *soc_dev =platform_get_drvdata (pdev); - -soc_device_unregister (soc_dev); -} -static const struct of_device_id wmt_socinfo_ids[] = { { .compatible ="via,vt8500-scc-id" }, {/* Sentinel */ },
@@ -112,7 +104,6 @@ static const struct of_device_id wmt_socinfo_ids[] = {static struct platform_driver wmt_socinfo = { .probe = wmt_socinfo_probe, - .remove = wmt_socinfo_remove, .driver = { .name ="wmt-socinfo" , .of_match_table = wmt_socinfo_ids,
Signature · 1 line
2.43.0