mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-03-01 16:55:52 +07:00
ALSA: sound/pci/mixart/mixart.c: Add missing snd_card_free
The function snd_mixart_create creates a link between mgr and card that allows snd_mixart_free to free card as well. But if snd_mixart_create fails, then the link has not been created and card has to be freed explicitly. The semantic match that finds the problem is as follows: (http://www.emn.fr/x-info/coccinelle/) // <smpl> @r exists@ local idexpression x; statement S,S1; position p1,p2,p3; expression E,E1; type T,T1; expression *ptr != NULL; @@ ( if ((x@p1 = snd_card_new(...)) == NULL) S | x@p1 = snd_card_new(...); ) ... when != snd_card_free(...,(T)x,...) when != if (...) { <+... snd_card_free(...,(T)x,...) ...+> } when != true x == NULL || ... when != x = E when != E = (T)x when any ( if (x == NULL || ...) S1 | if@p2 (...) { ... when != snd_card_free(...,(T1)x,...) when != if (...) { <+... snd_card_free(...,(T1)x,...) ...+> } when != x = E1 when != E1 = (T1)x ( return \(0\|<+...x...+>\|ptr\); | return@p3 ...; ) } ) @ script:python @ p1 << r.p1; p3 << r.p3; @@ print "* file: %s snd_card_new: %s return: %s" % (p1[0].file,p1[0].line,p3[0].line) // </smpl> Signed-off-by: Julia Lawall <julia@diku.dk> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
12666f050b
commit
73f6a12ed1
@ -1010,7 +1010,7 @@ static int __devinit snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *
|
||||
.dev_free = snd_mixart_chip_dev_free,
|
||||
};
|
||||
|
||||
mgr->chip[idx] = chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
||||
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
||||
if (! chip) {
|
||||
snd_printk(KERN_ERR "cannot allocate chip\n");
|
||||
return -ENOMEM;
|
||||
@ -1025,6 +1025,7 @@ static int __devinit snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *
|
||||
return err;
|
||||
}
|
||||
|
||||
mgr->chip[idx] = chip;
|
||||
snd_card_set_dev(card, &mgr->pci->dev);
|
||||
|
||||
return 0;
|
||||
@ -1378,6 +1379,7 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
|
||||
sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i);
|
||||
|
||||
if ((err = snd_mixart_create(mgr, card, i)) < 0) {
|
||||
snd_card_free(card);
|
||||
snd_mixart_free(mgr);
|
||||
return err;
|
||||
}
|
||||
|
@ -1024,7 +1024,7 @@ static int __devinit pcxhr_create(struct pcxhr_mgr *mgr, struct snd_card *card,
|
||||
.dev_free = pcxhr_chip_dev_free,
|
||||
};
|
||||
|
||||
mgr->chip[idx] = chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
||||
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
||||
if (! chip) {
|
||||
snd_printk(KERN_ERR "cannot allocate chip\n");
|
||||
return -ENOMEM;
|
||||
@ -1050,6 +1050,7 @@ static int __devinit pcxhr_create(struct pcxhr_mgr *mgr, struct snd_card *card,
|
||||
return err;
|
||||
}
|
||||
|
||||
mgr->chip[idx] = chip;
|
||||
snd_card_set_dev(card, &mgr->pci->dev);
|
||||
|
||||
return 0;
|
||||
@ -1307,6 +1308,7 @@ static int __devinit pcxhr_probe(struct pci_dev *pci, const struct pci_device_id
|
||||
sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i);
|
||||
|
||||
if ((err = pcxhr_create(mgr, card, i)) < 0) {
|
||||
snd_card_free(card);
|
||||
pcxhr_free(mgr);
|
||||
return err;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user