Skip to contentSkip to conversation

pci: allocation check missing

PATCH In review Alan 2 participants 2 messages Feb 5, 2014 – Feb 11, 2014 PCI

lore
Share & tools
lore

Alan

author
#0 lore raw

PATCH 1/1 pci: allocation check missing

If we fail to allocate the name, just drop nicely into the fail path

(as a footnote someone who works on this code more might want to shuffle
the allocations about so the name and attributes are allocated and freed as one. There seems to be no reason to keep them separate)

---
 drivers/pci/msi.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/msi.c +5 -1
index 18ca2497..9bdf290 100644
@@ -544,9 +544,13 @@ 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;
maintainer
#1 lore raw
Quoted 7 lines · Alan

If we fail to allocate the name, just drop nicely into the fail path

(as a footnote someone who works on this code more might want to shuffle
the allocations about so the name and attributes are allocated and freed as one. There seems to be no reason to keep them separate)

I already applied Greg KH's identical patch, thanks! :)

http://git.kernel.org/cgit/linux/kernel/git/helgaas/pci.git/commit/?h=pci/msi&id=b3bac8e57c82e8d3e05f4abcb18c4f0a40656655

Quoted 28 lines
---
 drivers/pci/msi.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/msi.c +5 -2
index 18ca2497..9bdf290 100644
@@ -544,9 +544,13 @@ 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;
 
--

To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html