summaryrefslogtreecommitdiffstats
path: root/drivers/pci/msi.c
diff options
context:
space:
mode:
authorJan Beulich <JBeulich@suse.com>2014-04-14 14:59:50 -0600
committerBjorn Helgaas <bhelgaas@google.com>2014-04-14 15:15:34 -0600
commit1406276c1254d761da7c16b30aa32e3af2b3612a (patch)
tree656f0d92eade2f9d0c78cf618b4b9031ce48c796 /drivers/pci/msi.c
parent9ada07b1100a9c7d3107c47673664194574b02a0 (diff)
downloadlinux-1406276c1254d761da7c16b30aa32e3af2b3612a.tar.bz2
PCI/MSI: Simplify populate_msi_sysfs()
Simplify populate_msi_sysfs() by - Swapping the order of the two allocations and storing the msi_dev_attr-derived pointer right after allocation, allowing the cleanup code to pick things up without extra effort. - Using kasprintf() instead of the kmalloc()/sprintf() pair. Signed-off-by: Jan Beulich <jbeulich@suse.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/pci/msi.c')
-rw-r--r--drivers/pci/msi.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 955ab7990c5b..04130c3f9cf6 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -544,22 +544,18 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
if (!msi_attrs)
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) {
- kfree(name);
+ if (!msi_dev_attr)
goto error_attrs;
- }
+ msi_attrs[count] = &msi_dev_attr->attr;
- sprintf(name, "%d", entry->irq);
sysfs_attr_init(&msi_dev_attr->attr);
- msi_dev_attr->attr.name = name;
+ msi_dev_attr->attr.name = kasprintf(GFP_KERNEL, "%d",
+ entry->irq);
+ if (!msi_dev_attr->attr.name)
+ goto error_attrs;
msi_dev_attr->attr.mode = S_IRUGO;
msi_dev_attr->show = msi_mode_show;
- msi_attrs[count] = &msi_dev_attr->attr;
++count;
}