summaryrefslogtreecommitdiff
path: root/drivers/pci/msi.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-13 10:47:20 -0700
committerBjorn Helgaas <bhelgaas@google.com>2014-02-13 10:47:20 -0700
commit86bb4f697a964ab5e50f1159e04c6a5d5acde2d4 (patch)
tree7f5c75e35d58340c5d7fe391752e8ece4543f134 /drivers/pci/msi.c
parent322a8e91844f4ae2093e0d3d8a318d0ef2596756 (diff)
downloadlwn-86bb4f697a964ab5e50f1159e04c6a5d5acde2d4.tar.gz
lwn-86bb4f697a964ab5e50f1159e04c6a5d5acde2d4.zip
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: 1c51b50c2995 ("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>
Diffstat (limited to 'drivers/pci/msi.c')
-rw-r--r--drivers/pci/msi.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 7a0fec6ce571..39dff3fe57af 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -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;