Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH] can: kvaser_usb: fix potential crash in probe
@ 2026-09-02 11:06 Anton Olsson
  2026-09-02 11:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Olsson @ 2026-09-02 11:06 UTC (permalink / raw)
  To: linux-can; +Cc: Anton Olsson, Farhad Alemi, Jimmy Assarsson

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


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

end of thread, other threads:[~2026-09-02 11:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02 11:06 [PATCH] can: kvaser_usb: fix potential crash in probe Anton Olsson
2026-09-02 11:26 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox