PCI: vmd: Use devm_kasprintf instead of simple kasprintf
Subsystems (3)
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
@@ -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
Quoted 4 lines · On Tue, May 31, 2022 at 06:56:17PM +0530, [email protected] wrote:
From: Subramanian Mohan <[email protected]>
Use
devm_kasprintfinstead 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
Suggested-by Srikanth Thokala <[email protected]>Signed-off-by Subramanian Mohan <[email protected]>Acked-by Nirmal Patel <[email protected]>--- drivers/pci/controller/vmd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/pci/controller/vmd.c +2
-3@@ -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
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: Usedevm_kasprintfinstead of simple kasprintfOn 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_kasprintfinstead 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
Suggested-by Srikanth Thokala <[email protected]>Signed-off-by Subramanian Mohan <[email protected]>Acked-by Nirmal Patel <[email protected]>--- drivers/pci/controller/vmd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/pci/controller/vmd.cindexeb05cceab964..7a72948e001f100644drivers/pci/controller/vmd.c +0
-0@@ -897,7 +897,8 @@ static int vmd_probe(struct pci_dev *dev, conststruct
pci_device_id*id)Quoted 29 lines
drivers/pci/controller/vmd.c +2
-4if (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
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: Usedevm_kasprintfinstead of simple kasprintfQuoted 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: Usedevm_kasprintfinstead of simple kasprintfQuoted 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_kasprintfinstead 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,
SubbuQuoted 43 lines
drivers/pci/controller/vmd.c static int vmd_probe(struct pci_dev *dev, const
Quoted 13 lines
Suggested-by Srikanth Thokala <[email protected]>Signed-off-by Subramanian Mohan <[email protected]>Acked-by Nirmal Patel <[email protected]>--- drivers/pci/controller/vmd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/pci/controller/vmd.cindexeb05cceab964..7a72948e001f100644drivers/pci/controller/vmd.c +0
-0@@ -897,7 +897,8 @@ static int vmd_probe(struct pci_dev *dev, conststruct
pci_device_id*id)Quoted 29 lines
drivers/pci/controller/vmd.c +2
-4if (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
Bjorn Helgaas
AppliedQuoted 8 lines · On Tue, May 31, 2022 at 06:56:17PM +0530, [email protected] wrote:
From: Subramanian Mohan <[email protected]>
Use
devm_kasprintfinstead of simple kasprintf to free the allocated memory automatically when the device is freed.Suggested-by Srikanth Thokala <[email protected]>Signed-off-by Subramanian Mohan <[email protected]>Acked-by Nirmal Patel <[email protected]>
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@@ -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
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: Usedevm_kasprintfinstead of simple kasprintfQuoted 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_kasprintfinstead of simple kasprintf to free the allocated memory automatically when the device is freed.Suggested-by Srikanth Thokala <[email protected]>Signed-off-by Subramanian Mohan <[email protected]>Acked-by Nirmal Patel <[email protected]>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.cindexeb05cceab964..7a72948e001f100644drivers/pci/controller/vmd.c +0
-0@@ -897,7 +897,8 @@ static int vmd_probe(struct pci_dev *dev, conststruct
pci_device_id*id)Quoted 29 lines
drivers/pci/controller/vmd.c +2
-4if (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