Skip to content

Commit 07c3f92

Browse files
Frank Jungclausmarckleinebudde
authored andcommitted
can: esd_usb: Improve readability on decoding ESD_EV_CAN_ERROR_EXT messages
As suggested by Marc introduce a union plus a struct ev_can_err_ext for easier decoding of an ESD_EV_CAN_ERROR_EXT event message (which simply is a rx_msg with some dedicated data). Suggested-by: Marc Kleine-Budde <[email protected]> Link: https://lore.kernel.org/linux-can/[email protected]/ Signed-off-by: Frank Jungclaus <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 9684b00 commit 07c3f92

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/net/can/usb/esd_usb.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ struct rx_msg {
127127
u8 dlc;
128128
__le32 ts;
129129
__le32 id; /* upper 3 bits contain flags */
130-
u8 data[8];
130+
union {
131+
u8 data[8];
132+
struct {
133+
u8 status; /* CAN Controller Status */
134+
u8 ecc; /* Error Capture Register */
135+
u8 rec; /* RX Error Counter */
136+
u8 tec; /* TX Error Counter */
137+
} ev_can_err_ext; /* For ESD_EV_CAN_ERROR_EXT */
138+
};
131139
};
132140

133141
struct tx_msg {
@@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
229237
u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK;
230238

231239
if (id == ESD_EV_CAN_ERROR_EXT) {
232-
u8 state = msg->msg.rx.data[0];
233-
u8 ecc = msg->msg.rx.data[1];
234-
u8 rxerr = msg->msg.rx.data[2];
235-
u8 txerr = msg->msg.rx.data[3];
240+
u8 state = msg->msg.rx.ev_can_err_ext.status;
241+
u8 ecc = msg->msg.rx.ev_can_err_ext.ecc;
242+
u8 rxerr = msg->msg.rx.ev_can_err_ext.rec;
243+
u8 txerr = msg->msg.rx.ev_can_err_ext.tec;
236244

237245
netdev_dbg(priv->netdev,
238246
"CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n",

0 commit comments

Comments
 (0)