Skip to content

Commit

Permalink
PCI/MSI: Check kmalloc() return value, fix leak of name
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Greg Kroah-Hartman authored and Bjorn Helgaas committed Feb 13, 2014
1 parent 322a8e9 commit 86bb4f6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/pci/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,15 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
return -ENOMEM;
list_for_each_entry(entry, &pdev->msi_list, list) {
char *name = kmalloc(20, GFP_KERNEL);
if (!name)
goto error_attrs;

msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL);
if (!msi_dev_attr)
if (!msi_dev_attr) {
kfree(name);
goto error_attrs;
}

sprintf(name, "%d", entry->irq);
sysfs_attr_init(&msi_dev_attr->attr);
msi_dev_attr->attr.name = name;
Expand Down

0 comments on commit 86bb4f6

Please sign in to comment.