Skip to content

Commit

Permalink
tipc: recode getsockopt error handling for better readability
Browse files Browse the repository at this point in the history
The existing code for the copy to user and error handling at the
end of getsockopt isn't easy to follow, due to the excessive use
of if/else.  By simply using return where appropriate, it can be
made smaller and easier to follow at the same time.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paul Gortmaker authored and David S. Miller committed Jan 1, 2011
1 parent e83504f commit 25860c3
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions net/tipc/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1755,20 +1755,16 @@ static int getsockopt(struct socket *sock,

release_sock(sk);

if (res) {
/* "get" failed */
}
else if (len < sizeof(value)) {
res = -EINVAL;
}
else if (copy_to_user(ov, &value, sizeof(value))) {
res = -EFAULT;
}
else {
res = put_user(sizeof(value), ol);
}
if (res)
return res; /* "get" failed */

return res;
if (len < sizeof(value))
return -EINVAL;

if (copy_to_user(ov, &value, sizeof(value)))
return -EFAULT;

return put_user(sizeof(value), ol);
}

/**
Expand Down

0 comments on commit 25860c3

Please sign in to comment.