public inbox for linux-sound@vger.kernel.org
 help / color / mirror / Atom feed
From: "Cássio Gabriel Monteiro Pires" <cassiogabrielcontato@gmail.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] ALSA: sscape: Cache per-card resources for board reinitialization
Date: Sat, 11 Apr 2026 11:33:54 -0300	[thread overview]
Message-ID: <fe520e2a-5a95-4b57-a16b-a7a08a326ee7@gmail.com> (raw)
In-Reply-To: <87a4v9gbs1.wl-tiwai@suse.de>


[-- Attachment #1.1: Type: text/plain, Size: 2548 bytes --]



On 4/11/26 05:07, Takashi Iwai wrote:
> On Sat, 11 Apr 2026 06:54:29 +0200,
> Cássio Gabriel wrote:
>> +/*
>> + * Restore the SoundScape's MIDI control state after the firmware
>> + * upload has made the host interface available again.
>> + */
>> +static int sscape_restore_midi_state(struct soundscape *sscape)
>> +{
>> +	int err = 1;
>> +
>> +	guard(spinlock_irqsave)(&sscape->lock);
>> +	set_host_mode_unsafe(sscape->io_base);
>> +	err &= host_write_ctrl_unsafe(sscape->io_base, CMD_SET_MIDI_VOL, 100);
>> +	err &= host_write_ctrl_unsafe(sscape->io_base, sscape->midi_vol, 100);
>> +	err &= host_write_ctrl_unsafe(sscape->io_base, CMD_XXX_MIDI_VOL, 100);
>> +	err &= host_write_ctrl_unsafe(sscape->io_base, sscape->midi_vol, 100);
>> +	err &= host_write_ctrl_unsafe(sscape->io_base, CMD_SET_EXTMIDI, 100);
>> +	err &= host_write_ctrl_unsafe(sscape->io_base, 0, 100);
>> +	err &= host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100);
>> +	set_midi_mode_unsafe(sscape->io_base);
>> +
>> +	return err ? 0 : -EIO;
> 
> The above means it checks only the error of the last write.
> Is it intentional?

It was meant to accumulate failures across the whole sequence, since
host_write_ctrl_unsafe() returns 0/1 and the accumulator starts at 1.

So an earlier failed write is meant to keep the final result failed, not
only the last write. But I agree the current form is kinda easy to misread.

I can rewrite to make the cumulative error handling explicit:

static int sscape_restore_midi_state(struct soundscape *sscape)
  {
        bool ok = true;

        guard(spinlock_irqsave)(&sscape->lock);
        set_host_mode_unsafe(sscape->io_base);

        if (!host_write_ctrl_unsafe(sscape->io_base, CMD_SET_MIDI_VOL, 100))
                ok = false;
        if (!host_write_ctrl_unsafe(sscape->io_base, sscape->midi_vol, 100))
                ok = false;
        if (!host_write_ctrl_unsafe(sscape->io_base, CMD_XXX_MIDI_VOL, 100))
                ok = false;
        if (!host_write_ctrl_unsafe(sscape->io_base, sscape->midi_vol, 100))
                ok = false;
        if (!host_write_ctrl_unsafe(sscape->io_base, CMD_SET_EXTMIDI, 100))
                ok = false;
        if (!host_write_ctrl_unsafe(sscape->io_base, 0, 100))
                ok = false;
        if (!host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100))
                ok = false;

        set_midi_mode_unsafe(sscape->io_base);

        return ok ? 0 : -EIO;
  }

What you think?

-- 
Thanks,
Cássio


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  reply	other threads:[~2026-04-11 14:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-11  4:54 [PATCH 0/2] ALSA: sscape: add suspend/resume support Cássio Gabriel
2026-04-11  4:54 ` [PATCH 1/2] ALSA: sscape: Cache per-card resources for board reinitialization Cássio Gabriel
2026-04-11  8:07   ` Takashi Iwai
2026-04-11 14:33     ` Cássio Gabriel Monteiro Pires [this message]
2026-04-11 16:17       ` Takashi Iwai
2026-04-11 17:29         ` Cássio Gabriel Monteiro Pires
2026-04-11  4:54 ` [PATCH 2/2] ALSA: sscape: Add suspend and resume support Cássio Gabriel

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=fe520e2a-5a95-4b57-a16b-a7a08a326ee7@gmail.com \
    --to=cassiogabrielcontato@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /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