mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/8] driver: switch dev_get_drvdata to Linux semantics
Date: Tue,  6 May 2025 08:34:41 +0200	[thread overview]
Message-ID: <20250506063446.3133582-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250506063446.3133582-1-a.fatoum@pengutronix.de>

Now that no users of dev_get_drvdata remain, replace it with the Linux
version. Any out-of-tree users must be changed to use
device_get_match_data instead. The new dev_get_drvdata is the equivalent
of what was so far written as dev->priv.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/base/driver.c  | 15 ---------------
 include/device.h       |  5 ++++-
 include/driver.h       | 12 ------------
 include/linux/device.h | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 85cec7efab46..2160d2fd060b 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -709,21 +709,6 @@ static void devices_shutdown(void)
 }
 devshutdown_exitcall(devices_shutdown);
 
-int dev_get_drvdata(struct device *dev, const void **data)
-{
-	if (dev->of_id_entry) {
-		*data = dev->of_id_entry->data;
-		return 0;
-	}
-
-	if (dev->id_entry) {
-		*data = (const void **)dev->id_entry->driver_data;
-		return 0;
-	}
-
-	return -ENODEV;
-}
-
 const void *device_get_match_data(struct device *dev)
 {
 	if (dev->of_id_entry)
diff --git a/include/device.h b/include/device.h
index 8841197a0a56..bc3a348e2e15 100644
--- a/include/device.h
+++ b/include/device.h
@@ -54,7 +54,10 @@ struct device {
 	/*! Devices of a particular class normaly need to store more
 	 * information than struct device holds.
 	 */
-	void *priv;
+	union {
+		void *priv;
+		void *driver_data;
+	};
 	void *type_data;     /*! In case this device is a specific device, this pointer
 			      * points to the type specific device, i.e. eth_device
 			      */
diff --git a/include/driver.h b/include/driver.h
index d73c33a42a81..b63dce84c80e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -666,18 +666,6 @@ int cdevfs_del_partition(struct cdev *cdev);
 
 #define DRV_OF_COMPAT(compat) of_match_ptr(compat)
 
-/**
- * dev_get_drvdata - get driver match data associated with device
- * @dev: device instance
- * @data: pointer to void *, where match data is stored
- *
- * Returns 0 on success and error code otherwise.
- *
- * DEPRECATED: use device_get_match_data instead, which avoids
- * common pitfalls due to explicit pointer casts
- */
-int dev_get_drvdata(struct device *dev, const void **data);
-
 /**
  * device_get_match_data - get driver match data associated with device
  * @dev: device instance
diff --git a/include/linux/device.h b/include/linux/device.h
index 661d8b24730e..d4098b85239f 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -73,4 +73,36 @@ static inline int bus_for_each_dev(const struct bus_type *bus, struct device *st
 	return 0;
 }
 
+
+/**
+ * dev_set_drvdata - set driver private data for device
+ * @dev: device instance
+ * @data: driver-specific data
+ *
+ * Returns private driver data or NULL if none was set.
+ *
+ * NOTE: This does _not_ return the match data associated with
+ * the match. For that use device_get_match_data instead.
+ */
+static inline void dev_set_drvdata(struct device *dev, void *data)
+{
+	dev->driver_data = data;
+}
+
+/**
+ * dev_get_drvdata - get driver match data associated for device
+ * @dev: device instance
+ * @data: driver-specific data
+ *
+ * Set some driver and device specific data for later retrieval
+ * by dev_get_drvdata.
+ *
+ * NOTE: This does _not_ return the match data associated with
+ * the match. For that use device_get_match_data instead.
+ */
+static inline void *dev_get_drvdata(const struct device *dev)
+{
+	return dev->driver_data;
+}
+
 #endif
-- 
2.39.5




  parent reply	other threads:[~2025-05-06  6:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06  6:34 [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
2025-05-06  6:34 ` [PATCH 2/8] ARM: i.MX: esdctl: " Ahmad Fatoum
2025-05-06  6:34 ` Ahmad Fatoum [this message]
2025-05-06  6:34 ` [PATCH 4/8] gpio: gpio-mxs: " Ahmad Fatoum
2025-05-06  7:42   ` Sascha Hauer
2025-05-06  6:34 ` [PATCH 5/8] mci: am654-sdhci: fix error code printed in error messages Ahmad Fatoum
2025-05-06  6:34 ` [PATCH 6/8] pinctrl: at91: replace dev_get_drvdata with device_get_match_data Ahmad Fatoum
2025-05-06  6:34 ` [PATCH 7/8] drivers: maintain const when converting from struct driver Ahmad Fatoum
2025-05-06  6:34 ` [PATCH 8/8] driver: base: invert driver match callback for Linux compatibility Ahmad Fatoum
2025-05-06  7:41 ` [PATCH 1/8] treewide: replace dev_get_drvdata with device_get_match_data Sascha Hauer

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=20250506063446.3133582-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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