Skip to contentSkip to conversation

PCI: vmd: Use devm_kasprintf instead of simple kasprintf

PATCH Applied [email protected] 2 participants 6 messages May 31, 2022 – Jun 13, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: vmd: Use devm_kasprintf instead of simple kasprintf

From: Subramanian Mohan <[email protected]>

Use devm_kasprintf instead of simple kasprintf to free the allocated memory automatically when the device is freed.

---
 drivers/pci/controller/vmd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/controller/vmd.c +2 -3
index eb05cceab964..7a72948e001f 100644
@@ -897,7 +897,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;
@@ -935,7 +936,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;
 }
 
@@ -958,7 +958,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
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · On Tue, May 31, 2022 at 06:56:17PM +0530, [email protected] wrote:

From: Subramanian Mohan <[email protected]>

Use devm_kasprintf instead of simple kasprintf to free the allocated memory automatically when the device is freed.

I guess this is pure simplification, not a bug fix, since we *did* free the buffer in the error path and in vmd_remove(), right?

Quoted 40 lines
---
 drivers/pci/controller/vmd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/controller/vmd.c +2 -3
index eb05cceab964..7a72948e001f 100644
@@ -897,7 +897,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;
@@ -935,7 +936,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;
 }
 
@@ -958,7 +958,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
Signature · 1 line
2.17.1
#2 lore raw
Quoted 17 lines

-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Wednesday, June 1, 2022 12:09 AM
To: Mohan, Subramanian <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Sangannavar, Mallikarjunappa <[email protected]>; Thokala, Srikanth <[email protected]>
Subject: Re: [PATCH] PCI: vmd: Use devm_kasprintf instead of simple kasprintf

On Tue, May 31, 2022 at 06:56:17PM +0530, [email protected] wrote:

Quoted 8 lines
Quoted 4 lines

From: Subramanian Mohan <[email protected]>

Use devm_kasprintf instead of simple kasprintf to free the allocated memory automatically when the device is freed.

I guess this is pure simplification, not a bug fix, since we *did* free the buffer in the error path and in vmd_remove(), right?

Yes this is simplification and not bug fix.

Thanks,
Subbu

Quoted 42 lines

drivers/pci/controller/vmd.c static int vmd_probe(struct pci_dev *dev, const

Quoted 12 lines
---
 drivers/pci/controller/vmd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/pci/controller/vmd.c index eb05cceab964..7a72948e001f 100644

drivers/pci/controller/vmd.c +0 -0
@@ -897,7 +897,8 @@ static int vmd_probe(struct pci_dev *dev, const

struct pci_device_id *id)

Quoted 29 lines
drivers/pci/controller/vmd.c +2 -4
 	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;
@@ -935,7 +936,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;
 }
@@ -958,7 +958,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
--

2.17.1

#3 lore raw

Hi Bjorn,

Quoted 31 lines

-----Original Message-----
From: Mohan, Subramanian
Sent: Wednesday, June 1, 2022 4:45 PM
To: Bjorn Helgaas <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Sangannavar, Mallikarjunappa <[email protected]>; Thokala, Srikanth <[email protected]>
Subject: RE: [PATCH] PCI: vmd: Use devm_kasprintf instead of simple kasprintf

Quoted 17 lines

-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Wednesday, June 1, 2022 12:09 AM
To: Mohan, Subramanian <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Sangannavar, Mallikarjunappa <[email protected]>; Thokala, Srikanth <[email protected]>
Subject: Re: [PATCH] PCI: vmd: Use devm_kasprintf instead of simple kasprintf

Quoted 2 lines · On Tue, May 31, 2022 at 06:56:17PM +0530, [email protected] wrote:

From: Subramanian Mohan <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Use devm_kasprintf instead of simple kasprintf to free the allocated memory automatically when the device is freed.

I guess this is pure simplification, not a bug fix, since we *did* free the buffer in the error path and in vmd_remove(), right?

Yes this is simplification and not bug fix.

Gentle reminder, kindly let me know any further comments.

Quoted 47 lines

Thanks,
Subbu

Quoted 43 lines

drivers/pci/controller/vmd.c static int vmd_probe(struct pci_dev *dev, const

Quoted 13 lines
---
 drivers/pci/controller/vmd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/pci/controller/vmd.c index eb05cceab964..7a72948e001f 100644

drivers/pci/controller/vmd.c +0 -0
@@ -897,7 +897,8 @@ static int vmd_probe(struct pci_dev *dev, const

struct pci_device_id *id)

Quoted 29 lines
drivers/pci/controller/vmd.c +2 -4
 	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;
@@ -935,7 +936,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;
 }
@@ -958,7 +958,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
--

2.17.1

#4 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, May 31, 2022 at 06:56:17PM +0530, [email protected] wrote:

From: Subramanian Mohan <[email protected]>

Use devm_kasprintf instead of simple kasprintf to free the allocated memory automatically when the device is freed.

Applied to pci/ctrl/vmd for v5.20, thanks!

Quoted 37 lines
---
 drivers/pci/controller/vmd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/pci/controller/vmd.c +2 -3
index eb05cceab964..7a72948e001f 100644
@@ -897,7 +897,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;
@@ -935,7 +936,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;
 }
 
@@ -958,7 +958,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
Signature · 1 line
2.17.1
#5 lore raw

Hi Bjorn,

Quoted 17 lines

-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: Friday, June 10, 2022 8:17 PM
To: Mohan, Subramanian <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Sangannavar, Mallikarjunappa <[email protected]>; Thokala, Srikanth <[email protected]>
Subject: Re: [PATCH] PCI: vmd: Use devm_kasprintf instead of simple kasprintf

Quoted 2 lines · On Tue, May 31, 2022 at 06:56:17PM +0530, [email protected] wrote:

From: Subramanian Mohan <[email protected]>

Quoted 8 lines
Quoted 6 lines

Use devm_kasprintf instead of simple kasprintf to free the allocated memory automatically when the device is freed.

Applied to pci/ctrl/vmd for v5.20, thanks!

Thanks !

Quoted 40 lines

drivers/pci/controller/vmd.c static int vmd_probe(struct pci_dev *dev, const

Quoted 10 lines
---
 drivers/pci/controller/vmd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/pci/controller/vmd.c index eb05cceab964..7a72948e001f 100644

drivers/pci/controller/vmd.c +0 -0
@@ -897,7 +897,8 @@ static int vmd_probe(struct pci_dev *dev, const

struct pci_device_id *id)

Quoted 29 lines
drivers/pci/controller/vmd.c +2 -4
 	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;
@@ -935,7 +936,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;
 }
@@ -958,7 +958,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
--

2.17.1