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.fat...@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