Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sreeraj S Kurup" <sreekuttan2156239@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] sound: Add a generic result header
Date: Fri, 04 Dec 2026 11:48:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-249721@kernel.org> (raw)
In-Reply-To: <20261204114122.4465-1-sreekuttan2156239@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sound: unidiomatic type-erased struct snd_result duplicates
  kernel idioms
- [Low] sound: add unused public header include/sound/snd_result.h with
  no callers
--

commit 1e31fdcfe3387f0bfdf6718e049b56a19745e76e
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

sound: Add a generic result header

This commit adds include/sound/snd_result.h defining struct snd_result,
enum snd_result_type, and inline constructors for returning an error code,
integer, unsigned integer, or pointer from sound APIs.

> diff --git a/include/sound/snd_result.h b/include/sound/snd_result.h
> new file mode 100644
> index 0000000000000..61503675e7fba
> --- /dev/null
> +++ b/include/sound/snd_result.h
> @@ -0,0 +1,61 @@

[ ... ]

> +#ifndef __SOUND_RESULT_H
> +#define __SOUND_RESULT_H

[Severity: Low]
Should this header wait until there are in-tree callers using it?

Nothing in the tree includes sound/snd_result.h or uses struct snd_result
or any of the snd_result_*() helpers.  Without concrete call sites, the
header is not build-tested during normal builds and cannot be evaluated
against actual sound APIs.  Introducing it alongside the first conversions
would avoid adding unused infrastructure.

> +enum snd_result_type {
> +	SND_RESULT_ERR,
> +	SND_RESULT_INT,
> +	SND_RESULT_UINT,
> +	SND_RESULT_PTR,
> +};
> +
> +struct snd_result {
> +	enum snd_result_type type;
> +	union {
> +		int err;
> +		int i;
> +		unsigned int u;
> +		void *ptr;
> +	};
> +};
> +
> +static inline struct snd_result snd_result_err(int err)
> +{
> +	return (struct snd_result) {
> +		.type = SND_RESULT_ERR,
> +		.err = err,
> +	};
> +}

[ ... ]

> +static inline struct snd_result snd_result_ptr(void *value)
> +{
> +	return (struct snd_result) {
> +		.type = SND_RESULT_PTR,
> +		.ptr = value,
> +	};
> +}

[Severity: Medium]
Does ALSA need a custom type-erased struct snd_result when existing kernel
patterns already handle these return types?

Functions returning a full-range unsigned int with negative errno codes
conventionally return int with a typed output pointer, as
_snd_hdac_read_parm() in include/sound/hdaudio.h does.  Pointer returns use
ERR_PTR(), IS_ERR(), and PTR_ERR() from include/linux/err.h instead.

Using struct snd_result weakens compile-time type checking: all adopting
functions share one return type, snd_result_ptr() drops the pointee type
and const or address-space qualifiers, and callers read raw union members
without error predicates, accessors, __must_check, or ownership rules.

Assigning SND_RESULT_ERR to 0 makes any zero-initialized struct snd_result
appear as an error with err == 0, and snd_result_err() does not reject
non-negative values, so returning res.err on an error path can silently
return 0.

Returning a 16-byte struct by value on 64-bit targets (or via a hidden
stack pointer on 32-bit) also adds ABI overhead for simple integer results.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204114122.4465-1-sreekuttan2156239@gmail.com?part=1

  reply	other threads:[~2026-12-04 11:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 11:41 [PATCH] sound: Add a generic result header Sreeraj S Kurup
2026-12-04 11:48 ` sashiko-bot [this message]
2026-12-04 16:45 ` Takashi Iwai
2026-12-04 17:33   ` Sreeraj S Kurup

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=sashiko-outbox-249721@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sreekuttan2156239@gmail.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