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: netlink: add can_validate_databittiming()

Factorise the databittiming validation out of can_validate() and move
it in the new add can_validate_databittiming() function. Also move
can_validate()'s comment because it is specific to CAN FD. This is a
preparation patch for the introduction of CAN XL as this databittiming
validation will be reused later on.

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

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
3820a415 b23a8425

+44 -20
+44 -20
drivers/net/can/dev/netlink.c
··· 100 100 return 0; 101 101 } 102 102 103 - static int can_validate(struct nlattr *tb[], struct nlattr *data[], 104 - struct netlink_ext_ack *extack) 103 + static int can_validate_databittiming(struct nlattr *data[], 104 + struct netlink_ext_ack *extack, 105 + int ifla_can_data_bittiming, u32 flags) 105 106 { 106 - bool is_can_fd = false; 107 + struct nlattr *data_tdc; 108 + u32 tdc_flags; 109 + bool is_on; 107 110 int err; 108 111 109 112 /* Make sure that valid CAN FD configurations always consist of ··· 116 113 * - TDC parameters are coherent (details in can_validate_tdc()) 117 114 */ 118 115 116 + if (ifla_can_data_bittiming == IFLA_CAN_DATA_BITTIMING) { 117 + data_tdc = data[IFLA_CAN_TDC]; 118 + tdc_flags = flags & CAN_CTRLMODE_FD_TDC_MASK; 119 + is_on = flags & CAN_CTRLMODE_FD; 120 + } else { 121 + return -EOPNOTSUPP; /* Place holder for CAN XL */ 122 + } 123 + 124 + if (is_on) { 125 + if (!data[IFLA_CAN_BITTIMING] || !data[ifla_can_data_bittiming]) 126 + return -EOPNOTSUPP; 127 + } 128 + 129 + if (data[ifla_can_data_bittiming] || data_tdc) { 130 + if (!is_on) 131 + return -EOPNOTSUPP; 132 + } 133 + 134 + err = can_validate_bittiming(data, extack, ifla_can_data_bittiming); 135 + if (err) 136 + return err; 137 + 138 + err = can_validate_tdc(data_tdc, extack, tdc_flags); 139 + if (err) 140 + return err; 141 + 142 + return 0; 143 + } 144 + 145 + static int can_validate(struct nlattr *tb[], struct nlattr *data[], 146 + struct netlink_ext_ack *extack) 147 + { 148 + u32 flags = 0; 149 + int err; 150 + 119 151 if (!data) 120 152 return 0; 121 153 122 154 if (data[IFLA_CAN_CTRLMODE]) { 123 155 struct can_ctrlmode *cm = nla_data(data[IFLA_CAN_CTRLMODE]); 124 156 125 - is_can_fd = cm->flags & cm->mask & CAN_CTRLMODE_FD; 126 - 127 - err = can_validate_tdc(data[IFLA_CAN_TDC], extack, 128 - cm->flags & CAN_CTRLMODE_FD_TDC_MASK); 129 - if (err) 130 - return err; 157 + flags = cm->flags & cm->mask; 131 158 } 132 159 133 160 err = can_validate_bittiming(data, extack, IFLA_CAN_BITTIMING); 134 161 if (err) 135 162 return err; 136 163 137 - if (is_can_fd) { 138 - if (!data[IFLA_CAN_BITTIMING] || !data[IFLA_CAN_DATA_BITTIMING]) 139 - return -EOPNOTSUPP; 140 - } 141 - 142 - if (data[IFLA_CAN_DATA_BITTIMING] || data[IFLA_CAN_TDC]) { 143 - if (!is_can_fd) 144 - return -EOPNOTSUPP; 145 - } 146 - 147 - err = can_validate_bittiming(data, extack, IFLA_CAN_DATA_BITTIMING); 164 + err = can_validate_databittiming(data, extack, 165 + IFLA_CAN_DATA_BITTIMING, flags); 148 166 if (err) 149 167 return err; 150 168