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_tdc()

Factorise the TDC validation out of can_validate() and move it in the
new can_validate_tdc() function. This is a preparation patch for the
introduction of CAN XL because this TDC validation will be reused
later on.

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

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
b23a8425 f5ae5a75

+52 -34
+48 -34
drivers/net/can/dev/netlink.c
··· 57 57 return 0; 58 58 } 59 59 60 + static int can_validate_tdc(struct nlattr *data_tdc, 61 + struct netlink_ext_ack *extack, u32 tdc_flags) 62 + { 63 + bool tdc_manual = tdc_flags & CAN_CTRLMODE_TDC_MANUAL_MASK; 64 + bool tdc_auto = tdc_flags & CAN_CTRLMODE_TDC_AUTO_MASK; 65 + int err; 66 + 67 + /* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually exclusive */ 68 + if (tdc_auto && tdc_manual) 69 + return -EOPNOTSUPP; 70 + 71 + /* If one of the CAN_CTRLMODE_TDC_* flag is set then TDC 72 + * must be set and vice-versa 73 + */ 74 + if ((tdc_auto || tdc_manual) != !!data_tdc) 75 + return -EOPNOTSUPP; 76 + 77 + /* If providing TDC parameters, at least TDCO is needed. TDCV 78 + * is needed if and only if CAN_CTRLMODE_TDC_MANUAL is set 79 + */ 80 + if (data_tdc) { 81 + struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX + 1]; 82 + 83 + err = nla_parse_nested(tb_tdc, IFLA_CAN_TDC_MAX, 84 + data_tdc, can_tdc_policy, extack); 85 + if (err) 86 + return err; 87 + 88 + if (tb_tdc[IFLA_CAN_TDC_TDCV]) { 89 + if (tdc_auto) 90 + return -EOPNOTSUPP; 91 + } else { 92 + if (tdc_manual) 93 + return -EOPNOTSUPP; 94 + } 95 + 96 + if (!tb_tdc[IFLA_CAN_TDC_TDCO]) 97 + return -EOPNOTSUPP; 98 + } 99 + 100 + return 0; 101 + } 102 + 60 103 static int can_validate(struct nlattr *tb[], struct nlattr *data[], 61 104 struct netlink_ext_ack *extack) 62 105 { ··· 110 67 * - nominal/arbitration bittiming 111 68 * - data bittiming 112 69 * - control mode with CAN_CTRLMODE_FD set 113 - * - TDC parameters are coherent (details below) 70 + * - TDC parameters are coherent (details in can_validate_tdc()) 114 71 */ 115 72 116 73 if (!data) ··· 118 75 119 76 if (data[IFLA_CAN_CTRLMODE]) { 120 77 struct can_ctrlmode *cm = nla_data(data[IFLA_CAN_CTRLMODE]); 121 - u32 tdc_flags = cm->flags & CAN_CTRLMODE_FD_TDC_MASK; 122 78 123 79 is_can_fd = cm->flags & cm->mask & CAN_CTRLMODE_FD; 124 80 125 - /* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually exclusive */ 126 - if (tdc_flags == CAN_CTRLMODE_FD_TDC_MASK) 127 - return -EOPNOTSUPP; 128 - /* If one of the CAN_CTRLMODE_TDC_* flag is set then 129 - * TDC must be set and vice-versa 130 - */ 131 - if (!!tdc_flags != !!data[IFLA_CAN_TDC]) 132 - return -EOPNOTSUPP; 133 - /* If providing TDC parameters, at least TDCO is 134 - * needed. TDCV is needed if and only if 135 - * CAN_CTRLMODE_TDC_MANUAL is set 136 - */ 137 - if (data[IFLA_CAN_TDC]) { 138 - struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX + 1]; 139 - 140 - err = nla_parse_nested(tb_tdc, IFLA_CAN_TDC_MAX, 141 - data[IFLA_CAN_TDC], 142 - can_tdc_policy, extack); 143 - if (err) 144 - return err; 145 - 146 - if (tb_tdc[IFLA_CAN_TDC_TDCV]) { 147 - if (tdc_flags & CAN_CTRLMODE_TDC_AUTO) 148 - return -EOPNOTSUPP; 149 - } else { 150 - if (tdc_flags & CAN_CTRLMODE_TDC_MANUAL) 151 - return -EOPNOTSUPP; 152 - } 153 - 154 - if (!tb_tdc[IFLA_CAN_TDC_TDCO]) 155 - return -EOPNOTSUPP; 156 - } 81 + err = can_validate_tdc(data[IFLA_CAN_TDC], extack, 82 + cm->flags & CAN_CTRLMODE_FD_TDC_MASK); 83 + if (err) 84 + return err; 157 85 } 158 86 159 87 err = can_validate_bittiming(data, extack, IFLA_CAN_BITTIMING);
+4
include/linux/can/bittiming.h
··· 16 16 17 17 #define CAN_CTRLMODE_FD_TDC_MASK \ 18 18 (CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL) 19 + #define CAN_CTRLMODE_TDC_AUTO_MASK \ 20 + (CAN_CTRLMODE_TDC_AUTO) 21 + #define CAN_CTRLMODE_TDC_MANUAL_MASK \ 22 + (CAN_CTRLMODE_TDC_MANUAL) 19 23 20 24 /* 21 25 * struct can_tdc - CAN FD Transmission Delay Compensation parameters