Skip to content

Commit 86bb4f6

Browse files
gregkhbjorn-helgaas
authored andcommitted
PCI/MSI: Check kmalloc() return value, fix leak of name
Coverity reported that I forgot to check the return value of kmalloc() when creating the MSI attribute name, so fix that up and properly free it if there is an error when allocating the msi_dev_attr variable. Found by Coverity (CID 1163315 and 1163316). Fixes: 1c51b50 ("PCI/MSI: Export MSI mode using attributes, not kobjects") Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 322a8e9 commit 86bb4f6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/pci/msi.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,15 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
545545
return -ENOMEM;
546546
list_for_each_entry(entry, &pdev->msi_list, list) {
547547
char *name = kmalloc(20, GFP_KERNEL);
548+
if (!name)
549+
goto error_attrs;
550+
548551
msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL);
549-
if (!msi_dev_attr)
552+
if (!msi_dev_attr) {
553+
kfree(name);
550554
goto error_attrs;
555+
}
556+
551557
sprintf(name, "%d", entry->irq);
552558
sysfs_attr_init(&msi_dev_attr->attr);
553559
msi_dev_attr->attr.name = name;

0 commit comments

Comments
 (0)