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 <srikanth.thokala@intel.com> Link: https://lore.kernel.org/r/20220531132617.20517-1-subramanian.mohan@intel.com Signed-off-by: Subramanian Mohan <subramanian.mohan@intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Nirmal Patel <nirmal.patel@linux.intel.com>
1 parent f2906aa commit 46d2398

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

  • drivers/pci/controller

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)