All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: kirin: Use devm_kasprintf()
@ 2023-11-12  7:37 Christophe JAILLET
  2023-11-13  9:30 ` Serge Semin
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christophe JAILLET @ 2023-11-12  7:37 UTC (permalink / raw)
  To: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-pci

Use devm_kasprintf() instead of hand writing it.
This saves the need of an intermediate buffer.

There was also no reason to use the _const() version of devm_kstrdup().
The string was known be not constant.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/pci/controller/dwc/pcie-kirin.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
index 2ee146767971..d9e3514de0a0 100644
--- a/drivers/pci/controller/dwc/pcie-kirin.c
+++ b/drivers/pci/controller/dwc/pcie-kirin.c
@@ -366,7 +366,6 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
 				      struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	char name[32];
 	int ret, i;
 
 	/* This is an optional property */
@@ -387,9 +386,8 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
 		if (pcie->gpio_id_clkreq[i] < 0)
 			return pcie->gpio_id_clkreq[i];
 
-		sprintf(name, "pcie_clkreq_%d", i);
-		pcie->clkreq_names[i] = devm_kstrdup_const(dev, name,
-							    GFP_KERNEL);
+		pcie->clkreq_names[i] = devm_kasprintf(dev, GFP_KERNEL,
+						       "pcie_clkreq_%d", i);
 		if (!pcie->clkreq_names[i])
 			return -ENOMEM;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] PCI: kirin: Use devm_kasprintf()
  2023-11-12  7:37 [PATCH] PCI: kirin: Use devm_kasprintf() Christophe JAILLET
@ 2023-11-13  9:30 ` Serge Semin
  2023-11-13  9:55 ` Krzysztof Wilczyński
  2023-11-14 13:06 ` Ilpo Järvinen
  2 siblings, 0 replies; 5+ messages in thread
From: Serge Semin @ 2023-11-13  9:30 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas,
	linux-kernel, kernel-janitors, linux-pci

On Sun, Nov 12, 2023 at 08:37:01AM +0100, Christophe JAILLET wrote:
> Use devm_kasprintf() instead of hand writing it.
> This saves the need of an intermediate buffer.
> 
> There was also no reason to use the _const() version of devm_kstrdup().
> The string was known be not constant.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Neat cleanup. Thanks!
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>

-Serge(y)

> ---
>  drivers/pci/controller/dwc/pcie-kirin.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
> index 2ee146767971..d9e3514de0a0 100644
> --- a/drivers/pci/controller/dwc/pcie-kirin.c
> +++ b/drivers/pci/controller/dwc/pcie-kirin.c
> @@ -366,7 +366,6 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
>  				      struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	char name[32];
>  	int ret, i;
>  
>  	/* This is an optional property */
> @@ -387,9 +386,8 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
>  		if (pcie->gpio_id_clkreq[i] < 0)
>  			return pcie->gpio_id_clkreq[i];
>  
> -		sprintf(name, "pcie_clkreq_%d", i);
> -		pcie->clkreq_names[i] = devm_kstrdup_const(dev, name,
> -							    GFP_KERNEL);
> +		pcie->clkreq_names[i] = devm_kasprintf(dev, GFP_KERNEL,
> +						       "pcie_clkreq_%d", i);
>  		if (!pcie->clkreq_names[i])
>  			return -ENOMEM;
>  	}
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] PCI: kirin: Use devm_kasprintf()
  2023-11-12  7:37 [PATCH] PCI: kirin: Use devm_kasprintf() Christophe JAILLET
  2023-11-13  9:30 ` Serge Semin
@ 2023-11-13  9:55 ` Krzysztof Wilczyński
  2023-11-13 19:13   ` Christophe JAILLET
  2023-11-14 13:06 ` Ilpo Järvinen
  2 siblings, 1 reply; 5+ messages in thread
From: Krzysztof Wilczyński @ 2023-11-13  9:55 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi, Rob Herring,
	Bjorn Helgaas, linux-kernel, kernel-janitors, linux-pci

Hello!

[...]
> @@ -387,9 +386,8 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
>  		if (pcie->gpio_id_clkreq[i] < 0)
>  			return pcie->gpio_id_clkreq[i];
>  
> -		sprintf(name, "pcie_clkreq_%d", i);
> -		pcie->clkreq_names[i] = devm_kstrdup_const(dev, name,
> -							    GFP_KERNEL);
> +		pcie->clkreq_names[i] = devm_kasprintf(dev, GFP_KERNEL,
> +						       "pcie_clkreq_%d", i);

