提交 f2f527d5 编写于 作者: O Oliver Hartkopp 提交者: Marc Kleine-Budde

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: NMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: NOliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20230203090807.97100-1-socketcan@hartkopp.netSigned-off-by: NMarc Kleine-Budde <mkl@pengutronix.de>
上级 e6ebe6c1
...@@ -523,6 +523,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, ...@@ -523,6 +523,7 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
struct can_filter sfilter; /* single filter */ struct can_filter sfilter; /* single filter */
struct net_device *dev = NULL; struct net_device *dev = NULL;
can_err_mask_t err_mask = 0; can_err_mask_t err_mask = 0;
int fd_frames;
int count = 0; int count = 0;
int err = 0; int err = 0;
...@@ -664,17 +665,17 @@ static int raw_setsockopt(struct socket *sock, int level, int optname, ...@@ -664,17 +665,17 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
break; break;
case CAN_RAW_FD_FRAMES: case CAN_RAW_FD_FRAMES:
if (optlen != sizeof(ro->fd_frames)) if (optlen != sizeof(fd_frames))
return -EINVAL; return -EINVAL;
if (copy_from_sockptr(&ro->fd_frames, optval, optlen)) if (copy_from_sockptr(&fd_frames, optval, optlen))
return -EFAULT; return -EFAULT;
/* Enabling CAN XL includes CAN FD */ /* Enabling CAN XL includes CAN FD */
if (ro->xl_frames && !ro->fd_frames) { if (ro->xl_frames && !fd_frames)
ro->fd_frames = ro->xl_frames;
return -EINVAL; return -EINVAL;
}
ro->fd_frames = fd_frames;
break; break;
case CAN_RAW_XL_FRAMES: case CAN_RAW_XL_FRAMES:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册