Skip to content

Commit 46d2398

Browse files
subbu-m37bjorn-helgaas
authored andcommitted
PCI: vmd: Use devm_kasprintf() instead of simple kasprintf()
Use devm_kasprintf() instead of simple kasprintf() to free allocated memory automatically when the device is freed. Suggested-by: Srikanth Thokala <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Subramanian Mohan <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Acked-by: Nirmal Patel <[email protected]>
1 parent f2906aa commit 46d2398

File tree

1 file changed

+2
-3
lines changed
  • drivers/pci/controller

1 file changed

+2
-3
lines changed

drivers/pci/controller/vmd.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,8 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)
898898
if (vmd->instance < 0)
899899
return vmd->instance;
900900

901-
vmd->name = kasprintf(GFP_KERNEL, "vmd%d", vmd->instance);
901+
vmd->name = devm_kasprintf(&dev->dev, GFP_KERNEL, "vmd%d",
902+
vmd->instance);
902903
if (!vmd->name) {
903904
err = -ENOMEM;
904905
goto out_release_instance;
@@ -936,7 +937,6 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)
936937

937938
out_release_instance:
938939
ida_simple_remove(&vmd_instance_ida, vmd->instance);
939-
kfree(vmd->name);
940940
return err;
941941
}
942942

@@ -959,7 +959,6 @@ static void vmd_remove(struct pci_dev *dev)
959959
vmd_detach_resources(vmd);
960960
vmd_remove_irq_domain(vmd);
961961
ida_simple_remove(&vmd_instance_ida, vmd->instance);
962-
kfree(vmd->name);
963962
}
964963

965964
#ifdef CONFIG_PM_SLEEP

0 commit comments

Comments
 (0)