Skip to contentSkip to conversation

NFS: Address build error when built with W=1

PATCH New Peng Fan (OSS) 1 participant 4 messages Feb 27

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

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]>
#1 lore raw

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
index f67773d52830d2ab4d12dd04caccc2077d4105e0..cd175204807600ff4e33ff769e03ef7ac700a6dc 100644
@@ -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
index c40395ae081429f315ccee6b73eafc742b4f01a4..9e36350b10fa84d5e2a2e6f25fce36ed504285ce 100644
@@ -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
#2 lore raw

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
index cd175204807600ff4e33ff769e03ef7ac700a6dc..1d8099337652a1cdbcaf58d394a6e981e8e7e413 100644
@@ -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
#3 lore raw

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
index 91bcf67bd743f72a008a9dcde29207bf7a36c407..64e0221c39423dae58a30018a28d874198de57aa 100644
@@ -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