forked from mirrors/linux
		
	driver core: add dev_groups to all drivers
Add the ability for the driver core to create and remove a list of attribute groups automatically when the device is bound/unbound from a specific driver. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Tested-by: Richard Gong <richard.gong@linux.intel.com> Link: https://lore.kernel.org/r/20190731124349.4474-2-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									5f9e832c13
								
							
						
					
					
						commit
						23b6904442
					
				
					 2 changed files with 17 additions and 0 deletions
				
			
		| 
						 | 
					@ -554,9 +554,16 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 | 
				
			||||||
			goto probe_failed;
 | 
								goto probe_failed;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (device_add_groups(dev, drv->dev_groups)) {
 | 
				
			||||||
 | 
							dev_err(dev, "device_add_groups() failed\n");
 | 
				
			||||||
 | 
							goto dev_groups_failed;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (test_remove) {
 | 
						if (test_remove) {
 | 
				
			||||||
		test_remove = false;
 | 
							test_remove = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							device_remove_groups(dev, drv->dev_groups);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (dev->bus->remove)
 | 
							if (dev->bus->remove)
 | 
				
			||||||
			dev->bus->remove(dev);
 | 
								dev->bus->remove(dev);
 | 
				
			||||||
		else if (drv->remove)
 | 
							else if (drv->remove)
 | 
				
			||||||
| 
						 | 
					@ -584,6 +591,11 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 | 
				
			||||||
		 drv->bus->name, __func__, dev_name(dev), drv->name);
 | 
							 drv->bus->name, __func__, dev_name(dev), drv->name);
 | 
				
			||||||
	goto done;
 | 
						goto done;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dev_groups_failed:
 | 
				
			||||||
 | 
						if (dev->bus->remove)
 | 
				
			||||||
 | 
							dev->bus->remove(dev);
 | 
				
			||||||
 | 
						else if (drv->remove)
 | 
				
			||||||
 | 
							drv->remove(dev);
 | 
				
			||||||
probe_failed:
 | 
					probe_failed:
 | 
				
			||||||
	if (dev->bus)
 | 
						if (dev->bus)
 | 
				
			||||||
		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 | 
							blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 | 
				
			||||||
| 
						 | 
					@ -1114,6 +1126,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		pm_runtime_put_sync(dev);
 | 
							pm_runtime_put_sync(dev);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							device_remove_groups(dev, drv->dev_groups);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (dev->bus && dev->bus->remove)
 | 
							if (dev->bus && dev->bus->remove)
 | 
				
			||||||
			dev->bus->remove(dev);
 | 
								dev->bus->remove(dev);
 | 
				
			||||||
		else if (drv->remove)
 | 
							else if (drv->remove)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -262,6 +262,8 @@ enum probe_type {
 | 
				
			||||||
 * @resume:	Called to bring a device from sleep mode.
 | 
					 * @resume:	Called to bring a device from sleep mode.
 | 
				
			||||||
 * @groups:	Default attributes that get created by the driver core
 | 
					 * @groups:	Default attributes that get created by the driver core
 | 
				
			||||||
 *		automatically.
 | 
					 *		automatically.
 | 
				
			||||||
 | 
					 * @dev_groups:	Additional attributes attached to device instance once the
 | 
				
			||||||
 | 
					 *		it is bound to the driver.
 | 
				
			||||||
 * @pm:		Power management operations of the device which matched
 | 
					 * @pm:		Power management operations of the device which matched
 | 
				
			||||||
 *		this driver.
 | 
					 *		this driver.
 | 
				
			||||||
 * @coredump:	Called when sysfs entry is written to. The device driver
 | 
					 * @coredump:	Called when sysfs entry is written to. The device driver
 | 
				
			||||||
| 
						 | 
					@ -296,6 +298,7 @@ struct device_driver {
 | 
				
			||||||
	int (*suspend) (struct device *dev, pm_message_t state);
 | 
						int (*suspend) (struct device *dev, pm_message_t state);
 | 
				
			||||||
	int (*resume) (struct device *dev);
 | 
						int (*resume) (struct device *dev);
 | 
				
			||||||
	const struct attribute_group **groups;
 | 
						const struct attribute_group **groups;
 | 
				
			||||||
 | 
						const struct attribute_group **dev_groups;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const struct dev_pm_ops *pm;
 | 
						const struct dev_pm_ops *pm;
 | 
				
			||||||
	void (*coredump) (struct device *dev);
 | 
						void (*coredump) (struct device *dev);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue