Linux CAN drivers development
 help / color / mirror / Atom feed
From: Anton Olsson <anol@kvaser.com>
To: linux-can@vger.kernel.org
Cc: Anton Olsson <anol@kvaser.com>,
	Farhad Alemi <farhad.alemi@berkeley.edu>,
	Jimmy Assarsson <extja@kvaser.com>
Subject: [PATCH] can: kvaser_usb: fix potential crash in probe
Date: Wed,  2 Sep 2026 13:06:11 +0200	[thread overview]
Message-ID: <20260902110611.2426535-1-anol@kvaser.com> (raw)

The leaf driver does not return any errors when no clock configuration
can be found, and instead it emits a null-check warning. Add default
cases to return an error when no matching clock configuration can be
found.

Signed-off-by: Anton Olsson <anol@kvaser.com>
Reported-by: Farhad Alemi <farhad.alemi@berkeley.edu>
Link: https://lore.kernel.org/linux-can/20260828-sassy-ammonite-of-focus-b2f17c-mkl@pengutronix.de/T/#t
Reviewed-by: Jimmy Assarsson <extja@kvaser.com>
---
 drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index a876c7819b81..2091de2e4f8f 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -747,8 +747,8 @@ static int kvaser_usb_leaf_send_simple_cmd(const struct kvaser_usb *dev,
 	return rc;
 }
 
-static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
-						   const struct leaf_cmd_softinfo *softinfo)
+static int kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
+						  const struct leaf_cmd_softinfo *softinfo)
 {
 	u32 fw_version;
 	u32 sw_options = le32_to_cpu(softinfo->sw_options);
@@ -777,6 +777,8 @@ static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
 		case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK:
 			dev->cfg = &kvaser_usb_leaf_m32c_dev_cfg_32mhz;
 			break;
+		default:
+			return -ENODEV;
 		}
 	} else {
 		switch (sw_options & KVASER_USB_LEAF_SWOPTION_FREQ_MASK) {
@@ -789,8 +791,11 @@ static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
 		case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK:
 			dev->cfg = &kvaser_usb_leaf_imx_dev_cfg_32mhz;
 			break;
+		default:
+			return -ENODEV;
 		}
 	}
+	return 0;
 }
 
 static int kvaser_usb_leaf_get_software_info_inner(struct kvaser_usb *dev)
@@ -809,7 +814,9 @@ static int kvaser_usb_leaf_get_software_info_inner(struct kvaser_usb *dev)
 
 	switch (dev->driver_info->family) {
 	case KVASER_LEAF:
-		kvaser_usb_leaf_get_software_info_leaf(dev, &cmd.u.leaf.softinfo);
+		err = kvaser_usb_leaf_get_software_info_leaf(dev, &cmd.u.leaf.softinfo);
+		if (err)
+			return err;
 		break;
 	case KVASER_USBCAN:
 		fw_version = le32_to_cpu(cmd.u.usbcan.softinfo.fw_version);
-- 
2.43.0


             reply	other threads:[~2026-09-02 11:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 11:06 Anton Olsson [this message]
2026-09-02 11:26 ` [PATCH] can: kvaser_usb: fix potential crash in probe sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260902110611.2426535-1-anol@kvaser.com \
    --to=anol@kvaser.com \
    --cc=extja@kvaser.com \
    --cc=farhad.alemi@berkeley.edu \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox