]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
can: raw: use temp variable instead of rolling back config
authorOliver Hartkopp <socketcan@hartkopp.net>
Fri, 3 Feb 2023 09:08:07 +0000 (10:08 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 8 Feb 2023 20:53:24 +0000 (21:53 +0100)
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>
net/can/raw.c

index ba86782ba8bb3cb9c1d4234016ec6c030449eb6c..f64469b98260f2f7df1fdcdb11868e4981fa70df 100644 (file)
@@ -523,6 +523,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
        struct can_filter sfilter;         /* single filter */
        struct net_device *dev = NULL;
        can_err_mask_t err_mask = 0;
+       int fd_frames;
        int count = 0;
        int err = 0;
 
@@ -664,17 +665,17 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
                break;
 
        case CAN_RAW_FD_FRAMES:
-               if (optlen != sizeof(ro->fd_frames))
+               if (optlen != sizeof(fd_frames))
                        return -EINVAL;
 
-               if (copy_from_sockptr(&ro->fd_frames, optval, optlen))
+               if (copy_from_sockptr(&fd_frames, optval, optlen))
                        return -EFAULT;
 
                /* Enabling CAN XL includes CAN FD */
-               if (ro->xl_frames && !ro->fd_frames) {
-                       ro->fd_frames = ro->xl_frames;
+               if (ro->xl_frames && !fd_frames)
                        return -EINVAL;
-               }
+
+               ro->fd_frames = fd_frames;
                break;
 
        case CAN_RAW_XL_FRAMES: