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>
This commit is contained in:
parent
9ada07b110
commit
1406276c12
1 changed files with 6 additions and 10 deletions
|
@ -544,22 +544,18 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
|
||||||
if (!msi_attrs)
|
if (!msi_attrs)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
list_for_each_entry(entry, &pdev->msi_list, list) {
|
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);
|
msi_dev_attr = kzalloc(sizeof(*msi_dev_attr), GFP_KERNEL);
|
||||||
if (!msi_dev_attr) {
|
if (!msi_dev_attr)
|
||||||
kfree(name);
|
|
||||||
goto error_attrs;
|
goto error_attrs;
|
||||||
}
|
msi_attrs[count] = &msi_dev_attr->attr;
|
||||||
|
|
||||||
sprintf(name, "%d", entry->irq);
|
|
||||||
sysfs_attr_init(&msi_dev_attr->attr);
|
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->attr.mode = S_IRUGO;
|
||||||
msi_dev_attr->show = msi_mode_show;
|
msi_dev_attr->show = msi_mode_show;
|
||||||
msi_attrs[count] = &msi_dev_attr->attr;
|
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue