Skip to contentSkip to conversation

media: cx23885: Fix snd_card_free call on null card pointer

PATCH New Colin King 1 participant 1 message Aug 4, 2021

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 media: cx23885: Fix snd_card_free call on null card pointer

From: Colin Ian King <[email protected]>

Currently a call to snd_card_new that fails will set card with a NULL pointer, this causes a null pointer dereference on the error cleanup path when card it passed to snd_card_free. Fix this by adding a new error exit path that does not call snd_card_free and exiting via this new path.

Addresses-Coverity: ("Explicit null dereference")

Fixes 9e44d63246a9 ("[media] cx23885: Add ALSA support")
---
 drivers/media/pci/cx23885/cx23885-alsa.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/pci/cx23885/cx23885-alsa.c +2 -1
index ab14d35214aa..25dc8d4dc5b7 100644
@@ -550,7 +550,7 @@ struct cx23885_audio_dev *cx23885_audio_register(struct cx23885_dev *dev)
 			   SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
 			THIS_MODULE, sizeof(struct cx23885_audio_dev), &card);
 	if (err < 0)
-		goto error;
+		goto error_msg;
 
 	chip = (struct cx23885_audio_dev *) card->private_data;
 	chip->dev = dev;
@@ -576,6 +576,7 @@ struct cx23885_audio_dev *cx23885_audio_register(struct cx23885_dev *dev)
 
 error:
 	snd_card_free(card);
+error_msg:
 	pr_err("%s(): Failed to register analog audio adapter\n",
 	       __func__);
 
Signature · 1 line
2.31.1