forked from mirrors/linux
		
	device-core: Ensure drvdata = NULL when no driver is bound
1) drvdata is for a driver to store a pointer to driver specific data 2) If no driver is bound, there is no driver specific data associated with the device 3) Thus logically drvdata should be NULL if no driver is bound. But many drivers don't clear drvdata on device_release, or set drvdata early on in probe and leave it set on probe error. Both of which results in a dangling pointer in drvdata. This patch enforce for drvdata to be NULL after device_release or on probe failure. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									b02f8bede2
								
							
						
					
					
						commit
						0998d06310
					
				
					 1 changed files with 2 additions and 0 deletions
				
			
		|  | @ -283,6 +283,7 @@ static int really_probe(struct device *dev, struct device_driver *drv) | ||||||
| 	devres_release_all(dev); | 	devres_release_all(dev); | ||||||
| 	driver_sysfs_remove(dev); | 	driver_sysfs_remove(dev); | ||||||
| 	dev->driver = NULL; | 	dev->driver = NULL; | ||||||
|  | 	dev_set_drvdata(dev, NULL); | ||||||
| 
 | 
 | ||||||
| 	if (ret == -EPROBE_DEFER) { | 	if (ret == -EPROBE_DEFER) { | ||||||
| 		/* Driver requested deferred probing */ | 		/* Driver requested deferred probing */ | ||||||
|  | @ -487,6 +488,7 @@ static void __device_release_driver(struct device *dev) | ||||||
| 			drv->remove(dev); | 			drv->remove(dev); | ||||||
| 		devres_release_all(dev); | 		devres_release_all(dev); | ||||||
| 		dev->driver = NULL; | 		dev->driver = NULL; | ||||||
|  | 		dev_set_drvdata(dev, NULL); | ||||||
| 		klist_remove(&dev->p->knode_driver); | 		klist_remove(&dev->p->knode_driver); | ||||||
| 		if (dev->bus) | 		if (dev->bus) | ||||||
| 			blocking_notifier_call_chain(&dev->bus->p->bus_notifier, | 			blocking_notifier_call_chain(&dev->bus->p->bus_notifier, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Hans de Goede
						Hans de Goede