* [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()
2026-07-06 8:49 [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure phucduc.bui
@ 2026-07-06 8:49 ` phucduc.bui
2026-07-06 9:35 ` Cezary Rojewski
2026-07-06 8:49 ` [PATCH 2/6] ALSA: hwdep: Return -ENODEV instead of -EFAULT in snd_hwdep_open() phucduc.bui
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: phucduc.bui @ 2026-07-06 8:49 UTC (permalink / raw)
To: Cezary Rojewski, Jaroslav Kysela, Takashi Iwai,
cassiogabrielcontato
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/core/control.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/core/control.c b/sound/core/control.c
index 037e455bb11b..f64b2dec746a 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()
2026-07-06 8:49 ` [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open() phucduc.bui
@ 2026-07-06 9:35 ` Cezary Rojewski
2026-07-06 9:40 ` Bui Duc Phuc
0 siblings, 1 reply; 13+ messages in thread
From: Cezary Rojewski @ 2026-07-06 9:35 UTC (permalink / raw)
To: phucduc.bui
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
Jaroslav Kysela, Takashi Iwai, cassiogabrielcontato
On 7/6/2026 10:49 AM, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
>
> 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.
>
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
> ---
> sound/core/control.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/sound/core/control.c b/sound/core/control.c
> index 037e455bb11b..f64b2dec746a 100644
> --- a/sound/core/control.c
> +++ b/sound/core/control.c
> @@ -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.
> goto __error1;
> }
> if (!try_module_get(card->module)) {
> - err = -EFAULT;
> + err = -ENODEV;
> goto __error2;
> }
> ctl = kzalloc(sizeof(*ctl), GFP_KERNEL);
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()
2026-07-06 9:35 ` Cezary Rojewski
@ 2026-07-06 9:40 ` Bui Duc Phuc
0 siblings, 0 replies; 13+ messages in thread
From: Bui Duc Phuc @ 2026-07-06 9:40 UTC (permalink / raw)
To: Cezary Rojewski
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
Jaroslav Kysela, Takashi Iwai, cassiogabrielcontato
Hi Cezary,
Thank you for your review !
> > 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
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 2/6] ALSA: hwdep: Return -ENODEV instead of -EFAULT in snd_hwdep_open()
2026-07-06 8:49 [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure phucduc.bui
2026-07-06 8:49 ` [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open() phucduc.bui
@ 2026-07-06 8:49 ` phucduc.bui
2026-07-06 8:49 ` [PATCH 3/6] ALSA: info: Return -ENODEV instead of -EFAULT in alloc_info_private() phucduc.bui
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: phucduc.bui @ 2026-07-06 8:49 UTC (permalink / raw)
To: Cezary Rojewski, Jaroslav Kysela, Takashi Iwai,
cassiogabrielcontato
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/core/hwdep.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index 973d11732bfd..352047e0b33e 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 3/6] ALSA: info: Return -ENODEV instead of -EFAULT in alloc_info_private()
2026-07-06 8:49 [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure phucduc.bui
2026-07-06 8:49 ` [PATCH 1/6] ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open() phucduc.bui
2026-07-06 8:49 ` [PATCH 2/6] ALSA: hwdep: Return -ENODEV instead of -EFAULT in snd_hwdep_open() phucduc.bui
@ 2026-07-06 8:49 ` phucduc.bui
2026-07-06 8:49 ` [PATCH 4/6] ALSA: mixer: oss: Return -ENODEV instead of -EFAULT in snd_mixer_oss_open() phucduc.bui
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: phucduc.bui @ 2026-07-06 8:49 UTC (permalink / raw)
To: Cezary Rojewski, Jaroslav Kysela, Takashi Iwai,
cassiogabrielcontato
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/core/info.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/core/info.c b/sound/core/info.c
index 54834dbe6b59..3b8ccda04e1a 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 4/6] ALSA: mixer: oss: Return -ENODEV instead of -EFAULT in snd_mixer_oss_open()
2026-07-06 8:49 [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure phucduc.bui
` (2 preceding siblings ...)
2026-07-06 8:49 ` [PATCH 3/6] ALSA: info: Return -ENODEV instead of -EFAULT in alloc_info_private() phucduc.bui
@ 2026-07-06 8:49 ` phucduc.bui
2026-07-06 8:49 ` [PATCH 5/6] ALSA: pcm: oss: Return -ENODEV instead of -EFAULT in snd_pcm_oss_open() phucduc.bui
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: phucduc.bui @ 2026-07-06 8:49 UTC (permalink / raw)
To: Cezary Rojewski, Jaroslav Kysela, Takashi Iwai,
cassiogabrielcontato
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/core/oss/mixer_oss.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index f5bcc7896542..3a1dd1edd26d 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 5/6] ALSA: pcm: oss: Return -ENODEV instead of -EFAULT in snd_pcm_oss_open()
2026-07-06 8:49 [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure phucduc.bui
` (3 preceding siblings ...)
2026-07-06 8:49 ` [PATCH 4/6] ALSA: mixer: oss: Return -ENODEV instead of -EFAULT in snd_mixer_oss_open() phucduc.bui
@ 2026-07-06 8:49 ` phucduc.bui
2026-07-06 8:49 ` [PATCH 6/6] ALSA: pcm: Return -ENODEV instead of -EFAULT in snd_pcm_open() phucduc.bui
2026-07-06 9:42 ` [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure Cezary Rojewski
6 siblings, 0 replies; 13+ messages in thread
From: phucduc.bui @ 2026-07-06 8:49 UTC (permalink / raw)
To: Cezary Rojewski, Jaroslav Kysela, Takashi Iwai,
cassiogabrielcontato
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/core/oss/pcm_oss.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 0d7818eb3e14..8ae43755fb9b 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -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) {
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH 6/6] ALSA: pcm: Return -ENODEV instead of -EFAULT in snd_pcm_open()
2026-07-06 8:49 [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure phucduc.bui
` (4 preceding siblings ...)
2026-07-06 8:49 ` [PATCH 5/6] ALSA: pcm: oss: Return -ENODEV instead of -EFAULT in snd_pcm_oss_open() phucduc.bui
@ 2026-07-06 8:49 ` phucduc.bui
2026-07-06 9:42 ` [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure Cezary Rojewski
6 siblings, 0 replies; 13+ messages in thread
From: phucduc.bui @ 2026-07-06 8:49 UTC (permalink / raw)
To: Cezary Rojewski, Jaroslav Kysela, Takashi Iwai,
cassiogabrielcontato
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/core/pcm_native.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 3462cd5275a2..4fe5fab8d096 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure
2026-07-06 8:49 [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure phucduc.bui
` (5 preceding siblings ...)
2026-07-06 8:49 ` [PATCH 6/6] ALSA: pcm: Return -ENODEV instead of -EFAULT in snd_pcm_open() phucduc.bui
@ 2026-07-06 9:42 ` Cezary Rojewski
2026-07-06 12:31 ` Bui Duc Phuc
6 siblings, 1 reply; 13+ messages in thread
From: Cezary Rojewski @ 2026-07-06 9:42 UTC (permalink / raw)
To: phucduc.bui
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
Jaroslav Kysela, Takashi Iwai, cassiogabrielcontato
On 7/6/2026 10:49 AM, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
>
> 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.
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.
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure
2026-07-06 9:42 ` [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure Cezary Rojewski
@ 2026-07-06 12:31 ` Bui Duc Phuc
2026-07-06 13:13 ` Cezary Rojewski
0 siblings, 1 reply; 13+ messages in thread
From: Bui Duc Phuc @ 2026-07-06 12:31 UTC (permalink / raw)
To: Cezary Rojewski
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
Jaroslav Kysela, Takashi Iwai, cassiogabrielcontato
Hi Cezary,
Thank you for your review.
> > 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.
> 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
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure
2026-07-06 12:31 ` Bui Duc Phuc
@ 2026-07-06 13:13 ` Cezary Rojewski
2026-07-06 13:26 ` Takashi Iwai
0 siblings, 1 reply; 13+ messages in thread
From: Cezary Rojewski @ 2026-07-06 13:13 UTC (permalink / raw)
To: Bui Duc Phuc
Cc: Kees Cook, Dan Carpenter, Cen Zhang, Len Bao, Mehul Rao,
Sebastian Andrzej Siewior, linux-sound, linux-kernel,
Jaroslav Kysela, Takashi Iwai, cassiogabrielcontato
On 7/6/2026 2:31 PM, Bui Duc Phuc wrote:
>> 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.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH 0/6] Return -ENODEV instead of -EFAULT on module-get failure
2026-07-06 13:13 ` Cezary Rojewski
@ 2026-07-06 13:26 ` Takashi Iwai
0 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2026-07-06 13:26 UTC (permalink / raw)
To: Cezary Rojewski
Cc: Bui Duc Phuc, Kees Cook, Dan Carpenter, Cen Zhang, Len Bao,
Mehul Rao, Sebastian Andrzej Siewior, linux-sound, linux-kernel,
Jaroslav Kysela, Takashi Iwai, cassiogabrielcontato
On Mon, 06 Jul 2026 15:13:15 +0200,
Cezary Rojewski wrote:
>
> On 7/6/2026 2:31 PM, Bui Duc Phuc wrote:
>
> >> 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.
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
^ permalink raw reply [flat|nested] 13+ messages in thread