Skip to contentSkip to conversation

ALSA: control: preserve snd_card_file_add() error code in snd_ctl_open()

PATCH In review [email protected] 3 participants 5 messages Jul 8 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALSA: control: preserve snd_card_file_add() error code in snd_ctl_open()

From: bui duc phuc <[email protected]>

snd_ctl_open() unconditionally overwrites the return value of snd_card_file_add() with -ENODEV on failure, discarding the actual error code.

Fix this by directly returning the original error code returned by snd_card_file_add() (e.g. -ENOMEM or -ENODEV). This behavior is consistent with the error handling used in other functions such as snd_mixer_oss_open(), snd_hwdep_open(), snd_pcm_oss_open(), and others.

There is no functional change other than the returned error code in this failure path.

---

Changes in v2:
- Update commit messages.
- Drop superfluous braces.

 sound/core/control.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/core/control.c +1 -3
index 0ca9fff56e51..73d7ba0f509f 100644
@@ -63,10 +63,8 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
 		goto __error1;
 	}
 	err = snd_card_file_add(card, file);
-	if (err < 0) {
-		err = -ENODEV;
+	if (err < 0)
 		goto __error1;
-	}
 	if (!try_module_get(card->module)) {
 		err = -ENODEV;
 		goto __error2;
Signature · 1 line
2.43.0
#2 lore raw
In reply to [email protected]
Quoted 12 lines · On Wed, 08 Jul 2026 04:35:40 +0200, [email protected] wrote:

From: bui duc phuc <[email protected]>

snd_ctl_open() unconditionally overwrites the return value of snd_card_file_add() with -ENODEV on failure, discarding the actual error code.

Fix this by directly returning the original error code returned by snd_card_file_add() (e.g. -ENOMEM or -ENODEV). This behavior is consistent with the error handling used in other functions such as snd_mixer_oss_open(), snd_hwdep_open(), snd_pcm_oss_open(), and others.

Quoted 4 lines

There is no functional change other than the returned error code in this failure path.

Applied now to for-next branch. Thanks.

Takashi

#3 lore raw
In reply to [email protected]
Quoted 6 lines · On 7/8/2026 4:35 AM, [email protected] wrote:

From: bui duc phuc <[email protected]>

snd_ctl_open() unconditionally overwrites the return value of snd_card_file_add() with -ENODEV on failure, discarding the actual error code.

Quoted 7 lines

Fix this by directly returning the original error code returned by snd_card_file_add() (e.g. -ENOMEM or -ENODEV). This behavior is consistent with the error handling used in other functions such as snd_mixer_oss_open(), snd_hwdep_open(), snd_pcm_oss_open(), and others.

There is no functional change other than the returned error code in this failure path.

BTW, as you've provided a number of positive contributions, a tip for future:

The change is simple and does not relate to any workaround or some kind of 'recommended' sequence. And thus there's no need to be as verbose. IMHO the first paragraph suffices - explicitly answers the _why_ question.

The last is completely redundant - return code is a functional change. Similarly, "Fix this by (...)" in context of such a simple change yields no value for the reader - we see _what_ is happening clearly in the code.

Quoted 26 lines

---

Changes in v2:
- Update commit messages.
- Drop superfluous braces.

  sound/core/control.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
sound/core/control.c +1 -3
index 0ca9fff56e51..73d7ba0f509f 100644
@@ -63,10 +63,8 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
  		goto __error1;
  	}
  	err = snd_card_file_add(card, file);
-	if (err < 0) {
-		err = -ENODEV;
+	if (err < 0)
  		goto __error1;
-	}
  	if (!try_module_get(card->module)) {
  		err = -ENODEV;
  		goto __error2;
#4 lore raw

Hi Cezary,

Thanks for the tip, appreciate it.

Quoted 10 lines

BTW, as you've provided a number of positive contributions, a tip for future:

The change is simple and does not relate to any workaround or some kind of 'recommended' sequence. And thus there's no need to be as verbose. IMHO the first paragraph suffices - explicitly answers the _why_ question.

The last is completely redundant - return code is a functional change. Similarly, "Fix this by (...)" in context of such a simple change yields no value for the reader - we see _what_ is happening clearly in the code.

Will keep future commit messages more concise and focused on the why.

Best regards,
Phuc