Re: [PATCH 2/2] ASoC: spacemit: init *dp to NULL before error paths

Bui Duc Phuc <[email protected]> Mon, 3 Aug 2026 11:05:47 +0700
Newsgroups dev.linux.lists.spacemit,org.infradead.lists.linux-riscv,org.kernel.vger.linux-kernel,org.kernel.vger.linux-sound
Message-ID <CAABR9nEqZG1Vywb2CkoLVgqoLVPKqfYt01t3dF=WTu9qJSS=bw@mail.gmail.com>
Hi Troy,

Thank you for your feedback.

> > The current caller does check the return value before using dp, so this
> > isn't an active bug. Still, initialize *dp to NULL upfront as a defensive
> > measure, consistent with how core helpers like _snd_pcm_new() handle
> > their optional output parameters.
>
> If devm_kmemdup() fails, spacemit_i2s_init_dai() returns -ENOMEM. The
> sole caller checks the return value and returns immediately, so it never
> accesses dai on that path. On success, dp is non-NULL and *dp is assigned
> before the function returns.
>
> Therefore, I do not see a path where initializing *dp to NULL has any
> effect. Could you clarify what case this change is intended to handle?


My intention was to make the API a bit more defensive. While the current
implementation only has one failure path,  spacemit_i2s_init_dai() may
grow additional error paths in the future. Initializing *dp to NULL ensures
it is left in a well-defined state on any failure.

It would also avoid leaving dai uninitialized if a future caller accidentally
skipped checking the return value before using it.

Best regards,
Phuc