NFS: Address build error when built with W=1
Subsystems (2)
cover NFS: Address build error when built with W=1
I built x86_64_defconfig with COMPILE_TEST=y and W=1, then saw three build errors from fs/nfs: "error: variable set but not used"
Detailed info could be found in each patch commit log.
With the patchset, kernel build pass.
---
Peng Fan (3):
NFS: flexfilelayout: return ERR_PTR from nfs4_ff_alloc_deviceid_node() and fix caller
NFS: flexfilelayout: Mark err as __maybe_unused in ff_layout_io_track_ds_error
NFS: nfs4proc: Mark ptr as __maybe_unused in nfs4_proc_create_session
fs/nfs/flexfilelayout/flexfilelayout.c | 4 ++-- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 2 +- fs/nfs/nfs4proc.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
---
base-commit: 7d6661873f6b54c75195780a40d66bad3d482d8f
change-id: 20260227-nfs-ff0f0f96fea3
Best regards,
Signature · 1 line
Peng Fan <[email protected]>
PATCH 1/3 NFS: flexfilelayout: return ERR_PTR from nfs4_ff_alloc_deviceid_node() and fix caller
From: Peng Fan <[email protected]>
nfs4_ff_alloc_deviceid_node() initialized 'ret' but never returned it, triggering W=1:
fs/nfs/flexfilelayout/flexfilelayoutdev.c:56:9: error: variable 'ret' set but not used [-Werror=unused-but-set-variable]
The function also returned NULL on error, dropping the specific errno stored in 'ret'. Convert it to return ERR_PTR(ret) instead, and update ff_layout_alloc_deviceid_node() to detect errors using IS_ERR(). This preserves the error code for callers and aligns the helper with common ERR_PTR-returning allocation patterns. It also resolves the build warning.
No functional change for success paths; improves error reporting.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 2 +- fs/nfs/flexfilelayout/flexfilelayoutdev.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +1 -1
@@ -2566,7 +2566,7 @@ ff_layout_alloc_deviceid_node(struct nfs_server *server,struct nfs4_ff_layout_ds *dsaddr; dsaddr =nfs4_ff_alloc_deviceid_node (server, pdev, gfp_flags); -if (!dsaddr) +if (IS_ERR (dsaddr))return NULL ;return &dsaddr->id_node; }
fs/nfs/flexfilelayout/flexfilelayoutdev.c +1 -1
@@ -181,7 +181,7 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,kfree (new_ds);dprintk ("%s ERROR: returning %d\n" , __func__, ret); -return NULL ; +return ERR_PTR (ret); } static void extend_ds_error(struct nfs4_ff_layout_ds_err *err,
Signature · 1 line
2.37.1
PATCH 2/3 NFS: flexfilelayout: Mark err as __maybe_unused in ff_layout_io_track_ds_error
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Fix the following compiler warning when building with W=1:
flexfilelayout.c: In function 'ff_layout_io_track_ds_error':
flexfilelayout.c:1503:6:
error: variable 'err' set but not used [-Werror=unused-but-set-variable]
1503 | int err;
| ^~~Variable 'err' is assigned the return value of ff_layout_track_ds_error() but is only used in the dprintk() debug statement at the end of the function. When debug output is disabled, the variable appears unused to the compiler.
Mark it as __maybe_unused to indicate this is intentional.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/flexfilelayout/flexfilelayout.c +1 -1
@@ -1500,7 +1500,7 @@ static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg, {struct nfs4_ff_layout_mirror *mirror;u32 status = *op_status; -int err; +int err__maybe_unused ;if (status ==0 ) {switch (error) {
Signature · 1 line
2.37.1
PATCH 3/3 NFS: nfs4proc: Mark ptr as __maybe_unused in nfs4_proc_create_session
In reply to Peng Fan (OSS)From: Peng Fan <[email protected]>
Fix the following compiler warning when building with W=1:
nfs4proc.c: In function 'nfs4_proc_create_session':
nfs4proc.c:9244:16: error: variable 'ptr' set but not used [-Werror=unused-but-set-variable]
9244 | unsigned *ptr;
| ^~~
The variable 'ptr' is assigned but only used in dprintk() debug statements. When debug output is disabled, the variable appears unused to the compiler.
Mark it as __maybe_unused to indicate this is intentional.
--- fs/nfs/nfs4proc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4proc.c +1 -1
@@ -9241,7 +9241,7 @@ static int _nfs4_proc_create_session(struct nfs_client *clp,int nfs4_proc_create_session (struct nfs_client *clp,const struct cred *cred) {int status; -unsigned *ptr; +unsigned *ptr__maybe_unused ;struct nfs4_session *session = clp->cl_session;struct nfs4_add_xprt_data xprtdata = { .clp = clp,
Signature · 1 line
2.37.1