diff options
author | Jan Beulich <JBeulich@suse.com> | 2014-04-14 16:59:50 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2014-04-14 17:15:34 -0400 |
commit | 1406276c1254d761da7c16b30aa32e3af2b3612a (patch) | |
tree | 656f0d92eade2f9d0c78cf618b4b9031ce48c796 | |
parent | 9ada07b1100a9c7d3107c47673664194574b02a0 (diff) |
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>
-rw-r--r-- | drivers/pci/msi.c | 16 |
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) | |||
544 | if (!msi_attrs) | 544 | if (!msi_attrs) |
545 | return -ENOMEM; | 545 | return -ENOMEM; |
546 | list_for_each_entry(entry, &pdev->msi_list, list) { | 546 | list_for_each_entry(entry, &pdev->msi_list, list) { |
547 | char *name = kmalloc(20, GFP_KERNEL); | ||
548 | if (!name) | ||
549 | goto error_attrs; | ||
550 | |||
551 | msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL); | 547 | msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL); |
552 | if (!msi_dev_attr) { | 548 | if (!msi_dev_attr) |
553 | kfree(name); | ||
554 | goto error_attrs; | 549 | goto error_attrs; |
555 | } | 550 | msi_attrs[count] = &msi_dev_attr->attr; |
556 | 551 | ||
557 | sprintf(name, "%d", entry->irq); | ||
558 | sysfs_attr_init(&msi_dev_attr->attr); | 552 | sysfs_attr_init(&msi_dev_attr->attr); |
559 | msi_dev_attr->attr.name = name; | 553 | msi_dev_attr->attr.name = kasprintf(GFP_KERNEL, "%d", |
554 | entry->irq); | ||
555 | if (!msi_dev_attr->attr.name) | ||
556 | goto error_attrs; | ||
560 | msi_dev_attr->attr.mode = S_IRUGO; | 557 | msi_dev_attr->attr.mode = S_IRUGO; |
561 | msi_dev_attr->show = msi_mode_show; | 558 | msi_dev_attr->show = msi_mode_show; |
562 | msi_attrs[count] = &msi_dev_attr->attr; | ||
563 | ++count; | 559 | ++count; |
564 | } | 560 | } |
565 | 561 | ||