Skip to content

Commit

Permalink
can: raw: raw_getsockopt(): reduce scope of err
Browse files Browse the repository at this point in the history
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: Vincent Mailhol <[email protected]>
Link: https://lore.kernel.org/all/[email protected]
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
marckleinebudde committed Feb 20, 2024
1 parent c8fba5d commit 00bf80c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,6 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
struct raw_sock *ro = raw_sk(sk);
int len;
void *val;
int err = 0;

if (level != SOL_CAN_RAW)
return -EINVAL;
Expand All @@ -766,7 +765,9 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
return -EINVAL;

switch (optname) {
case CAN_RAW_FILTER:
case CAN_RAW_FILTER: {
int err = 0;

lock_sock(sk);
if (ro->count > 0) {
int fsize = ro->count * sizeof(struct can_filter);
Expand All @@ -791,7 +792,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
if (!err)
err = put_user(len, optlen);
return err;

}
case CAN_RAW_ERR_FILTER:
if (len > sizeof(can_err_mask_t))
len = sizeof(can_err_mask_t);
Expand Down Expand Up @@ -822,7 +823,9 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
val = &ro->xl_frames;
break;

case CAN_RAW_XL_VCID_OPTS:
case CAN_RAW_XL_VCID_OPTS: {
int err = 0;

/* user space buffer to small for VCID opts? */
if (len < sizeof(ro->raw_vcid_opts)) {
/* return -ERANGE and needed space in optlen */
Expand All @@ -838,7 +841,7 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
if (!err)
err = put_user(len, optlen);
return err;

}
case CAN_RAW_JOIN_FILTERS:
if (len > sizeof(int))
len = sizeof(int);
Expand Down

0 comments on commit 00bf80c

Please sign in to comment.