diff mbox series

arcnet: com20020-pci:Check devm_kasprintf() returned value

Message ID 20240828061941.8173-1-hanchunchao@inspur.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series arcnet: com20020-pci:Check devm_kasprintf() returned value | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 17 this patch: 17
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns WARNING: line length of 88 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-08-28--12-00 (tests: 712)

Commit Message

Charles Han Aug. 28, 2024, 6:19 a.m. UTC
devm_kasprintf() can return a NULL pointer on failure but this returned
value is not checked.

Fix this lack and check the returned value.

Fixes: 8890624a4e8c ("arcnet: com20020-pci: add led trigger support")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/net/arcnet/com20020-pci.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Simon Horman Aug. 28, 2024, 3:07 p.m. UTC | #1
On Wed, Aug 28, 2024 at 02:19:41PM +0800, Charles Han wrote:
> devm_kasprintf() can return a NULL pointer on failure but this returned
> value is not checked.
> 
> Fix this lack and check the returned value.
> 
> Fixes: 8890624a4e8c ("arcnet: com20020-pci: add led trigger support")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>

nit: I think there should be a space after each ':' in the subject.
     Also, IMHO, return value is a bit more natural.

Subject: [PATCH] arcnet: com20020-pci: Check devm_kasprintf() return value

> ---
>  drivers/net/arcnet/com20020-pci.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c
> index c5e571ec94c9..ca393f9658e9 100644
> --- a/drivers/net/arcnet/com20020-pci.c
> +++ b/drivers/net/arcnet/com20020-pci.c
> @@ -254,6 +254,10 @@ 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) {
> +				ret = -ENOMEM;
> +				goto err_free_arcdev;
> +			}

I'd prefer if the error values were checked one by one.

			card->tx_led.default_trigger = ...
			if (!card->tx_led.default_trigger) {
				...
			}

			card->tx_led.name = ...
			if (!card->tx_led.default_trigger) {
				...
			}

>  
>  			card->tx_led.dev = &dev->dev;
>  			card->recon_led.brightness_set = led_recon_set;
> @@ -263,6 +267,11 @@ 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) {

Ditto.

> +				ret = -ENOMEM;
> +				goto err_free_arcdev;
> +			}
> +
>  			card->recon_led.dev = &dev->dev;
>  
>  			ret = devm_led_classdev_register(&pdev->dev, &card->tx_led);
diff mbox series

Patch

diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c
index c5e571ec94c9..ca393f9658e9 100644
--- a/drivers/net/arcnet/com20020-pci.c
+++ b/drivers/net/arcnet/com20020-pci.c
@@ -254,6 +254,10 @@  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) {
+				ret = -ENOMEM;
+				goto err_free_arcdev;
+			}
 
 			card->tx_led.dev = &dev->dev;
 			card->recon_led.brightness_set = led_recon_set;
@@ -263,6 +267,11 @@  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) {
+				ret = -ENOMEM;
+				goto err_free_arcdev;
+			}
+
 			card->recon_led.dev = &dev->dev;
 
 			ret = devm_led_classdev_register(&pdev->dev, &card->tx_led);