Skip to content

Commit edfa91b

Browse files
CassivsGabriellisgregkh
authored andcommitted
ALSA: core: Validate compress device numbers without dynamic minors
[ Upstream commit 796e119 ] Without CONFIG_SND_DYNAMIC_MINORS, ALSA reserves only two fixed minors for compress devices on each card: comprD0 and comprD1. snd_find_free_minor() currently computes the compress minor as type + dev without validating dev first, so device numbers greater than 1 spill into the HWDEP minor range instead of failing registration. ASoC passes rtd->id to snd_compress_new(), so this can happen on real non-dynamic-minor builds. Add a dedicated fixed-minor check for SNDRV_DEVICE_TYPE_COMPRESS in snd_find_free_minor() and reject out-of-range device numbers with -EINVAL before constructing the minor. Also remove the stale TODO in compress_offload.c that still claims multiple compress nodes are missing. Fixes: 3eafc95 ("ALSA: core: add support for compressed devices") Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com> Link: https://patch.msgid.link/20260325-alsa-compress-static-minors-v1-1-0628573bee1c@gmail.com Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3c34999 commit edfa91b

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

sound/core/compress_offload.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@
4141
#define COMPR_CODEC_CAPS_OVERFLOW
4242
#endif
4343

44-
/* TODO:
45-
* - add substream support for multiple devices in case of
46-
* SND_DYNAMIC_MINORS is not used
47-
* - Multiple node representation
48-
* driver should be able to register multiple nodes
49-
*/
50-
5144
struct snd_compr_file {
5245
unsigned long caps;
5346
struct snd_compr_stream stream;

sound/core/sound.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,16 @@ static int snd_find_free_minor(int type, struct snd_card *card, int dev)
216216
case SNDRV_DEVICE_TYPE_RAWMIDI:
217217
case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
218218
case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
219+
if (snd_BUG_ON(!card))
220+
return -EINVAL;
221+
minor = SNDRV_MINOR(card->number, type + dev);
222+
break;
219223
case SNDRV_DEVICE_TYPE_COMPRESS:
220224
if (snd_BUG_ON(!card))
221225
return -EINVAL;
226+
if (dev < 0 ||
227+
dev >= SNDRV_MINOR_HWDEP - SNDRV_MINOR_COMPRESS)
228+
return -EINVAL;
222229
minor = SNDRV_MINOR(card->number, type + dev);
223230
break;
224231
default:

0 commit comments

Comments
 (0)