diff mbox series

[v1] arcnet: Add NULL check in com20020pci_probe()

Message ID 20250401134903.28462-1-bsdhenrymartin@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v1] arcnet: Add NULL check in com20020pci_probe() | 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: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 1 blamed authors not CCed: thomas.reichinger@sohard.de; 1 maintainers not CCed: thomas.reichinger@sohard.de
netdev/build_clang success Errors and warnings before: 0 this patch: 0
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: 1 this patch: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 13 lines checked
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

Commit Message

Henry Martin April 1, 2025, 1:49 p.m. UTC
devm_kasprintf() returns NULL when memory allocation fails. Currently,
com20020pci_probe() does not check for this case, which results in a
NULL pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes: 6b17a597fc2f ("arcnet: restoring support for multiple Sohard Arcnet cards")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 drivers/net/arcnet/com20020-pci.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Andrew Lunn April 1, 2025, 2:36 p.m. UTC | #1
On Tue, Apr 01, 2025 at 09:49:03PM +0800, Henry Martin wrote:
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> com20020pci_probe() does not check for this case, which results in a
> NULL pointer dereference.
> 
> Add NULL check after devm_kasprintf() to prevent this issue.

It is more normal to add a test after each devm_kasprintf() rather
than one big one at the end. If the first fails, all the others are
going to fail as well, so you should not bother and just fail the
probe.

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

    Andrew

---
pw-bot: cr
diff mbox series

Patch

diff --git a/drivers/net/arcnet/com20020-pci.c b/drivers/net/arcnet/com20020-pci.c
index c5e571ec94c9..65c6fab0e359 100644
--- a/drivers/net/arcnet/com20020-pci.c
+++ b/drivers/net/arcnet/com20020-pci.c
@@ -264,6 +264,13 @@  static int com20020pci_probe(struct pci_dev *pdev,
 							"pci:red:recon:%d-%d",
 							dev->dev_id, i);
 			card->recon_led.dev = &dev->dev;
+			if (!card->tx_led.default_trigger ||
+			    !card->tx_led.name ||
+			    !card->recon_led.default_trigger ||
+			    !card->recon_led.name) {
+				ret = -ENOMEM;
+				goto err_free_arcdev;
+			}
 
 			ret = devm_led_classdev_register(&pdev->dev, &card->tx_led);
 			if (ret)