PCI: vmd: Use devm_kasprintf() instead of simple kasprintf()
authorSubramanian Mohan <subramanian.mohan@intel.com>
Tue, 31 May 2022 13:26:17 +0000 (18:56 +0530)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 10 Jun 2022 14:46:14 +0000 (09:46 -0500)
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>
drivers/pci/controller/vmd.c

index 94a14a3d7e55525deb956861ac279009bb67a49e..cecb55264fb9f884e52061800c0fdca8fb940a4f 100644 (file)
@@ -898,7 +898,8 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)
        if (vmd->instance < 0)
                return vmd->instance;
 
-       vmd->name = kasprintf(GFP_KERNEL, "vmd%d", vmd->instance);
+       vmd->name = devm_kasprintf(&dev->dev, GFP_KERNEL, "vmd%d",
+                                  vmd->instance);
        if (!vmd->name) {
                err = -ENOMEM;
                goto out_release_instance;
@@ -936,7 +937,6 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)
 
  out_release_instance:
        ida_simple_remove(&vmd_instance_ida, vmd->instance);
-       kfree(vmd->name);
        return err;
 }
 
@@ -959,7 +959,6 @@ static void vmd_remove(struct pci_dev *dev)
        vmd_detach_resources(vmd);
        vmd_remove_irq_domain(vmd);
        ida_simple_remove(&vmd_instance_ida, vmd->instance);
-       kfree(vmd->name);
 }
 
 #ifdef CONFIG_PM_SLEEP