On Tue, 2026-09-15 at 08:18 +0000, Bill Wendling wrote: > rpc_sockaddr2uaddr() formats the IP address into "addrbuf", formats the > port into a temporary "portbuf" buffer with snprintf(), and then appends > "portbuf" to "addrbuf" using strlcat(). > > In preparation for removing the deprecated strlcat() API[1], capture the > length returned by rpc_ntop4() and rpc_ntop6_noscopeid() and format the > port directly onto the end of "addrbuf" with snprintf(). This eliminates > the strlcat() call and the temporary "portbuf" buffer. > > Link: https://github.com/KSPP/linux/issues/370 [1] > Cc: [email protected] > Assisted-by: CoPilot:3.5-sonnet [editor_update_file, shell_command_run] > Signed-off-by: Bill Wendling <[email protected]> > --- > Cc: Russell King <[email protected]> > Cc: Huacai Chen <[email protected]> > Cc: WANG Xuerui <[email protected]> > Cc: Thomas Bogendoerfer <[email protected]> > Cc: "James E.J. Bottomley" <[email protected]> > Cc: Helge Deller <[email protected]> > Cc: Thomas Gleixner <[email protected]> > Cc: Ingo Molnar <[email protected]> > Cc: Borislav Petkov <[email protected]> > Cc: Dave Hansen <[email protected]> > Cc: [email protected] > Cc: "H. Peter Anvin" <[email protected]> > Cc: Ian Abbott <[email protected]> > Cc: H Hartley Sweeten <[email protected]> > Cc: Tony Luck <[email protected]> > Cc: Maarten Lankhorst <[email protected]> > Cc: Maxime Ripard <[email protected]> > Cc: Thomas Zimmermann <[email protected]> > Cc: David Airlie <[email protected]> > Cc: Simona Vetter <[email protected]> > Cc: Matthew Brost <[email protected]> > Cc: "Thomas Hellström" <[email protected]> > Cc: Rodrigo Vivi <[email protected]> > Cc: Dmitry Torokhov <[email protected]> > Cc: Matthias Schwarzott <[email protected]> > Cc: Mauro Carvalho Chehab <[email protected]> > Cc: Tony Nguyen <[email protected]> > Cc: Przemek Kitszel <[email protected]> > Cc: Andrew Lunn <[email protected]> > Cc: "David S. Miller" <[email protected]> > Cc: Eric Dumazet <[email protected]> > Cc: Jakub Kicinski <[email protected]> > Cc: Paolo Abeni <[email protected]> > Cc: Arend van Spriel <[email protected]> > Cc: Rob Herring <[email protected]> > Cc: Saravana Kannan <[email protected]> > Cc: Krzysztof Kozlowski <[email protected]> > Cc: Sylwester Nawrocki <[email protected]> > Cc: Peter Griffin <[email protected]> > Cc: Alim Akhtar <[email protected]> > Cc: Linus Walleij <[email protected]> > Cc: Anil Gurumurthy <[email protected]> > Cc: Sudarsana Kalluru <[email protected]> > Cc: "Martin K. Petersen" <[email protected]> > Cc: Trond Myklebust <[email protected]> > Cc: Anna Schumaker <[email protected]> > Cc: Mike Marshall <[email protected]> > Cc: Martin Brandenburg <[email protected]> > Cc: Kees Cook <[email protected]> > Cc: Jiri Pirko <[email protected]> > Cc: Simon Horman <[email protected]> > Cc: Chuck Lever <[email protected]> > Cc: Jeff Layton <[email protected]> > Cc: NeilBrown <[email protected]> > Cc: Olga Kornievskaia <[email protected]> > Cc: Dai Ngo <[email protected]> > Cc: Tom Talpey <[email protected]> > Cc: Jaroslav Kysela <[email protected]> > Cc: Takashi Iwai <[email protected]> > Cc: Bill Wendling <[email protected]> > Cc: Andrew Morton <[email protected]> > Cc: "Mike Rapoport (Microsoft)" <[email protected]> > Cc: Kanglong Wang <[email protected]> > Cc: Tiezhu Yang <[email protected]> > Cc: Qiang Ma <[email protected]> > Cc: Randy Dunlap <[email protected]> > Cc: Pengpeng Hou <[email protected]> > Cc: Ard Biesheuvel <[email protected]> > Cc: Breno Leitao <[email protected]> > Cc: Thorsten Blum <[email protected]> > Cc: Harshit Mogalapalli <[email protected]> > Cc: Greg Kroah-Hartman <[email protected]> > Cc: Lyude Paul <[email protected]> > Cc: Ashutosh Desai <[email protected]> > Cc: Imre Deak <[email protected]> > Cc: Dmitry Baryshkov <[email protected]> > Cc: Johan Hovold <[email protected]> > Cc: Johannes Berg <[email protected]> > Cc: Miri Korenblit <[email protected]> > Cc: Alexander Stein <[email protected]> > Cc: Cryolitia PukNgae <[email protected]> > Cc: Jiaming Zhang <[email protected]> > Cc: Will Porter <[email protected]> > Cc: Cen Zhang <[email protected]> > Cc: "Cássio Gabriel" <[email protected]> > Cc: Rong Zhang <[email protected]> > Cc: Arun Raghavan <[email protected]> > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > Cc: [email protected] > --- > net/sunrpc/addr.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c > index 97ff11973c49..a1e4173e5a53 100644 > --- a/net/sunrpc/addr.c > +++ b/net/sunrpc/addr.c > @@ -264,18 +264,20 @@ EXPORT_SYMBOL_GPL(rpc_pton); > */ > char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags) > { > - char portbuf[RPCBIND_MAXUADDRPLEN]; > char addrbuf[RPCBIND_MAXUADDRLEN]; > unsigned short port; > + size_t len; > > switch (sap->sa_family) { > case AF_INET: > - if (rpc_ntop4(sap, addrbuf, sizeof(addrbuf)) == 0) > + len = rpc_ntop4(sap, addrbuf, sizeof(addrbuf)); > + if (len == 0 || len >= sizeof(addrbuf)) > return NULL; > port = ntohs(((struct sockaddr_in *)sap)->sin_port); > break; > case AF_INET6: > - if (rpc_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)) == 0) > + len = rpc_ntop6_noscopeid(sap, addrbuf, sizeof(addrbuf)); > + if (len == 0 || len >= sizeof(addrbuf)) > return NULL; > port = ntohs(((struct sockaddr_in6 *)sap)->sin6_port); > break; > @@ -283,11 +285,8 @@ char *rpc_sockaddr2uaddr(const struct sockaddr *sap, > gfp_t gfp_flags) > return NULL; > } > > - if (snprintf(portbuf, sizeof(portbuf), > - ".%u.%u", port >> 8, port & 0xff) >= (int)sizeof(portbuf)) > - return NULL; > - > - if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) >= sizeof(addrbuf)) > + if (snprintf(addrbuf + len, sizeof(addrbuf) - len, > + ".%u.%u", port >> 8, port & 0xff) >= sizeof(addrbuf) - len) > return NULL; > > return kstrdup(addrbuf, gfp_flags); > @@ -352,3 +351,4 @@ size_t rpc_uaddr2sockaddr(struct net *net, const char > *uaddr, > return 0; > } > EXPORT_SYMBOL_GPL(rpc_uaddr2sockaddr); > +
The last blank line here is not needed. The rest looks fine though. Reviewed-by: Jeff Layton <[email protected]>
