Skip to content

Commit 25860c3

Browse files
Paul Gortmakerdavem330
authored andcommitted
tipc: recode getsockopt error handling for better readability
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>
1 parent e83504f commit 25860c3

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

‎net/tipc/socket.c‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,20 +1755,16 @@ static int getsockopt(struct socket *sock,
17551755

17561756
release_sock(sk);
17571757

1758-
if (res) {
1759-
/* "get" failed */
1760-
}
1761-
else if (len < sizeof(value)) {
1762-
res = -EINVAL;
1763-
}
1764-
else if (copy_to_user(ov, &value, sizeof(value))) {
1765-
res = -EFAULT;
1766-
}
1767-
else {
1768-
res = put_user(sizeof(value), ol);
1769-
}
1758+
if (res)
1759+
return res; /* "get" failed */
17701760

1771-
return res;
1761+
if (len < sizeof(value))
1762+
return -EINVAL;
1763+
1764+
if (copy_to_user(ov, &value, sizeof(value)))
1765+
return -EFAULT;
1766+
1767+
return put_user(sizeof(value), ol);
17721768
}
17731769

17741770
/**

0 commit comments

Comments
 (0)