Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

can: dev: add can_get_ctrlmode_str()

In an effort to give more human readable messages when errors occur
because of conflicting options, it can be useful to convert the CAN
control mode flags into text.

Add a function which converts the first set CAN control mode into a
human readable string. The reason to only convert the first one is to
simplify edge cases: imagine that there are several invalid control
modes, we would just return the first invalid one to the user, thus
not having to handle complex string concatenation. The user can then
solve the first problem, call the netlink interface again and see the
next issue.

People who wish to enumerate all the control modes can still do so by,
for example, using this new function in a for_each_set_bit() loop.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250923-canxl-netlink-prep-v4-19-e720d28f66fe@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
7de54546 6ffc1230

+35
+33
drivers/net/can/dev/dev.c
··· 88 88 } 89 89 EXPORT_SYMBOL_GPL(can_get_state_str); 90 90 91 + const char *can_get_ctrlmode_str(u32 ctrlmode) 92 + { 93 + switch (ctrlmode & ~(ctrlmode - 1)) { 94 + case 0: 95 + return "none"; 96 + case CAN_CTRLMODE_LOOPBACK: 97 + return "loopback"; 98 + case CAN_CTRLMODE_LISTENONLY: 99 + return "listen-only"; 100 + case CAN_CTRLMODE_3_SAMPLES: 101 + return "triple-sampling"; 102 + case CAN_CTRLMODE_ONE_SHOT: 103 + return "one-shot"; 104 + case CAN_CTRLMODE_BERR_REPORTING: 105 + return "berr-reporting"; 106 + case CAN_CTRLMODE_FD: 107 + return "fd"; 108 + case CAN_CTRLMODE_PRESUME_ACK: 109 + return "presume-ack"; 110 + case CAN_CTRLMODE_FD_NON_ISO: 111 + return "fd-non-iso"; 112 + case CAN_CTRLMODE_CC_LEN8_DLC: 113 + return "cc-len8-dlc"; 114 + case CAN_CTRLMODE_TDC_AUTO: 115 + return "fd-tdc-auto"; 116 + case CAN_CTRLMODE_TDC_MANUAL: 117 + return "fd-tdc-manual"; 118 + default: 119 + return "<unknown>"; 120 + } 121 + } 122 + EXPORT_SYMBOL_GPL(can_get_ctrlmode_str); 123 + 91 124 static enum can_state can_state_err_to_state(u16 err) 92 125 { 93 126 if (err < CAN_ERROR_WARNING_THRESHOLD)
+2
include/linux/can/dev.h
··· 141 141 void can_bus_off(struct net_device *dev); 142 142 143 143 const char *can_get_state_str(const enum can_state state); 144 + const char *can_get_ctrlmode_str(u32 ctrlmode); 145 + 144 146 void can_state_get_by_berr_counter(const struct net_device *dev, 145 147 const struct can_berr_counter *bec, 146 148 enum can_state *tx_state,