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

can: raw: use temp variable instead of rolling back config

Introduce a temporary variable to check for an invalid configuration
attempt from user space. Before this patch the value was copied to
the real config variable and rolled back in the case of an error.

Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20230203090807.97100-1-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Oliver Hartkopp and committed by
Marc Kleine-Budde
f2f527d5 e6ebe6c1

+6 -5
+6 -5
net/can/raw.c
··· 523 523 struct can_filter sfilter; /* single filter */ 524 524 struct net_device *dev = NULL; 525 525 can_err_mask_t err_mask = 0; 526 + int fd_frames; 526 527 int count = 0; 527 528 int err = 0; 528 529 ··· 665 664 break; 666 665 667 666 case CAN_RAW_FD_FRAMES: 668 - if (optlen != sizeof(ro->fd_frames)) 667 + if (optlen != sizeof(fd_frames)) 669 668 return -EINVAL; 670 669 671 - if (copy_from_sockptr(&ro->fd_frames, optval, optlen)) 670 + if (copy_from_sockptr(&fd_frames, optval, optlen)) 672 671 return -EFAULT; 673 672 674 673 /* Enabling CAN XL includes CAN FD */ 675 - if (ro->xl_frames && !ro->fd_frames) { 676 - ro->fd_frames = ro->xl_frames; 674 + if (ro->xl_frames && !fd_frames) 677 675 return -EINVAL; 678 - } 676 + 677 + ro->fd_frames = fd_frames; 679 678 break; 680 679 681 680 case CAN_RAW_XL_FRAMES: