Skip to content

Commit 1bb6c08

Browse files
jdelvaregregkh
authored andcommitted
driver core: Move driver_data back to struct device
Having to allocate memory as part of dev_set_drvdata() is a problem because that memory may never get freed if the device itself is not created. So move driver_data back to struct device. This is a partial revert of commit b402843. Signed-off-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5cbb00c commit 1bb6c08

3 files changed

Lines changed: 6 additions & 13 deletions

File tree

‎drivers/base/base.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ struct driver_private {
6363
* binding of drivers which were unable to get all the resources needed by
6464
* the device; typically because it depends on another driver getting
6565
* probed first.
66-
* @driver_data - private pointer for driver specific info. Will turn into a
67-
* list soon.
6866
* @device - pointer back to the struct class that this structure is
6967
* associated with.
7068
*
@@ -76,7 +74,6 @@ struct device_private {
7674
struct klist_node knode_driver;
7775
struct klist_node knode_bus;
7876
struct list_head deferred_probe;
79-
void *driver_data;
8077
struct device *device;
8178
};
8279
#define to_device_private_parent(obj) \

‎drivers/base/dd.c‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -594,22 +594,15 @@ void driver_detach(struct device_driver *drv)
594594
*/
595595
void *dev_get_drvdata(const struct device *dev)
596596
{
597-
if (dev && dev->p)
598-
return dev->p->driver_data;
597+
if (dev)
598+
return dev->driver_data;
599599
return NULL;
600600
}
601601
EXPORT_SYMBOL(dev_get_drvdata);
602602

603603
int dev_set_drvdata(struct device *dev, void *data)
604604
{
605-
int error;
606-
607-
if (!dev->p) {
608-
error = device_private_init(dev);
609-
if (error)
610-
return error;
611-
}
612-
dev->p->driver_data = data;
605+
dev->driver_data = data;
613606
return 0;
614607
}
615608
EXPORT_SYMBOL(dev_set_drvdata);

‎include/linux/device.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ struct acpi_dev_node {
673673
* variants, which GPIO pins act in what additional roles, and so
674674
* on. This shrinks the "Board Support Packages" (BSPs) and
675675
* minimizes board-specific #ifdefs in drivers.
676+
* @driver_data: Private pointer for driver specific info.
676677
* @power: For device power management.
677678
* See Documentation/power/devices.txt for details.
678679
* @pm_domain: Provide callbacks that are executed during system suspend,
@@ -734,6 +735,8 @@ struct device {
734735
device */
735736
void *platform_data; /* Platform specific data, device
736737
core doesn't touch it */
738+
void *driver_data; /* Driver data, set and get with
739+
dev_set/get_drvdata */
737740
struct dev_pm_info power;
738741
struct dev_pm_domain *pm_domain;
739742

0 commit comments

Comments
 (0)