From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Mark Brown <broonie@kernel.org>
Cc: <tiwai@suse.com>, <perex@perex.cz>, <amade@asmblr.net>,
<kuninori.morimoto.gx@renesas.com>, <linux-sound@vger.kernel.org>
Subject: Re: [PATCH] ALSA: control: Verify put() result when in debug mode
Date: Fri, 30 Jan 2026 15:49:40 +0100 [thread overview]
Message-ID: <4d1a0095-dfe8-4719-bda9-61ed6a42749e@intel.com> (raw)
In-Reply-To: <60f477d0-ea1f-435a-bd8c-4e7e06a1802b@sirena.org.uk>
On 2026-01-30 3:12 PM, Mark Brown wrote:
> On Fri, Jan 30, 2026 at 02:55:41PM +0100, Cezary Rojewski wrote:
>> The put() operation is expected to return:
>> 1) 0 on success if no changes were made
>> 2) 1 on success if changes were made
>> 3) error code otherwise
>>
>> Currently 2) is usually ignored when writing control-operations. While
>> forcing compliance is not an option right now, make it easier for
>> developers to adhere to the expectations and notice problems by logging
>> them when CONFIG_SND_CTL_DEBUG is enabled.
>
> Makes sense to me, although I fear it's about as likely that people
> enable this config as that they run mixer-test it's reasonable to be
> helpful.
Fair point. I admit I've noticed the problem in the existing
sound/soc/intel/* drivers long time ago and.. forgot to address them due
to lack of any "pings" in the logs.
alsa-utils' tools and alsa-lib do not allow to differentiate between
success-no-changes and success-changes. Ideally userspace-level tests
(functional tests) would be allowed to verify that. While in the long
run updating/extending alsa-lib is probably the way to go, I believe
having kernel-level check _now_ is not bad.
>> + struct snd_ctl_elem_value original;
>
>> + ret = kctl->get(kctl, &original);
>> + if (ret)
>> + return ret;
>
>> + retcmp = memcmp(&original.value.bytes.data[0], &control->value.bytes.data[0],
>> + sizeof(original.value.bytes.data[0]));
>> + if (retcmp)
>> + retcmp = 1;
>
> original was just allocated from the stack so who knows what values it
> had originally, and the get() is only going to write the part of the
> value that has data since the normal get() path has a memset() in the
> core. Similarly with the new value coming in from userspace there's no
> requirement for userspace to set anything that isn't part of the value
> being written to any particular value. This means we're liable to get
> spurious mismatches.
You're right, I've based my patch on results from drivers that do init
the space entirely. That may not be true for every driver in sound/.
next prev parent reply other threads:[~2026-01-30 14:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 13:55 [PATCH] ALSA: control: Verify put() result when in debug mode Cezary Rojewski
2026-01-30 14:12 ` Mark Brown
2026-01-30 14:29 ` Takashi Iwai
2026-01-30 15:00 ` Cezary Rojewski
2026-01-30 15:13 ` Mark Brown
2026-02-04 11:37 ` Cezary Rojewski
2026-01-30 15:14 ` Takashi Iwai
2026-02-04 11:33 ` Cezary Rojewski
2026-01-30 14:49 ` Cezary Rojewski [this message]
2026-02-02 0:20 ` Kuninori Morimoto
2026-02-04 11:30 ` Cezary Rojewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4d1a0095-dfe8-4719-bda9-61ed6a42749e@intel.com \
--to=cezary.rojewski@intel.com \
--cc=amade@asmblr.net \
--cc=broonie@kernel.org \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox