Commit 00bf80c4 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

can: raw: raw_getsockopt(): reduce scope of err

Reduce the scope of the variable "err" to the individual cases. This
is to avoid the mistake of setting "err" in the mistaken belief that
it will be evaluated later.
Reviewed-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
Link: https://lore.kernel.org/all/20240220-raw-setsockopt-v1-1-7d34cb1377fc@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent c8fba5d6
...@@ -756,7 +756,6 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, ...@@ -756,7 +756,6 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
struct raw_sock *ro = raw_sk(sk); struct raw_sock *ro = raw_sk(sk);
int len; int len;
void *val; void *val;
int err = 0;
if (level != SOL_CAN_RAW) if (level != SOL_CAN_RAW)
return -EINVAL; return -EINVAL;
...@@ -766,7 +765,9 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, ...@@ -766,7 +765,9 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
return -EINVAL; return -EINVAL;
switch (optname) { switch (optname) {
case CAN_RAW_FILTER: case CAN_RAW_FILTER: {
int err = 0;
lock_sock(sk); lock_sock(sk);
if (ro->count > 0) { if (ro->count > 0) {
int fsize = ro->count * sizeof(struct can_filter); int fsize = ro->count * sizeof(struct can_filter);
...@@ -791,7 +792,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, ...@@ -791,7 +792,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
if (!err) if (!err)
err = put_user(len, optlen); err = put_user(len, optlen);
return err; return err;
}
case CAN_RAW_ERR_FILTER: case CAN_RAW_ERR_FILTER:
if (len > sizeof(can_err_mask_t)) if (len > sizeof(can_err_mask_t))
len = sizeof(can_err_mask_t); len = sizeof(can_err_mask_t);
...@@ -822,7 +823,9 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, ...@@ -822,7 +823,9 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
val = &ro->xl_frames; val = &ro->xl_frames;
break; break;
case CAN_RAW_XL_VCID_OPTS: case CAN_RAW_XL_VCID_OPTS: {
int err = 0;
/* user space buffer to small for VCID opts? */ /* user space buffer to small for VCID opts? */
if (len < sizeof(ro->raw_vcid_opts)) { if (len < sizeof(ro->raw_vcid_opts)) {
/* return -ERANGE and needed space in optlen */ /* return -ERANGE and needed space in optlen */
...@@ -838,7 +841,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname, ...@@ -838,7 +841,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
if (!err) if (!err)
err = put_user(len, optlen); err = put_user(len, optlen);
return err; return err;
}
case CAN_RAW_JOIN_FILTERS: case CAN_RAW_JOIN_FILTERS:
if (len > sizeof(int)) if (len > sizeof(int))
len = sizeof(int); len = sizeof(int);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment