Skip to contentSkip to conversation

Return -ENODEV instead of -EFAULT on module-get failure

PATCH Superseded [email protected] 4 participants 17 messages Jul 6 – Jul 10 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Return -ENODEV instead of -EFAULT on module-get failure

From: bui duc phuc <[email protected]>

Hi all,

Several ALSA open/allocate paths call try_module_get() on the owning card module and return -EFAULT when it fails. However, try_module_get() fails when the module is no longer live (i.e. it is going away), meaning the device is no longer usable.
This series updates only those paths, making the error code consistent with the existing "device unavailable" checks in the same functions. Other -EFAULT returns are left unchanged.
No functional change is intended.

Best regards,
Phuc

bui duc phuc (6):
ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()
ALSA: hwdep: Return -ENODEV instead of -EFAULT in snd_hwdep_open()
ALSA: info: Return -ENODEV instead of -EFAULT in alloc_info_private()
ALSA: mixer: oss: Return -ENODEV instead of -EFAULT in
snd_mixer_oss_open()
ALSA: pcm: oss: Return -ENODEV instead of -EFAULT in

    snd_pcm_oss_open()

ALSA: pcm: Return -ENODEV instead of -EFAULT in snd_pcm_open()

 sound/core/control.c       | 3 +--
 sound/core/hwdep.c         | 2 +-
 sound/core/info.c          | 2 +-
 sound/core/oss/mixer_oss.c | 2 +-
 sound/core/oss/pcm_oss.c   | 2 +-
 sound/core/pcm_native.c    | 2 +-
 6 files changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/6 ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()

From: bui duc phuc <[email protected]>

When try_module_get() fails in snd_ctl_open(), the owning module is going away and the device is no longer usable, so -EFAULT ("bad address") is the wrong error. Return -ENODEV, matching the other unavailable-device paths in this function(the NULL card check and the snd_card_file_add() failure). This changes the errno reported to userspace on this rare race. No other behaviour changes.

---
 sound/core/control.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/core/control.c +1 -2
index 037e455bb11b..f64b2dec746a 100644
@@ -64,11 +64,10 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
 	}
 	err = snd_card_file_add(card, file);
 	if (err < 0) {
-		err = -ENODEV;
 		goto __error1;
 	}
 	if (!try_module_get(card->module)) {
-		err = -EFAULT;
+		err = -ENODEV;
 		goto __error2;
 	}
 	ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
Signature · 1 line
2.43.0
#7 lore raw

PATCH 2/6 ALSA: hwdep: Return -ENODEV instead of -EFAULT in snd_hwdep_open()

In reply to [email protected]

From: bui duc phuc <[email protected]>

When try_module_get() fails in snd_hwdep_open(), the owning module is going away and the device is no longer usable, so -EFAULT ("bad address") is the wrong error. Return -ENODEV, matching the other unavailable-device paths in this function(the NULL hw check and the card->shutdown check). This changes the errno reported to userspace on this rare race. No other behaviour changes.

---
 sound/core/hwdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/hwdep.c +1 -1
index 973d11732bfd..352047e0b33e 100644
@@ -87,7 +87,7 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
 
 	if (!try_module_get(hw->card->module)) {
 		snd_card_unref(hw->card);
-		return -EFAULT;
+		return -ENODEV;
 	}
 
 	init_waitqueue_entry(&wait, current);
Signature · 1 line
2.43.0
#8 lore raw

PATCH 3/6 ALSA: info: Return -ENODEV instead of -EFAULT in alloc_info_private()

In reply to [email protected]

From: bui duc phuc <[email protected]>

When try_module_get() fails in alloc_info_private(), the owning module is going away and the device is no longer usable, so -EFAULT ("bad address") is the wrong error. Return -ENODEV, matching the other -ENODEV path in the same function.
This changes the errno reported to userspace on this rare race. No other behaviour changes.

---
 sound/core/info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/info.c +1 -1
index 54834dbe6b59..3b8ccda04e1a 100644
@@ -78,7 +78,7 @@ static int alloc_info_private(struct snd_info_entry *entry,
 	if (!entry || !entry->p)
 		return -ENODEV;
 	if (!try_module_get(entry->module))
-		return -EFAULT;
+		return -ENODEV;
 	data = kzalloc_obj(*data);
 	if (!data) {
 		module_put(entry->module);
Signature · 1 line
2.43.0
#9 lore raw

PATCH 4/6 ALSA: mixer: oss: Return -ENODEV instead of -EFAULT in snd_mixer_oss_open()

In reply to [email protected]

From: bui duc phuc <[email protected]>

When try_module_get() fails in snd_mixer_oss_open(), the owning module is going away and the device is no longer usable, so -EFAULT ("bad address") is the wrong error. Return -ENODEV, matching the other unavailable-device paths in this function(the NULL card check and the NULL mixer_oss check). This changes the errno reported to userspace on this rare race. No other behaviour changes.

---
 sound/core/oss/mixer_oss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/oss/mixer_oss.c +1 -1
index f5bcc7896542..3a1dd1edd26d 100644
@@ -58,7 +58,7 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file)
 		kfree(fmixer);
 		snd_card_file_remove(card, file);
 		snd_card_unref(card);
-		return -EFAULT;
+		return -ENODEV;
 	}
 	snd_card_unref(card);
 	return 0;
Signature · 1 line
2.43.0
#10 lore raw

PATCH 5/6 ALSA: pcm: oss: Return -ENODEV instead of -EFAULT in snd_pcm_oss_open()

In reply to [email protected]

From: bui duc phuc <[email protected]>

When try_module_get() fails in snd_pcm_oss_open(), the owning module is going away and the device is no longer usable, so -EFAULT ("bad address") is the wrong error. Return -ENODEV, matching the other unavailable-device paths in this function(the NULL pcm check and the card->shutdown check). This changes the errno reported to userspace on this rare race. No other behaviour changes.

---
 sound/core/oss/pcm_oss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/oss/pcm_oss.c +1 -1
index 0d7818eb3e14..8ae43755fb9b 100644
@@ -2507,7 +2507,7 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
 	if (err < 0)
 		goto __error1;
 	if (!try_module_get(pcm->card->module)) {
-		err = -EFAULT;
+		err = -ENODEV;
 		goto __error2;
 	}
 	if (snd_task_name(current, task_name, sizeof(task_name)) < 0) {
Signature · 1 line
2.43.0
#11 lore raw

PATCH 6/6 ALSA: pcm: Return -ENODEV instead of -EFAULT in snd_pcm_open()

In reply to [email protected]

From: bui duc phuc <[email protected]>

When try_module_get() fails in snd_pcm_open(), the owning module is going away and the device is no longer usable, so -EFAULT ("bad address") is the wrong error. Return -ENODEV, matching the other unavailable-device paths in this function(the NULL pcm check and the card->shutdown check). This changes the errno reported to userspace on this rare race. No other behaviour changes.

---
 sound/core/pcm_native.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/pcm_native.c +1 -1
index 3462cd5275a2..4fe5fab8d096 100644
@@ -2913,7 +2913,7 @@ static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream)
 	if (err < 0)
 		goto __error1;
 	if (!try_module_get(pcm->card->module)) {
-		err = -EFAULT;
+		err = -ENODEV;
 		goto __error2;
 	}
 	init_waitqueue_entry(&wait, current);
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()

In reply to [email protected]
Quoted 19 lines · On 7/6/2026 10:49 AM, [email protected] wrote:

From: bui duc phuc <[email protected]>

When try_module_get() fails in snd_ctl_open(), the owning module is going away and the device is no longer usable, so -EFAULT ("bad address") is the wrong error. Return -ENODEV, matching the other unavailable-device paths in this function(the NULL card check and the snd_card_file_add() failure). This changes the errno reported to userspace on this rare race. No other behaviour changes.

---
  sound/core/control.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
sound/core/control.c +0 -0
index 037e455bb11b..f64b2dec746a 100644

sound/core/control.c static int snd_ctl_open(struct inode *inode, struct file *file) · line 67

Quoted 4 lines
sound/core/control.c +0 -1
@@ -64,11 +64,10 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
  	}
  	err = snd_card_file_add(card, file);
  	if (err < 0) {
-		err = -ENODEV;

Seems unrelated to the patchset.

Quoted 8 lines
sound/core/control.c +1 -1
  		goto __error1;
  	}
  	if (!try_module_get(card->module)) {
-		err = -EFAULT;
+		err = -ENODEV;
  		goto __error2;
  	}
  	ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
#3 lore raw

