Skip to content

Commit a0c669e

Browse files
rluboscarlescufi
authored andcommitted
net: sockets: Simplify common getsockname() implementation
Simplify common `getsockname()` implementation by using VTABLE_CALL() macro, in the same way as other socket calls do. This additionally allows to cover the case, when `getsockname()` is not implemnented by particular socket implementation, preventing the crash. Signed-off-by: Robert Lubos <[email protected]>
1 parent 889ab91 commit a0c669e

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

subsys/net/lib/sockets/sockets.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,26 +1991,7 @@ int zsock_getsockname_ctx(struct net_context *ctx, struct sockaddr *addr,
19911991
int z_impl_zsock_getsockname(int sock, struct sockaddr *addr,
19921992
socklen_t *addrlen)
19931993
{
1994-
const struct socket_op_vtable *vtable;
1995-
struct k_mutex *lock;
1996-
void *ctx;
1997-
int ret;
1998-
1999-
ctx = get_sock_vtable(sock, &vtable, &lock);
2000-
if (ctx == NULL) {
2001-
errno = EBADF;
2002-
return -1;
2003-
}
2004-
2005-
NET_DBG("getsockname: ctx=%p, fd=%d", ctx, sock);
2006-
2007-
(void)k_mutex_lock(lock, K_FOREVER);
2008-
2009-
ret = vtable->getsockname(ctx, addr, addrlen);
2010-
2011-
k_mutex_unlock(lock);
2012-
2013-
return ret;
1994+
VTABLE_CALL(getsockname, sock, addr, addrlen);
20141995
}
20151996

20161997
#ifdef CONFIG_USERSPACE

0 commit comments

Comments
 (0)