mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Davis <afd@ti.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Johan Hovold <johan@kernel.org>
Cc: <driver-core@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	"Andrew Davis" <afd@ti.com>
Subject: [PATCH 01/12] base: soc: Implement devm_soc_device_register() helper function
Date: Wed, 11 Nov 2026 11:57:00 -0600	[thread overview]
Message-ID: <20261111175711.428824-2-afd@ti.com> (raw)
In-Reply-To: <20261111175711.428824-1-afd@ti.com>

Add device managed devm_soc_device_register() to automatically unregister
soc_devices thus leading to simplified SOC driver code.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/base/soc.c      | 23 +++++++++++++++++++++++
 include/linux/sys_soc.h | 16 ++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index af7d71393774b..81a96e56fbc29 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -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;
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index cedabf177f470..02b22add818b3 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -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
-- 
2.43.0


  reply	other threads:[~2026-11-11 17:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 17:56 [PATCH 00/12] Add and use DEVM soc_device_register helper Andrew Davis
2026-11-11 17:57 ` Andrew Davis [this message]
2026-11-11 17:57 ` [PATCH 02/12] soc: ep93xx: Use devm_soc_device_register() helper Andrew Davis
2026-11-11 17:57 ` [PATCH 03/12] soc: imx8m: " Andrew Davis
2026-11-11 17:57 ` [PATCH 04/12] soc: imx9: " Andrew Davis
2026-11-11 17:57 ` [PATCH 05/12] soc: loongson: " Andrew Davis
2026-11-11 17:57 ` [PATCH 06/12] soc: mediatek: mtk-socinfo: " Andrew Davis
2026-11-11 17:57 ` [PATCH 07/12] soc: qcom: socinfo: " Andrew Davis
2026-11-11 17:57 ` [PATCH 08/12] soc: renesas: rz-sysc: " Andrew Davis
2026-11-11 17:57 ` [PATCH 09/12] soc: samsung: exynos-chipid: " Andrew Davis
2026-11-11 17:57 ` [PATCH 10/12] soc: ti: k3-socinfo: " Andrew Davis
2026-11-11 17:57 ` [PATCH 11/12] soc: versatile: realview: " Andrew Davis
2026-11-11 17:57 ` [PATCH 12/12] soc: vt8500: " Andrew Davis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261111175711.428824-2-afd@ti.com \
    --to=afd@ti.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®