* [PATCH] arcnet: com20020-pci: Add check devm_kasprintf() returned value
@ 2024-09-29 2:37 Charles Han
2024-09-30 15:21 ` Simon Horman
0 siblings, 1 reply; 2+ messages in thread
From: Charles Han @ 2024-09-29 2:37 UTC (permalink / raw)
To: m.grzeschik, davem
Cc: edumazet, kuba, pabeni, netdev, linux-kernel, Charles Han
devm_kasprintf() can return a NULL pointer on failure but this
returned value in com20020pci_probe() is not checked.
Fixes: 8890624a4e8c ("arcnet: com20020-pci: add led trigger support")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
drivers/net/arcnet/com20020-pci.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c
index c5e571ec94c9..6639ee11a7f8 100644
--- a/drivers/net/arcnet/com20020-pci.c
+++ b/drivers/net/arcnet/com20020-pci.c
@@ -254,6 +254,8 @@ static int com20020pci_probe(struct pci_dev *pdev,
card->tx_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
"pci:green:tx:%d-%d",
dev->dev_id, i);
+ if (!card->tx_led.default_trigger || !card->tx_led.name)
+ return -ENOMEM;
card->tx_led.dev = &dev->dev;
card->recon_led.brightness_set = led_recon_set;
@@ -263,6 +265,9 @@ static int com20020pci_probe(struct pci_dev *pdev,
card->recon_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
"pci:red:recon:%d-%d",
dev->dev_id, i);
+ if (!card->recon_led.default_trigger || !card->recon_led.name)
+ return -ENOMEM;
+
card->recon_led.dev = &dev->dev;
ret = devm_led_classdev_register(&pdev->dev, &card->tx_led);
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] arcnet: com20020-pci: Add check devm_kasprintf() returned value
2024-09-29 2:37 [PATCH] arcnet: com20020-pci: Add check devm_kasprintf() returned value Charles Han
@ 2024-09-30 15:21 ` Simon Horman
0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2024-09-30 15:21 UTC (permalink / raw)
To: Charles Han
Cc: m.grzeschik, davem, edumazet, kuba, pabeni, netdev, linux-kernel
On Sun, Sep 29, 2024 at 10:37:21AM +0800, Charles Han wrote:
> devm_kasprintf() can return a NULL pointer on failure but this
> returned value in com20020pci_probe() is not checked.
>
> Fixes: 8890624a4e8c ("arcnet: com20020-pci: add led trigger support")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
Hi Charles,
As a fix for Networking code this looks like it should be targeted
at the 'net' tree. Please do that by using 'net' in the subject like this:
Subject: [PATCH net v2] ...
Link: https://docs.kernel.org/process/maintainer-netdev.html
> ---
> drivers/net/arcnet/com20020-pci.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c
> index c5e571ec94c9..6639ee11a7f8 100644
> --- a/drivers/net/arcnet/com20020-pci.c
> +++ b/drivers/net/arcnet/com20020-pci.c
> @@ -254,6 +254,8 @@ static int com20020pci_probe(struct pci_dev *pdev,
> card->tx_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
> "pci:green:tx:%d-%d",
> dev->dev_id, i);
> + if (!card->tx_led.default_trigger || !card->tx_led.name)
> + return -ENOMEM;
Looking at the rest of this function, I think the
correct unwind procedure is as follows (completely untested!):
if (!card->tx_led.default_trigger ||
!card->tx_led.name) {
ret = -ENOMEM;
goto err_free_arcdev;
}
>
> card->tx_led.dev = &dev->dev;
> card->recon_led.brightness_set = led_recon_set;
> @@ -263,6 +265,9 @@ static int com20020pci_probe(struct pci_dev *pdev,
> card->recon_led.name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
> "pci:red:recon:%d-%d",
> dev->dev_id, i);
> + if (!card->recon_led.default_trigger || !card->recon_led.name)
Please line-wrap the line above so that it is <= 80 columns wide,
as is still preferred by Networking code. Checkpatch will flag
this when used with the --max-line-length=80 command line option.
> + return -ENOMEM;
> +
> card->recon_led.dev = &dev->dev;
>
> ret = devm_led_classdev_register(&pdev->dev, &card->tx_led);
--
pw-bot: changes-requested
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-30 15:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-29 2:37 [PATCH] arcnet: com20020-pci: Add check devm_kasprintf() returned value Charles Han
2024-09-30 15:21 ` Simon Horman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).