[PATCH 6/6] ALSA: portman2x4: Check card index validity at probe

Takashi Iwai <[email protected]>
Newsgroups org.kernel.vger.linux-sound
Message-ID <[email protected]>
Although portman2x4 driver has a check of the given devptr->id value,
it doesn't check for a negative id, which is often given as "none" or
such value when bound via sysfs.  This may lead to OOB access for
index[] and other parameters.

Add a sanity check for the card index and warn/correct it if it's a
value out of the range.

Cc: <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
---
 sound/drivers/portman2x4.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
index dcc0899cfb99..03ed3c3c27fb 100644
--- a/sound/drivers/portman2x4.c
+++ b/sound/drivers/portman2x4.c
@@ -697,6 +697,12 @@ static int snd_portman_probe(struct platform_device *pdev)
 	p = platform_get_drvdata(pdev);
 	platform_set_drvdata(pdev, NULL);
 
+	if (dev < 0) {
+		dev_warn(&pdev->dev,
+			 "Invalid card index %d, using default 0\n", dev);
+		dev = 0;
+	}
+
 	if (dev >= SNDRV_CARDS)
 		return -ENODEV;
 	if (!enable[dev]) 
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.