Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 b4028437.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jean Delvare and committed by
Greg Kroah-Hartman
1bb6c08a 5cbb00cc

+6 -13
-3
drivers/base/base.h
··· 63 63 * binding of drivers which were unable to get all the resources needed by 64 64 * the device; typically because it depends on another driver getting 65 65 * probed first. 66 - * @driver_data - private pointer for driver specific info. Will turn into a 67 - * list soon. 68 66 * @device - pointer back to the struct class that this structure is 69 67 * associated with. 70 68 * ··· 74 76 struct klist_node knode_driver; 75 77 struct klist_node knode_bus; 76 78 struct list_head deferred_probe; 77 - void *driver_data; 78 79 struct device *device; 79 80 }; 80 81 #define to_device_private_parent(obj) \
+3 -10
drivers/base/dd.c
··· 594 594 */ 595 595 void *dev_get_drvdata(const struct device *dev) 596 596 { 597 - if (dev && dev->p) 598 - return dev->p->driver_data; 597 + if (dev) 598 + return dev->driver_data; 599 599 return NULL; 600 600 } 601 601 EXPORT_SYMBOL(dev_get_drvdata); 602 602 603 603 int dev_set_drvdata(struct device *dev, void *data) 604 604 { 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; 613 606 return 0; 614 607 } 615 608 EXPORT_SYMBOL(dev_set_drvdata);
+3
include/linux/device.h
··· 673 673 * variants, which GPIO pins act in what additional roles, and so 674 674 * on. This shrinks the "Board Support Packages" (BSPs) and 675 675 * minimizes board-specific #ifdefs in drivers. 676 + * @driver_data: Private pointer for driver specific info. 676 677 * @power: For device power management. 677 678 * See Documentation/power/devices.txt for details. 678 679 * @pm_domain: Provide callbacks that are executed during system suspend, ··· 735 734 device */ 736 735 void *platform_data; /* Platform specific data, device 737 736 core doesn't touch it */ 737 + void *driver_data; /* Driver data, set and get with 738 + dev_set/get_drvdata */ 738 739 struct dev_pm_info power; 739 740 struct dev_pm_domain *pm_domain; 740 741