driver core: introduce device_set_driver() helper
commit 04d3e5461c1f5cf8eec964ab64948ebed826e95e upstream. In preparation to closing a race when reading driver pointer in dev_uevent() code, instead of setting device->driver pointer directly introduce device_set_driver() helper. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Link: https://lore.kernel.org/r/20250311052417.1846985-2-dmitry.torokhov@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
bfc66c4c28
commit
4f43c1bf2b
@@ -179,6 +179,12 @@ int driver_add_groups(const struct device_driver *drv, const struct attribute_gr
|
|||||||
void driver_remove_groups(const struct device_driver *drv, const struct attribute_group **groups);
|
void driver_remove_groups(const struct device_driver *drv, const struct attribute_group **groups);
|
||||||
void device_driver_detach(struct device *dev);
|
void device_driver_detach(struct device *dev);
|
||||||
|
|
||||||
|
static inline void device_set_driver(struct device *dev, const struct device_driver *drv)
|
||||||
|
{
|
||||||
|
// FIXME - this cast should not be needed "soon"
|
||||||
|
dev->driver = (struct device_driver *)drv;
|
||||||
|
}
|
||||||
|
|
||||||
int devres_release_all(struct device *dev);
|
int devres_release_all(struct device *dev);
|
||||||
void device_block_probing(void);
|
void device_block_probing(void);
|
||||||
void device_unblock_probing(void);
|
void device_unblock_probing(void);
|
||||||
|
|||||||
+1
-1
@@ -3697,7 +3697,7 @@ done:
|
|||||||
device_pm_remove(dev);
|
device_pm_remove(dev);
|
||||||
dpm_sysfs_remove(dev);
|
dpm_sysfs_remove(dev);
|
||||||
DPMError:
|
DPMError:
|
||||||
dev->driver = NULL;
|
device_set_driver(dev, NULL);
|
||||||
bus_remove_device(dev);
|
bus_remove_device(dev);
|
||||||
BusError:
|
BusError:
|
||||||
device_remove_attrs(dev);
|
device_remove_attrs(dev);
|
||||||
|
|||||||
+3
-4
@@ -550,7 +550,7 @@ static void device_unbind_cleanup(struct device *dev)
|
|||||||
arch_teardown_dma_ops(dev);
|
arch_teardown_dma_ops(dev);
|
||||||
kfree(dev->dma_range_map);
|
kfree(dev->dma_range_map);
|
||||||
dev->dma_range_map = NULL;
|
dev->dma_range_map = NULL;
|
||||||
dev->driver = NULL;
|
device_set_driver(dev, NULL);
|
||||||
dev_set_drvdata(dev, NULL);
|
dev_set_drvdata(dev, NULL);
|
||||||
if (dev->pm_domain && dev->pm_domain->dismiss)
|
if (dev->pm_domain && dev->pm_domain->dismiss)
|
||||||
dev->pm_domain->dismiss(dev);
|
dev->pm_domain->dismiss(dev);
|
||||||
@@ -629,8 +629,7 @@ static int really_probe(struct device *dev, const struct device_driver *drv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
re_probe:
|
re_probe:
|
||||||
// FIXME - this cast should not be needed "soon"
|
device_set_driver(dev, drv);
|
||||||
dev->driver = (struct device_driver *)drv;
|
|
||||||
|
|
||||||
/* If using pinctrl, bind pins now before probing */
|
/* If using pinctrl, bind pins now before probing */
|
||||||
ret = pinctrl_bind_pins(dev);
|
ret = pinctrl_bind_pins(dev);
|
||||||
@@ -1014,7 +1013,7 @@ static int __device_attach(struct device *dev, bool allow_async)
|
|||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
else {
|
else {
|
||||||
dev->driver = NULL;
|
device_set_driver(dev, NULL);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user