I think, the kirin_pcie_parse_port(), which is just below form this
function, might benefit from the same type of a nice change.  Thoughts?

	Krzysztof

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] PCI: kirin: Use devm_kasprintf()
  2023-11-13  9:55 ` Krzysztof Wilczyński
@ 2023-11-13 19:13   ` Christophe JAILLET
  0 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2023-11-13 19:13 UTC (permalink / raw)
  To: Krzysztof Wilczyński
  Cc: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi, Rob Herring,
	Bjorn Helgaas, linux-kernel, kernel-janitors, linux-pci,
	Serge Semin

Le 13/11/2023 à 10:55, Krzysztof Wilczyński a écrit :
> Hello!
> 
> [...]
>> @@ -387,9 +386,8 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
>>   		if (pcie->gpio_id_clkreq[i] < 0)
>>   			return pcie->gpio_id_clkreq[i];
>>   
>> -		sprintf(name, "pcie_clkreq_%d", i);
>> -		pcie->clkreq_names[i] = devm_kstrdup_const(dev, name,
>> -							    GFP_KERNEL);
>> +		pcie->clkreq_names[i] = devm_kasprintf(dev, GFP_KERNEL,
>> +						       "pcie_clkreq_%d", i);
> 
> I think, the kirin_pcie_parse_port(), which is just below form this
> function, might benefit from the same type of a nice change.  Thoughts?
> 
> 	Krzysztof
> 

Argh, yes, I've not seen it.

I'll send a v2 with both.
Thx for seeing it.

CJ

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] PCI: kirin: Use devm_kasprintf()
  2023-11-12  7:37 [PATCH] PCI: kirin: Use devm_kasprintf() Christophe JAILLET
  2023-11-13  9:30 ` Serge Semin
  2023-11-13  9:55 ` Krzysztof Wilczyński
@ 2023-11-14 13:06 ` Ilpo Järvinen
  2 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2023-11-14 13:06 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Xiaowei Song, Binghui Wang, Lorenzo Pieralisi,
	Krzysztof Wilczyński, Rob Herring, Bjorn Helgaas, LKML,
	kernel-janitors, linux-pci

[-- Attachment #1: Type: text/plain, Size: 1506 bytes --]

On Sun, 12 Nov 2023, Christophe JAILLET wrote:

> Use devm_kasprintf() instead of hand writing it.
> This saves the need of an intermediate buffer.
> 
> There was also no reason to use the _const() version of devm_kstrdup().
> The string was known be not constant.

was known be -> is known to be

With that fixed, 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.


> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/pci/controller/dwc/pcie-kirin.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-kirin.c b/drivers/pci/controller/dwc/pcie-kirin.c
> index 2ee146767971..d9e3514de0a0 100644
> --- a/drivers/pci/controller/dwc/pcie-kirin.c
> +++ b/drivers/pci/controller/dwc/pcie-kirin.c
> @@ -366,7 +366,6 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
>  				      struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> -	char name[32];
>  	int ret, i;
>  
>  	/* This is an optional property */
> @@ -387,9 +386,8 @@ static int kirin_pcie_get_gpio_enable(struct kirin_pcie *pcie,
>  		if (pcie->gpio_id_clkreq[i] < 0)
>  			return pcie->gpio_id_clkreq[i];
>  
> -		sprintf(name, "pcie_clkreq_%d", i);
> -		pcie->clkreq_names[i] = devm_kstrdup_const(dev, name,
> -							    GFP_KERNEL);
> +		pcie->clkreq_names[i] = devm_kasprintf(dev, GFP_KERNEL,
> +						       "pcie_clkreq_%d", i);
>  		if (!pcie->clkreq_names[i])
>  			return -ENOMEM;
>  	}
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-14 13:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-12  7:37 [PATCH] PCI: kirin: Use devm_kasprintf() Christophe JAILLET
2023-11-13  9:30 ` Serge Semin
2023-11-13  9:55 ` Krzysztof Wilczyński
2023-11-13 19:13   ` Christophe JAILLET
2023-11-14 13:06 ` Ilpo Järvinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.