Re: [PATCH 1/9] driver core: rely on put_device to free dev->p
From: sashiko-bot
Date: Thu Sep 17 2026 - 13:38:30 EST
> From: Tarun Sahu <tarunsahu@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> Signed-off-by: David Jeffery <djeffery@xxxxxxxxxx>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917163744.191748-1-djeffery@xxxxxxxxxx?part=1