Re: [PATCH] ALSA: hwdep: fix NULL dereference on error path

From: Takashi Iwai

Date: Mon Apr 13 2026 - 01:23:25 EST


On Sun, 12 Apr 2026 19:45:29 +0200,
Guangshuo Li wrote:
>
> snd_hwdep_new() allocates a hwdep instance first and then allocates
> hwdep->dev via snd_device_alloc().
>
> When snd_device_alloc() fails, hwdep->dev remains NULL, because
> snd_device_alloc() clears *dev_p before attempting to allocate the
> device object. The error path then calls snd_hwdep_free(), which
> unconditionally invokes put_device(hwdep->dev).
>
> This may lead to a NULL pointer dereference in put_device().

put_device() has a NULL check by itself, so it's safe to pass NULL
there.


thanks,

Takashi