Commit 7a8cd7c0 authored by Vincent Mailhol's avatar Vincent Mailhol Committed by Marc Kleine-Budde

can: etas_es58x: es58x_fd_rx_event_msg(): initialize rx_event_msg before...

can: etas_es58x: es58x_fd_rx_event_msg(): initialize rx_event_msg before calling es58x_check_msg_len()

Function es58x_fd_rx_event() invokes the es58x_check_msg_len() macro:

| 	ret = es58x_check_msg_len(es58x_dev->dev, *rx_event_msg, msg_len);

While doing so, it dereferences an uninitialized
variable: *rx_event_msg.

This is actually harmless because es58x_check_msg_len() only uses
preprocessor macros (sizeof() and __stringify()) on
*rx_event_msg. c.f. [1].

Nonetheless, this pattern is confusing so the lines are reordered to
make sure that rx_event_msg is correctly initialized.

This patch also fixes a false positive warning reported by cppcheck:

| cppcheck possible warnings: (new ones prefixed by >>, may not be real problems)
|
|    In file included from drivers/net/can/usb/etas_es58x/es58x_fd.c:
| >> drivers/net/can/usb/etas_es58x/es58x_fd.c:174:8: warning: Uninitialized variable: rx_event_msg [uninitvar]
|     ret = es58x_check_msg_len(es58x_dev->dev, *rx_event_msg, msg_len);
|           ^

[1] https://elixir.bootlin.com/linux/v5.16/source/drivers/net/can/usb/etas_es58x/es58x_core.h#L467

Link: https://lore.kernel.org/all/20220306101302.708783-1-mailhol.vincent@wanadoo.frSigned-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 259bdba2
...@@ -173,12 +173,11 @@ static int es58x_fd_rx_event_msg(struct net_device *netdev, ...@@ -173,12 +173,11 @@ static int es58x_fd_rx_event_msg(struct net_device *netdev,
const struct es58x_fd_rx_event_msg *rx_event_msg; const struct es58x_fd_rx_event_msg *rx_event_msg;
int ret; int ret;
rx_event_msg = &es58x_fd_urb_cmd->rx_event_msg;
ret = es58x_check_msg_len(es58x_dev->dev, *rx_event_msg, msg_len); ret = es58x_check_msg_len(es58x_dev->dev, *rx_event_msg, msg_len);
if (ret) if (ret)
return ret; return ret;
rx_event_msg = &es58x_fd_urb_cmd->rx_event_msg;
return es58x_rx_err_msg(netdev, rx_event_msg->error_code, return es58x_rx_err_msg(netdev, rx_event_msg->error_code,
rx_event_msg->event_code, rx_event_msg->event_code,
get_unaligned_le64(&rx_event_msg->timestamp)); get_unaligned_le64(&rx_event_msg->timestamp));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment