Skip to content

Commit 45be26b

Browse files
vincent-mailholmarckleinebudde
authored andcommitted
can: netlink: refactor CAN_CTRLMODE_TDC_{AUTO,MANUAL} flag reset logic
CAN_CTRLMODE_TDC_AUTO and CAN_CTRLMODE_TDC_MANUAL are mutually exclusive. This means that whenever the user switches from auto to manual mode (or vice versa), the other flag which was set previously needs to be cleared. Currently, this is handled with a masking operation. It can be done in a simpler manner by clearing any of the previous TDC flags before copying netlink attributes. The code becomes easier to understand and will make it easier to add the new upcoming CAN XL flags which will have a similar reset logic as the current TDC flags. Signed-off-by: Vincent Mailhol <mailhol@kernel.org> Link: https://patch.msgid.link/20250923-canxl-netlink-prep-v4-7-e720d28f66fe@kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 3820a41 commit 45be26b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/net/can/dev/netlink.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
255255
if ((maskedflags & ctrlstatic) != ctrlstatic)
256256
return -EOPNOTSUPP;
257257

258+
/* If a top dependency flag is provided, reset all its dependencies */
259+
if (cm->mask & CAN_CTRLMODE_FD)
260+
priv->ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK;
261+
258262
/* clear bits to be modified and copy the flag values */
259263
priv->ctrlmode &= ~cm->mask;
260264
priv->ctrlmode |= maskedflags;
@@ -270,11 +274,6 @@ static int can_changelink(struct net_device *dev, struct nlattr *tb[],
270274
can_set_default_mtu(dev);
271275

272276
fd_tdc_flag_provided = cm->mask & CAN_CTRLMODE_FD_TDC_MASK;
273-
/* CAN_CTRLMODE_TDC_{AUTO,MANUAL} are mutually
274-
* exclusive: make sure to turn the other one off
275-
*/
276-
if (fd_tdc_flag_provided)
277-
priv->ctrlmode &= cm->flags | ~CAN_CTRLMODE_FD_TDC_MASK;
278277
}
279278

280279
if (data[IFLA_CAN_BITTIMING]) {

0 commit comments

Comments
 (0)