Skip to contentSkip to conversation

net/sunrpc: Remove uses of NIPQUAD, use %pI4

PATCH RESEND Applied Joe Perches 4 participants 8 messages Mar 6, 2010 – Mar 8, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 net/sunrpc: Remove uses of NIPQUAD, use %pI4

Originally submitted Jan 1, 2010
http://patchwork.kernel.org/patch/71221/

Convert NIPQUAD to the %pI4 format extension where possible Convert %02x%02x%02x%02x/NIPQUAD to %08x/ntohl

---
 net/sunrpc/xprtrdma/transport.c |    3 +--
 net/sunrpc/xprtsock.c           |    5 ++---
 2 files changed, 3 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/transport.c +1 -2
index 7018eef..83d339f 100644
@@ -165,8 +165,7 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
 
 	xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma";
 
-	(void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
-				NIPQUAD(sin->sin_addr.s_addr));
+	(void)snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
 	xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
 
 	(void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
net/sunrpc/xprtsock.c +2 -3
index 3d739e5..86234bc 100644
@@ -297,12 +297,11 @@ static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
 	switch (sap->sa_family) {
 	case AF_INET:
 		sin = xs_addr_in(xprt);
-		(void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
-					NIPQUAD(sin->sin_addr.s_addr));
+		snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
 		break;
 	case AF_INET6:
 		sin6 = xs_addr_in6(xprt);
-		(void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
+		snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
 		break;
 	default:
 		BUG();
#2 lore raw
Quoted 6 lines · David Miller

From: Joe Perches <[email protected]>
Date: Fri, 05 Mar 2010 22:46:20 -0800

Quoted 3 lines

Originally submitted Jan 1, 2010
http://patchwork.kernel.org/patch/71221/

Quoted 8 lines
Quoted 4 lines

Convert NIPQUAD to the %pI4 format extension where possible Convert %02x%02x%02x%02x/NIPQUAD to %08x/ntohl

Trond, are you going to integrate this?

Otherwise I'm going to.

If you're planning another push to Linus then feel free to push this too.

If not, then I do have a couple of small cleanups and fixes that I want to push before the merge window closes, so I could send Joe's patch together with those...

Cheers
Trond

#3 lore raw
In reply to Joe Perches
Quoted 32 lines · Joe Perches

Originally submitted Jan 1, 2010
http://patchwork.kernel.org/patch/71221/

Convert NIPQUAD to the %pI4 format extension where possible Convert %02x%02x%02x%02x/NIPQUAD to %08x/ntohl

---
  net/sunrpc/xprtrdma/transport.c |    3 +--
  net/sunrpc/xprtsock.c           |    5 ++---
  2 files changed, 3 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/transport.c +1 -2
index 7018eef..83d339f 100644
@@ -165,8 +165,7 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
 
  	xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma";
 
-	(void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
-				NIPQUAD(sin->sin_addr.s_addr));
+	(void)snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
  	xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
 
  	(void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
net/sunrpc/xprtsock.c +0 -0
index 3d739e5..86234bc 100644
@@ -297,12 +297,11 @@ static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
  	switch (sap->sa_family) {

net/sunrpc/xprtsock.c static void xs_format_common_peer_addresses(struct rpc_xprt *xprt) · line 304

Quoted 10 lines
net/sunrpc/xprtsock.c +2 -3
  	case AF_INET:
  		sin = xs_addr_in(xprt);
-		(void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
-					NIPQUAD(sin->sin_addr.s_addr));
+		snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
  		break;
  	case AF_INET6:
  		sin6 = xs_addr_in6(xprt);
-		(void)snprintf(buf, sizeof(buf), "%pi6",&sin6->sin6_addr);
+		snprintf(buf, sizeof(buf), "%pi6",&sin6->sin6_addr);

Why remove the (void) here, but not in xprtrdma/transport.c? IMO the (void) cast should be left in place at all three call sites.

Quoted 9 lines
net/sunrpc/xprtsock.c +0 -1
  		break;
  	default:
  		BUG();
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
chuck[dot]lever[at]oracle[dot]com
#4 lore raw
Quoted 2 lines · Chuck Lever

Why remove the (void) here, but not in xprtrdma/transport.c? IMO the (void) cast should be left in place at all three call sites.

I didn't notice it in xprtrdma/transport.c, otherwise I'd've removed it there too.

When the result is not used, snprintf is most commonly not cast at all.

(There's a space and a tab in the brackets of the grep string)

$ grep -rP --include=*.[ch] "^[ 	]+snprintf\s*\(" * | wc -l
1301
$ grep -rP --include=*.[ch] "^[ 	]+\(\s*void\s*\)\s*snprintf\s*\(" * | wc -l
9

net/sunrpc/ has 7 of those.

I'll get around to submitting patches for all of them.

#5 lore raw

PATCH 1/1 net/sunrpc: Convert (void)snprintf to snprintf

In reply to Chuck Lever

(Applies on top of "Remove uses of NIPQUAD, use %pI4")

Casts to void of snprintf are most uncommon in kernel source. 9 use casts, 1301 do not.

Remove the remaining uses in net/sunrpc/

---
 net/sunrpc/xprtrdma/transport.c |    6 +++---
 net/sunrpc/xprtsock.c           |    4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
net/sunrpc/xprtrdma/transport.c +3 -3
index 83d339f..f96c2fe 100644
@@ -160,15 +160,15 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
 	(void)rpc_ntop(sap, buf, sizeof(buf));
 	xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
 
-	(void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
 
 	xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma";
 
-	(void)snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
+	snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
 	xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
 
-	(void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
 
 	/* netid */
net/sunrpc/xprtsock.c +2 -2
index 11f417b..75ab08e 100644
@@ -314,10 +314,10 @@ static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
 	struct sockaddr *sap = xs_addr(xprt);
 	char buf[128];
 
-	(void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
 
-	(void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
 }
 
maintainer
#6 lore raw

Re: [PATCH] net/sunrpc: Convert (void)snprintf to snprintf

From: Joe Perches <[email protected]>
Date: Mon, 08 Mar 2010 08:38:30 -0800

Quoted 8 lines

(Applies on top of "Remove uses of NIPQUAD, use %pI4")

Casts to void of snprintf are most uncommon in kernel source. 9 use casts, 1301 do not.

Remove the remaining uses in net/sunrpc/

Also applied, thanks Joe.