| Message ID | 20260902170734.95504-2-djeffery@redhat.com |
|---|---|
| State | New |
| Headers | show |
| Series | shut down devices asynchronously | expand |
> From: Tarun Sahu <tarunsahu@google.com> > > device_add allocate private_data for device and assigns to > dev->p. If device_add fails in later steps of the function, > it cleans up this dev->p which is not necessary because In > the next call, put_device free it anyway (if reference to > the device is 0 which will be unless someone concurrently > get the reference to this device). > > This avoids unnecessary races introduced in system. After device > is added in device_kset->list by device_add and later steps in the > device_add function failures occur, it will free dev->p manually, > while in between there might be a user of device_kset->list will > take reference to the device just added by device_add. and might > try to access dev->p. So relying on put_device to free dev->p > prevents such problem. > > Signed-off-by: Tarun Sahu <tarunsahu@google.com> > Signed-off-by: David Jeffery <djeffery@redhat.com> Sashiko has reviewed this patch and found no issues. It looks great!
diff --git a/drivers/base/core.c b/drivers/base/core.c index 4c0c373998a1..83263e3fa5d4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2618,6 +2618,7 @@ static void device_release(struct kobject *kobj) struct device *dev = kobj_to_dev(kobj); struct device_private *p = dev->p; + dev->p = NULL; /* * Some platform devices are driven without driver attached * and managed resources may have been acquired. Make sure @@ -3828,8 +3829,6 @@ int device_add(struct device *dev) parent_error: put_device(parent); name_error: - kfree(dev->p); - dev->p = NULL; goto done; } EXPORT_SYMBOL_GPL(device_add);