Commit 46d2398c authored by Subramanian Mohan's avatar Subramanian Mohan Committed by Bjorn Helgaas
Browse files

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: default avatarSrikanth Thokala <srikanth.thokala@intel.com>
Link: https://lore.kernel.org/r/20220531132617.20517-1-subramanian.mohan@intel.com


Signed-off-by: default avatarSubramanian Mohan <subramanian.mohan@intel.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: default avatarNirmal Patel <nirmal.patel@linux.intel.com>
parent f2906aa8
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -898,7 +898,8 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id)
	if (vmd->instance < 0)
	if (vmd->instance < 0)
		return vmd->instance;
		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) {
	if (!vmd->name) {
		err = -ENOMEM;
		err = -ENOMEM;
		goto out_release_instance;
		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:
 out_release_instance:
	ida_simple_remove(&vmd_instance_ida, vmd->instance);
	ida_simple_remove(&vmd_instance_ida, vmd->instance);
	kfree(vmd->name);
	return err;
	return err;
}
}


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


#ifdef CONFIG_PM_SLEEP
#ifdef CONFIG_PM_SLEEP