Re: [PATCH] ALSA: asihpi: avoid write overflow check warning
From: Arnd Bergmann
Date: Wed Mar 18 2026 - 08:19:32 EST
On Wed, Mar 18, 2026, at 12:54, Takashi Iwai wrote:
> On Wed, 18 Mar 2026 11:50:08 +0100,
>> + memcpy(&rESP_HPI_ADAPTER_OPEN[adapter].h, &hr,
>> + sizeof(rESP_HPI_ADAPTER_OPEN[adapter].h));
>> + memcpy(&rESP_HPI_ADAPTER_OPEN[adapter].a, &hr.u.s,
>> + sizeof(rESP_HPI_ADAPTER_OPEN[adapter].a));
>
> I think the last one is still a bit confusing as if doing an overflow
> copy again: hr.u.s is struct hpi_subsys_res which is smaller than
> rESP_HPI_ADAPTER_OPEN[adapter].a which is struct hpi_adapter_res.
Right, I got confused by the various similarly named types
again.
> If any, the last one should be
>
> memcpy(&rESP_HPI_ADAPTER_OPEN[adapter].a, &hr.u.ax.info,
> sizeof(rESP_HPI_ADAPTER_OPEN[adapter].a));
>
> Or it could be even
>
> rESP_HPI_ADAPTER_OPEN[adapter].a = hr.u.ax.info;
>
> (I'm not sure which one can be a better result, though.)
Code generation wise, I would expect them to be the same,
as gcc is good at transforming the memcpy() calls into
direct copies and vice versa.
I'll send a v2 with the first one after it passes build tests,
unless someone has another preference.
Arnd