* [PATCH v2] media: go7007: fix a miss of snd_card_free
@ 2019-12-10 3:15 Chuhong Yuan
2019-12-10 11:48 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Chuhong Yuan @ 2019-12-10 3:15 UTC (permalink / raw)
Cc: Hans Verkuil, Mauro Carvalho Chehab, Markus Elfring,
Dan Carpenter, linux-media, linux-kernel, Chuhong Yuan
go7007_snd_init() misses a snd_card_free() in an error path.
Add the missed call to fix it.
Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
---
Changes in v2:
- Use goto to simplify the code.
drivers/media/usb/go7007/snd-go7007.c | 35 +++++++++++++--------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/drivers/media/usb/go7007/snd-go7007.c b/drivers/media/usb/go7007/snd-go7007.c
index b05fa227ffb2..95756cbb722f 100644
--- a/drivers/media/usb/go7007/snd-go7007.c
+++ b/drivers/media/usb/go7007/snd-go7007.c
@@ -236,22 +236,18 @@ int go7007_snd_init(struct go7007 *go)
gosnd->capturing = 0;
ret = snd_card_new(go->dev, index[dev], id[dev], THIS_MODULE, 0,
&gosnd->card);
- if (ret < 0) {
- kfree(gosnd);
- return ret;
- }
+ if (ret < 0)
+ goto free_snd;
+
ret = snd_device_new(gosnd->card, SNDRV_DEV_LOWLEVEL, go,
&go7007_snd_device_ops);
- if (ret < 0) {
- kfree(gosnd);
- return ret;
- }
+ if (ret < 0)
+ goto free_card;
+
ret = snd_pcm_new(gosnd->card, "go7007", 0, 0, 1, &gosnd->pcm);
- if (ret < 0) {
- snd_card_free(gosnd->card);
- kfree(gosnd);
- return ret;
- }
+ if (ret < 0)
+ goto free_card;
+
strscpy(gosnd->card->driver, "go7007", sizeof(gosnd->card->driver));
strscpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->shortname));
strscpy(gosnd->card->longname, gosnd->card->shortname,
@@ -262,11 +258,8 @@ int go7007_snd_init(struct go7007 *go)
&go7007_snd_capture_ops);
ret = snd_card_register(gosnd->card);
- if (ret < 0) {
- snd_card_free(gosnd->card);
- kfree(gosnd);
- return ret;
- }
+ if (ret < 0)
+ goto free_card;
gosnd->substream = NULL;
go->snd_context = gosnd;
@@ -274,6 +267,12 @@ int go7007_snd_init(struct go7007 *go)
++dev;
return 0;
+
+free_card:
+ snd_card_free(gosnd->card);
+free_snd:
+ kfree(gosnd);
+ return ret;
}
EXPORT_SYMBOL(go7007_snd_init);
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] media: go7007: fix a miss of snd_card_free
2019-12-10 3:15 [PATCH v2] media: go7007: fix a miss of snd_card_free Chuhong Yuan
@ 2019-12-10 11:48 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2019-12-10 11:48 UTC (permalink / raw)
To: Chuhong Yuan, linux-media
Cc: Hans Verkuil, Mauro Carvalho Chehab, Dan Carpenter, linux-kernel
> go7007_snd_init() misses a snd_card_free() in an error path.
> Add the missed call to fix it.
Can the tag “Reported-by” be appropriate according to a review comment
from 2017-09-19?
https://lkml.org/lkml/2017/9/19/115
https://lore.kernel.org/patchwork/comment/1026462/
> Changes in v2:
> - Use goto to simplify the code.
Thanks for your improvement of the exception handling.
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-12-10 11:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10 3:15 [PATCH v2] media: go7007: fix a miss of snd_card_free Chuhong Yuan
2019-12-10 11:48 ` Markus Elfring
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.