Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: <tiwai@suse.com>, <broonie@kernel.org>, <perex@perex.cz>,
	<amade@asmblr.net>, <linux-sound@vger.kernel.org>
Subject: Re: [PATCH] ALSA: control: Verify put() result when in debug mode
Date: Wed, 4 Feb 2026 12:30:21 +0100	[thread overview]
Message-ID: <87fc67e6-5a8f-4249-9419-3f77e1c762e5@intel.com> (raw)
In-Reply-To: <87ikcgatdi.wl-kuninori.morimoto.gx@renesas.com>

On 2026-02-02 1:20 AM, Kuninori Morimoto wrote:

>> +static int snd_ctl_write_verify(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *control)
>> +{
>> +	struct snd_ctl_elem_value original;
>> +	int ret, retcmp;
>> +
>> +	ret = kctl->get(kctl, &original);
>> +	if (ret)
>> +		return ret;
>> +
>> +	ret = kctl->put(kctl, control);
>> +	if (ret < 0)
>> +		return ret;
>> +
>> +	retcmp = memcmp(&original.value.bytes.data[0], &control->value.bytes.data[0],
>> +			sizeof(original.value.bytes.data[0]));
>> +	if (retcmp)
>> +		retcmp = 1;
>> +
>> +	if (retcmp == ret)
>> +		pr_info("kctl->put() returned the expected value of '%d'\n", ret);
>> +	else
>> +		pr_warn("expected kctl->put() to return '%d' but got '%d'\n", ret, retcmp);
>> +	return ret;
>> +}
> 
> I think this is easy to read ?
> 
> 	static int snd_kctl_put(...)
> 	{
> 		if (IS_ENABLED(CONFIG_SND_CTL_DEBUG)) {
> 			/* Code with verification */
> 		} else {
> 			/* Code without verification */
> 		}
> 		return ret;
> 	}
> 
> 	...
> 
> 	if (!result)
> -		result = kctl->put(...);
> +		result = snd_kctl_put(...);

Hello,

I see the idea - reduce the number of if-statements in the actual code. 
What I decided to do in v2 is the above with a little twist - enlist 
macros. Not a fun for declaring yet another function with a single 
if-statement. Also, opted for "snd_ctl_put_xxx" instead of 
"snd_kctl_put_xxx" to match naming pattern most widely used in 
sound/core/control.c file.

Kind regards,
Czarek

      reply	other threads:[~2026-02-04 11:30 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
2026-02-02  0:20 ` Kuninori Morimoto
2026-02-04 11:30   ` Cezary Rojewski [this message]

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=87fc67e6-5a8f-4249-9419-3f77e1c762e5@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