Skip to content

Commit f2f527d

Browse files
hartkoppmarckleinebudde
authored andcommitted
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 <[email protected]> Signed-off-by: Oliver Hartkopp <[email protected]> Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent e6ebe6c commit f2f527d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/can/raw.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
523523
struct can_filter sfilter; /* single filter */
524524
struct net_device *dev = NULL;
525525
can_err_mask_t err_mask = 0;
526+
int fd_frames;
526527
int count = 0;
527528
int err = 0;
528529

@@ -664,17 +665,17 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
664665
break;
665666

666667
case CAN_RAW_FD_FRAMES:
667-
if (optlen != sizeof(ro->fd_frames))
668+
if (optlen != sizeof(fd_frames))
668669
return -EINVAL;
669670

670-
if (copy_from_sockptr(&ro->fd_frames, optval, optlen))
671+
if (copy_from_sockptr(&fd_frames, optval, optlen))
671672
return -EFAULT;
672673

673674
/* Enabling CAN XL includes CAN FD */
674-
if (ro->xl_frames && !ro->fd_frames) {
675-
ro->fd_frames = ro->xl_frames;
675+
if (ro->xl_frames && !fd_frames)
676676
return -EINVAL;
677-
}
677+
678+
ro->fd_frames = fd_frames;
678679
break;
679680

680681
case CAN_RAW_XL_FRAMES:

0 commit comments

Comments
 (0)