Skip to contentSkip to conversation

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

PATCH Applied [email protected] 3 participants 9 messages Jul 7 – Jul 8 Sound

lore
Share & tools
lore
#0 lore raw

v2 cover ALSA: 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.

Link v1:
https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Update the commit message.
- Remove unrelated changes from the "ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()" patch.

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       | 2 +-
 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(+), 6 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 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.

---

Changes in v2:
- Drop the unrelated change from this series.

 sound/core/control.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/control.c +1 -1
index 037e455bb11b..0ca9fff56e51 100644
@@ -68,7 +68,7 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
 		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
#2 lore raw

PATCH v2 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
#3 lore raw

PATCH v2 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
#4 lore raw

PATCH v2 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
#5 lore raw

PATCH v2 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
#6 lore raw

PATCH v2 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
Reviewed-by on the v2 series
#7 lore raw
In reply to [email protected]
Quoted 12 lines · On 7/7/2026 10:45 AM, [email protected] wrote:

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.

Quoted 7 lines

Link v1:
https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Update the commit message.
- Remove unrelated changes from the "ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()" patch.

For the series:

Applied
#8 lore raw
In reply to [email protected]
Quoted 31 lines · On Tue, 07 Jul 2026 10:45:00 +0200, [email protected] wrote:

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.

Link v1:
https://lore.kernel.org/all/[email protected]/

Changes in v2:
- Update the commit message.
- Remove unrelated changes from the "ALSA: control: Return -ENODEV instead of -EFAULT in snd_ctl_open()" patch.

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

Quoted 2 lines
    snd_pcm_oss_open()

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

Applied to for-next branch now. Thanks.

Takashi