Re: [PATCH] device_core: check null pointer
From: Greg KH
Date: Sat Nov 15 2025 - 15:16:47 EST
On Fri, Nov 14, 2025 at 10:18:21PM +0800, Zhengqiao Xia wrote:
> Add null pointer check to avoid null pointer.
> When the USB device's interface is disabled, 'device_add' will not
> be called, and 'dev->p' will be NULL.
Wait, how does that happen? Shouldn't we prevent that?
> When you use 'usbdev_ioctl' to
> call this USB interface at this point,'__device_attach' will be invoked.
> Then a null pointer will be generated.
>
> Signed-off-by: Zhengqiao Xia <xiazhengqiao@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Not a valid email address :(
> ---
> drivers/base/dd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index 3328101e0e106..cfdeb420fd12a 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -1033,7 +1033,7 @@ static int __device_attach(struct device *dev, bool allow_async)
> bool async = false;
>
> device_lock(dev);
> - if (dev->p->dead) {
> + if (dev->p && dev->p->dead) {
If dev->p is NULL here, something else went wrong with the caller,
please, let's fix the root problem here instead.
What suddenly changed to cause this to happen?
thanks,
greg k-h