Re: [PATCH v4 1/2] sunrpc: fix unused variable warnings by using no_printk
From: Andrew Lunn <andrew@lunn.ch>
Date: 2026-02-28 20:05:12
Also in:
linux-nfs, lkml
HI all, I've also identified the cause of the build error in fs/nfsd/nfsfh.c reported by syzbot [1]. The "use of undeclared identifier 'buf'" occurs because buf is only declared within the RPC_IFDEBUG macro, which is removed when CONFIG_SUNRPC_DEBUG is disabled. To fix this, I will follow the pattern used in net/sunrpc/xprtrdma/ svc_rdma_transport.c by wrapping the dprintk call that references buf within an #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) block.
Please try to avoid adding such #if code. Compile testing does not work as well if there are millions of #if def combinations. Ideally we want the stub functions to allow as much as possible to be compiled, and then let the optimizer throw it out because it is unreachable.
static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
{
....
RPC_IFDEBUG(struct sockaddr *sap);
...
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
dprintk("svcrdma: new connection accepted on device %s:\n", dev->name);
sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
dprintk(" local address : %pIS:%u\n", sap, rpc_get_port(sap));
sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
dprintk(" remote address : %pIS:%u\n", sap, rpc_get_port(sap));
dprintk(" max_sge : %d\n", newxprt->sc_max_send_sges);
dprintk(" sq_depth : %d\n", newxprt->sc_sq_depth);
dprintk(" rdma_rw_ctxs : %d\n", ctxts);
dprintk(" max_requests : %d\n", newxprt->sc_max_requests);
dprintk(" ord : %d\n", conn_param.initiator_depth);
#endif
...
}
The refactor in fs/nfsd/nfsfh.c will look like this:
static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
struct svc_cred *cred,
struct svc_export *exp)
{
/* Check if the request originated from a secure port. */
if (rqstp && !nfsd_originating_port_ok(rqstp, cred, exp)) {
RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
+#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
dprintk("nfsd: request from insecure port %s!\n",
svc_print_addr(rqstp, buf, sizeof(buf)));
+#endifIn this case, now dprintk() uses it arguments, i think you can drop the RPC_IFDEBUG() and always have buf. This code then gets compiled. Ask make to produce fs/nfsd/nfsfh.lst and see if it generated any code for this, or has it optimized it out. Andrew