Re: [PATCH] net: make getname() functions return length rather than use int* parameter

From: Denys Vlasenko
Date: Mon Feb 12 2018 - 12:59:21 EST


On 02/12/2018 06:47 PM, David Miller wrote:
From: Denys Vlasenko <dvlasenk@xxxxxxxxxx>
Date: Mon, 12 Feb 2018 15:15:18 +0100

Before:
All these functions either return a negative error indicator,
or store length of sockaddr into "int *socklen" parameter
and return zero on success.

"int *socklen" parameter is awkward. For example, if caller does not
care, it still needs to provide on-stack storage for the value
it does not need.

None of the many FOO_getname() functions of various protocols
ever used old value of *socklen. They always just overwrite it.

This change drops this parameter, and makes all these functions, on success,
return length of sockaddr. It's always >= 0 and can be differentiated
from an error.

Tests in callers are changed from "if (err)" to "if (err < 0)", where needed.

rpc_sockname() lost "int buflen" parameter, since its only use was
to be passed to kernel_getsockname() as &buflen and subsequently
not used in any way.

Userspace API is not changed.

text data bss dec hex filename
30108430 2633624 873672 33615726 200ef6e vmlinux.before.o
30108109 2633612 873672 33615393 200ee21 vmlinux.o

Signed-off-by: Denys Vlasenko <dvlasenk@xxxxxxxxxx>

Please do an allmodconfig build, there are still some conversions you
missed:

security/tomoyo/network.c: In function ʽtomoyo_socket_listen_permissionʼ:
security/tomoyo/network.c:658:19: warning: passing argument 3 of ʽsock->ops->getnameʼ makes integer from pointer without a cast [-Wint-conversion]
&addr, &addr_len, 0);
^
security/tomoyo/network.c:658:19: note: expected ʽintʼ but argument is of type ʽint *ʼ
security/tomoyo/network.c:657:21: error: too many arguments to function ʽsock->ops->getnameʼ
const int error = sock->ops->getname(sock, (struct sockaddr *)
^~~~
fs/dlm/lowcomms.c: In function ʽlowcomms_error_reportʼ:
fs/dlm/lowcomms.c:495:6: error: too many arguments to function ʽkernel_getpeernameʼ
kernel_getpeername(con->sock, (struct sockaddr *)&saddr, &buflen)) {
^~~~~~~~~~~~~~~~~~
fs/dlm/lowcomms.c: In function ʽtcp_accept_from_sockʼ:
fs/dlm/lowcomms.c:761:7: warning: passing argument 3 of ʽnewsock->ops->getnameʼ makes integer from pointer without a cast [-Wint-conversion]
&len, 2)) {
^
fs/dlm/lowcomms.c:761:7: note: expected ʽintʼ but argument is of type ʽint *ʼ
fs/dlm/lowcomms.c:760:6: error: too many arguments to function ʽnewsock->ops->getnameʼ
if (newsock->ops->getname(newsock, (struct sockaddr *)&peeraddr,
^~~~~~~

Sorry. Will send updated patch.