Re: [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()

Hi Cezary,

Thank you for your review !

Quoted 6 lines
Quoted 3 lines
      err = snd_card_file_add(card, file);
      if (err < 0) {

- err = -ENODEV;

Seems unrelated to the patchset.

I just fixed it while I was there. Splitting it into two patches would also have been fine,
but I was a bit lazy to write another commit message. :)

This also preserves the original return value from snd_card_file_add() (-ENOMEM or -ENODEV)
instead of unconditionally replacing it with -ENODEV.

Best regards,
Phuc

#12 lore raw
In reply to [email protected]
Quoted 4 lines · On 7/6/2026 10:49 AM, [email protected] wrote:

From: bui duc phuc <[email protected]>

Hi all,

Quoted 8 lines

Several ALSA open/allocate paths call try_module_get() on the owning card module and return -EFAULT when it fails. However, try_module_get() fails when the module is no longer live (i.e. it is going away), meaning the device is no longer usable.
This series updates only those paths, making the error code consistent with the existing "device unavailable" checks in the same functions. Other -EFAULT returns are left unchanged.
No functional change is intended.

Changing a return code _is_ a functional change, so the last statement is bogus.

Now, there is a benefit of having a different error code in try_module_get() case: easier to find the offending bit when viewing logs. All the functions in the area have rather low log-coverage so distinct error codes help.

Regardless, as you mentioned, -EFAULT isn't exactly the right return code either so the direction of the patchset is good.

#13 lore raw

Hi Cezary,

Thank you for your review.

Quoted 4 lines
Quoted 1 line

No functional change is intended.

Changing a return code _is_ a functional change, so the last statement is bogus.

Agreed, will fix the commit message.

Quoted 7 lines

Now, there is a benefit of having a different error code in try_module_get() case: easier to find the offending bit when viewing logs. All the functions in the area have rather low log-coverage so distinct error codes help.

Regardless, as you mentioned, -EFAULT isn't exactly the right return code either so the direction of the patchset is good.

Should I also add dev_err() at these paths, or is the distinct error code enough for now?

Best regards,
Phuc

#14 lore raw
Quoted 10 lines · Bui Duc Phuc
Quoted 7 lines

Now, there is a benefit of having a different error code in try_module_get() case: easier to find the offending bit when viewing logs. All the functions in the area have rather low log-coverage so distinct error codes help.

Regardless, as you mentioned, -EFAULT isn't exactly the right return code either so the direction of the patchset is good.

Should I also add dev_err() at these paths, or is the distinct error code enough for now?

Nah, typically I prefer not to mix the changes, let them remain atomic. Distinct error code is enough.

In regard to the specific constant, I'd ask Takashi and Jaroslav what's their view on the subject. Perhaps -EPERM or -ENOENT are good candidates.

#15 lore raw
Quoted 11 lines · Cezary Rojewski
Quoted 8 lines · Bui Duc Phuc
Quoted 7 lines

Now, there is a benefit of having a different error code in try_module_get() case: easier to find the offending bit when viewing logs. All the functions in the area have rather low log-coverage so distinct error codes help.

Regardless, as you mentioned, -EFAULT isn't exactly the right return code either so the direction of the patchset is good.

Quoted 8 lines
Quoted 2 lines

Should I also add dev_err() at these paths, or is the distinct error code enough for now?

Nah, typically I prefer not to mix the changes, let them remain atomic. Distinct error code is enough.

In regard to the specific constant, I'd ask Takashi and Jaroslav what's their view on the subject. Perhaps -EPERM or -ENOENT are good candidates.

A quick grep showed the statics like:
85 ENODEV
41 EINVAL
17 EBUSY
16 EFAULT
14 ENOENT
10 EPROBE
8 EIO
6 ENXIO
3 EPROTONOSUPPORT
3 EAGAIN
3 EACCES
2 EXPORT
2 EPERM
2 ENOLCK
1 EPROTO
1 EOPNOTSUPP
1 ENOSYS
1 ENOPROTOOPT
1 EAFNOSUPPORT

So -ENODEV looks fine.

thanks,

Takashi

#16 lore raw

Hi Takashi-san, Cezary,

Thanks for checking.

Quoted 21 lines

A quick grep showed the statics like:
85 ENODEV
41 EINVAL
17 EBUSY
16 EFAULT
14 ENOENT
10 EPROBE
8 EIO
6 ENXIO
3 EPROTONOSUPPORT
3 EAGAIN
3 EACCES
2 EXPORT
2 EPERM
2 ENOLCK
1 EPROTO
1 EOPNOTSUPP
1 ENOSYS
1 ENOPROTOOPT
1 EAFNOSUPPORT

Quoted 2 lines

So -ENODEV looks fine.

I'll keep the current -ENODEV return value.
I'll update the commit message and send a v2.

Best regards,
Phuc

#4 lore raw

Re: [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()

In reply to Bui Duc Phuc

Hi Cezary,

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
      err = snd_card_file_add(card, file);
      if (err < 0) {

- err = -ENODEV;

Seems unrelated to the patchset.

I'll drop this change from the current series and send it as a separate patch.

Best regards,
Phuc

#5 lore raw

Re: [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()

In reply to [email protected]
Quoted 1 line · On Mon, Jul 06, 2026 at 03:49:45PM +0700, [email protected] wrote:

From: bui duc phuc <[email protected]>

When you're sending email, then you always capitalize your name but when you're sending patches then you don't. The Signed-off-by lines are supposed to be formal like signing a legal document. So which ever way you sign off a legal document is fine...

I normally don't capitalize my name on email because I guess at some point I decided it would be fun to disobey the rules. But I do for patches.

regards,
dan carpenter

#6 lore raw

Re: [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()

Hi Dan,

Thanks for the feedback.

Quoted 10 lines

When you're sending email, then you always capitalize your name but when you're sending patches then you don't. The Signed-off-by lines are supposed to be formal like signing a legal document. So which ever way you sign off a legal document is fine...

I normally don't capitalize my name on email because I guess at some point I decided it would be fun to disobey the rules. But I do for patches.

Previously, Cezary also brought up this naming convention, and I shared my perspective in this discussion:
https://lore.kernel.org/all/CAABR9nH6b8kSQt5w8vPGFiXGH3h+QDQdjKgsF-C3pa2hUh1Wiw@mail.gmail.com/

As far as I know, there is no strict kernel rule mandating capitalization in the Signed-off-by line. In fact, our real-world signatures on paper are often just undecipherable scribbles anyway.

Since it still represents my real name and identity, I would prefer to keep it this way as long as it does not violate any official kernel rules.

By the way, I noticed that while most people use an email address containing their actual name in the Signed-off-by line, yours is [email protected]. Is there an interesting story behind that?

Best regards,
Phuc