Skip to contentSkip to conversation

Fix compiler warnings/errors in SUNRPC and MACB

PATCH Superseded Sean Chang 5 participants 11 messages Feb 28 – Mar 2

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Sean Chang

author
#0 lore raw

v5 cover Fix compiler warnings/errors in SUNRPC and MACB

This series addresses compiler warnings and a build error identified across different architectures and configurations.

The first patch refactors the dfprintk macros in the SUNRPC subsystem. This global fix silences unused variable warnings and, by incorporating no_printk(), ensures continued compiler type checking. It also includes a specific fix for a build error in nfsd (nfsfh.c) uncovered by syzbot in non-debug configurations.

The second patch fixes a format-truncation warning in the MACB ethernet driver by ensuring the snprintf output fits within the destination buffer.

v5:
- Simplify dfprintk and dfprintk_rcu macros by removing the redundant 'fmt' argument and calling no_printk(__VA_ARGS__) directly, as suggested by David Laight.
- Fix a build error in fs/nfsd/nfsfh.c reported by syzbot. The error was caused by a mismatch between the variable's lifecycle (defined via RPC_IFDEBUG) and its usage in dprintk.
- Add Link tag to the syzbot build failure report.
- Update series title to reflect the general nature of the fixes.

v4:
- Refactor patch 1 to use no_printk() in sunrpc headers instead of marking variables as __maybe_unused. This provides a cleaner, global fix and enables compiler type checking.

v3:
- Expand commit descriptions to include technical details regarding macro expansion, as requested by Andrew Lunn.
- Test the different platform, such as ARM, ARM64, X86_64.

v2:
- Split the original treewide patch into subsystem-specific commits.
- Added more detailed commit descriptions to satisfy checkpatch.

Sean Chang (2):
sunrpc: simplify dfprintk macros and fix nfsd build error
net: macb: use ethtool_sprintf to fill ethtool stats strings

 drivers/net/ethernet/cadence/macb_main.c | 7 ++-----
 fs/nfsd/nfsfh.c                          | 2 ++
 include/linux/sunrpc/debug.h             | 4 ++--
 3 files changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/2 sunrpc: simplify dfprintk macros and fix nfsd build error

When CONFIG_SUNRPC_DEBUG is disabled, the dfprintk() macros currently expand to empty do-while loops. This causes variables used solely within these calls to appear unused, triggering -Wunused-variable warnings.

Following David Laight's suggestion, simplify the macro definitions by removing the unnecessary 'fmt' argument and using no_printk(__VA_ARGS__) directly. This ensures the compiler performs type checking and "sees" the variables, silencing the warnings without emitting any code.

Additionally, fix a build error in fs/nfsd/nfsfh.c reported by syzbot. In nfsd_setuser_and_check_port(), the variable 'buf' is conditionally defined via RPC_IFDEBUG. Since no_printk() now performs type checking, it triggers an 'undeclared identifier' error when debug is disabled. Wrap the dprintk call in an #if block to synchronize its lifecycle with 'buf', following the pattern in svc_rdma_transport.c.

---
 fs/nfsd/nfsfh.c              | 2 ++
 include/linux/sunrpc/debug.h | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/nfsfh.c +2 -0
index ed85dd43da18..f7386fd483a6 100644
@@ -106,8 +106,10 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
 	/* 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)));
+#endif
 		return nfserr_perm;
 	}
 
include/linux/sunrpc/debug.h +2 -2
index eb4bd62df319..cb33c7e1f370 100644
@@ -52,8 +52,8 @@ do {									\
 # define RPC_IFDEBUG(x)		x
 #else
 # define ifdebug(fac)		if (0)
-# define dfprintk(fac, fmt, ...)	do {} while (0)
-# define dfprintk_rcu(fac, fmt, ...)	do {} while (0)
+# define dfprintk(fac, ...)		no_printk(__VA_ARGS__)
+# define dfprintk_rcu(fac, ...)	no_printk(__VA_ARGS__)
 # define RPC_IFDEBUG(x)
 #endif
 
Signature · 1 line
2.34.1
author
#9 lore raw

PATCH v5 2/2 net: macb: use ethtool_sprintf to fill ethtool stats strings

In reply to Sean Chang

The RISC-V toolchain triggers a stringop-truncation warning when using snprintf() with a fixed ETH_GSTRING_LEN (32 bytes) buffer.

Convert the driver to use the modern ethtool_sprintf() API from linux/ethtool.h. This removes the need for manual snprintf() and memcpy() calls, handles the 32-byte padding automatically, and simplifies the logic by removing manual pointer arithmetic.

---
 drivers/net/ethernet/cadence/macb_main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +2 -5
index 5bc35f651ebd..79ca19097b2d 100644
@@ -3145,7 +3145,6 @@ static int gem_get_sset_count(struct net_device *dev, int sset)
 
 static void gem_get_ethtool_strings(struct net_device *dev, u32 sset, u8 *p)
 {
-	char stat_string[ETH_GSTRING_LEN];
 	struct macb *bp = netdev_priv(dev);
 	struct macb_queue *queue;
 	unsigned int i;
@@ -3158,10 +3157,8 @@ static void gem_get_ethtool_strings(struct net_device *dev, u32 sset, u8 *p)
 			       ETH_GSTRING_LEN);
 
 		for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
-			for (i = 0; i < QUEUE_STATS_LEN; i++, p += ETH_GSTRING_LEN) {
-				snprintf(stat_string, ETH_GSTRING_LEN, "q%d_%s",
-						q, queue_statistics[i].stat_string);
-				memcpy(p, stat_string, ETH_GSTRING_LEN);
+			for (i = 0; i < QUEUE_STATS_LEN; i++) {
+				ethtool_sprintf(&p, "q%u_%s", q, queue_statistics[i].stat_string);
 			}
 		}
 		break;
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error

In reply to Sean Chang
kernel test robot noticed the following build warnings:

Hi Sean,

kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on trondmy-nfs/linux-next net/main net-next/main linus/master v7.0-rc1 next-20260227] [cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sean-Chang/sunrpc-simplify-dfprintk-macros-and-fix-nfsd-build-error/20260301-040617
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20260228180821.811683-2-seanwascoding%40gmail.com
patch subject: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error
config: i386-randconfig-001-20260301 (https://download.01.org/0day-ci/archive/20260301/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260301/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/asm-generic/bug.h:31,

                    from arch/x86/include/asm/bug.h:193,
                    from include/linux/bug.h:5,
                    from include/linux/slab.h:15,
                    from fs/lockd/svclock.c:25:
   fs/lockd/svclock.c: In function 'nlmsvc_lookup_block':
   fs/lockd/svclock.c:163:33: error: implicit declaration of function 'nlmdbg_cookie2a' [-Wimplicit-function-declaration]
     163 |                                 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
         |                                 ^~~~~~~~~~~~~~~
   include/linux/printk.h:134:32: note: in definition of macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                                ^~~~~~~~~~~
   include/linux/sunrpc/debug.h:23:9: note: in expansion of macro 'dfprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |         ^~~~~~~~
   fs/lockd/svclock.c:159:17: note: in expansion of macro 'dprintk'
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                 ^~~~~~~
>> fs/lockd/svclock.c:159:25: warning: format '%s' expects argument of type 'char *', but argument 7 has type 'int' [-Wformat=]
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ......
     163 |                                 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
         |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                 |
         |                                 int
   include/linux/printk.h:134:25: note: in definition of macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                         ^~~
   include/linux/sunrpc/debug.h:23:9: note: in expansion of macro 'dfprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |         ^~~~~~~~
   fs/lockd/svclock.c:159:17: note: in expansion of macro 'dprintk'
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                 ^~~~~~~
   fs/lockd/svclock.c:159:72: note: format string is defined here
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                                                                       ~^
         |                                                                        |
         |                                                                        char *
         |                                                                       %d
   fs/lockd/svclock.c: In function 'nlmsvc_find_block':
   fs/lockd/svclock.c:202:17: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~
         |                                                      |
         |                                                      int
   include/linux/printk.h:134:25: note: in definition of macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                         ^~~
   include/linux/sunrpc/debug.h:23:9: note: in expansion of macro 'dfprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |         ^~~~~~~~
   fs/lockd/svclock.c:202:9: note: in expansion of macro 'dprintk'
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |         ^~~~~~~
   fs/lockd/svclock.c:202:37: note: format string is defined here
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |                                    ~^
         |                                     |
         |                                     char *
         |                                    %d

vim +159 fs/lockd/svclock.c

^1da177e4c3f41 Linus Torvalds  2005-04-16  141  
^1da177e4c3f41 Linus Torvalds  2005-04-16  142  /*
d9f6eb75d49007 Trond Myklebust 2006-03-20  143   * Find a block for a given lock
^1da177e4c3f41 Linus Torvalds  2005-04-16  144   */
^1da177e4c3f41 Linus Torvalds  2005-04-16  145  static struct nlm_block *
d9f6eb75d49007 Trond Myklebust 2006-03-20  146  nlmsvc_lookup_block(struct nlm_file *file, struct nlm_lock *lock)
^1da177e4c3f41 Linus Torvalds  2005-04-16  147  {
68a2d76cea4234 Olaf Kirch      2006-10-04  148  	struct nlm_block	*block;
^1da177e4c3f41 Linus Torvalds  2005-04-16  149  	struct file_lock	*fl;
^1da177e4c3f41 Linus Torvalds  2005-04-16  150  
^1da177e4c3f41 Linus Torvalds  2005-04-16  151  	dprintk("lockd: nlmsvc_lookup_block f=%p pd=%d %Ld-%Ld ty=%d\n",
eb8ed7c6ab08cd Jeff Layton     2024-01-31  152  				file, lock->fl.c.flc_pid,
^1da177e4c3f41 Linus Torvalds  2005-04-16  153  				(long long)lock->fl.fl_start,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  154  				(long long)lock->fl.fl_end,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  155  				lock->fl.c.flc_type);
be2be5f7f44364 Alexander Aring 2023-07-20  156  	spin_lock(&nlm_blocked_lock);
68a2d76cea4234 Olaf Kirch      2006-10-04  157  	list_for_each_entry(block, &nlm_blocked, b_list) {
92737230dd3f14 Trond Myklebust 2006-03-20  158  		fl = &block->b_call->a_args.lock.fl;
^1da177e4c3f41 Linus Torvalds  2005-04-16 @159  		dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
eb8ed7c6ab08cd Jeff Layton     2024-01-31  160  				block->b_file, fl->c.flc_pid,
^1da177e4c3f41 Linus Torvalds  2005-04-16  161  				(long long)fl->fl_start,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  162  				(long long)fl->fl_end, fl->c.flc_type,
92737230dd3f14 Trond Myklebust 2006-03-20  163  				nlmdbg_cookie2a(&block->b_call->a_args.cookie));
^1da177e4c3f41 Linus Torvalds  2005-04-16  164  		if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) {
6849c0cab69f5d Trond Myklebust 2006-03-20  165  			kref_get(&block->b_count);
be2be5f7f44364 Alexander Aring 2023-07-20  166  			spin_unlock(&nlm_blocked_lock);
^1da177e4c3f41 Linus Torvalds  2005-04-16  167  			return block;
^1da177e4c3f41 Linus Torvalds  2005-04-16  168  		}
^1da177e4c3f41 Linus Torvalds  2005-04-16  169  	}
be2be5f7f44364 Alexander Aring 2023-07-20  170  	spin_unlock(&nlm_blocked_lock);
^1da177e4c3f41 Linus Torvalds  2005-04-16  171  
^1da177e4c3f41 Linus Torvalds  2005-04-16  172  	return NULL;
^1da177e4c3f41 Linus Torvalds  2005-04-16  173  }
^1da177e4c3f41 Linus Torvalds  2005-04-16  174  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

Re: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error

In reply to Sean Chang
kernel test robot noticed the following build errors:

Hi Sean,

kernel test robot noticed the following build errors:

[auto build test ERROR on brauner-vfs/vfs.all]
[also build test ERROR on trondmy-nfs/linux-next net/main net-next/main linus/master v7.0-rc1 next-20260227] [cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sean-Chang/sunrpc-simplify-dfprintk-macros-and-fix-nfsd-build-error/20260301-040617
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20260228180821.811683-2-seanwascoding%40gmail.com
patch subject: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error
config: i386-randconfig-001-20260301 (https://download.01.org/0day-ci/archive/20260301/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260301/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from include/asm-generic/bug.h:31,

                    from arch/x86/include/asm/bug.h:193,
                    from include/linux/bug.h:5,
                    from include/linux/slab.h:15,
                    from fs/lockd/svclock.c:25:
   fs/lockd/svclock.c: In function 'nlmsvc_lookup_block':
>> fs/lockd/svclock.c:163:33: error: implicit declaration of function 'nlmdbg_cookie2a' [-Wimplicit-function-declaration]
     163 |                                 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
         |                                 ^~~~~~~~~~~~~~~
   include/linux/printk.h:134:32: note: in definition of macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                                ^~~~~~~~~~~
   include/linux/sunrpc/debug.h:23:9: note: in expansion of macro 'dfprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |         ^~~~~~~~
   fs/lockd/svclock.c:159:17: note: in expansion of macro 'dprintk'
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                 ^~~~~~~
   fs/lockd/svclock.c:159:25: warning: format '%s' expects argument of type 'char *', but argument 7 has type 'int' [-Wformat=]
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ......
     163 |                                 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
         |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                 |
         |                                 int
   include/linux/printk.h:134:25: note: in definition of macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                         ^~~
   include/linux/sunrpc/debug.h:23:9: note: in expansion of macro 'dfprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |         ^~~~~~~~
   fs/lockd/svclock.c:159:17: note: in expansion of macro 'dprintk'
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                 ^~~~~~~
   fs/lockd/svclock.c:159:72: note: format string is defined here
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                                                                       ~^
         |                                                                        |
         |                                                                        char *
         |                                                                       %d
   fs/lockd/svclock.c: In function 'nlmsvc_find_block':
   fs/lockd/svclock.c:202:17: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~~~~~~~~~~~~
         |                                                      |
         |                                                      int
   include/linux/printk.h:134:25: note: in definition of macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                         ^~~
   include/linux/sunrpc/debug.h:23:9: note: in expansion of macro 'dfprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |         ^~~~~~~~
   fs/lockd/svclock.c:202:9: note: in expansion of macro 'dprintk'
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |         ^~~~~~~
   fs/lockd/svclock.c:202:37: note: format string is defined here
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |                                    ~^
         |                                     |
         |                                     char *
         |                                    %d

vim +/nlmdbg_cookie2a +163 fs/lockd/svclock.c

^1da177e4c3f41 Linus Torvalds  2005-04-16  141  
^1da177e4c3f41 Linus Torvalds  2005-04-16  142  /*
d9f6eb75d49007 Trond Myklebust 2006-03-20  143   * Find a block for a given lock
^1da177e4c3f41 Linus Torvalds  2005-04-16  144   */
^1da177e4c3f41 Linus Torvalds  2005-04-16  145  static struct nlm_block *
d9f6eb75d49007 Trond Myklebust 2006-03-20  146  nlmsvc_lookup_block(struct nlm_file *file, struct nlm_lock *lock)
^1da177e4c3f41 Linus Torvalds  2005-04-16  147  {
68a2d76cea4234 Olaf Kirch      2006-10-04  148  	struct nlm_block	*block;
^1da177e4c3f41 Linus Torvalds  2005-04-16  149  	struct file_lock	*fl;
^1da177e4c3f41 Linus Torvalds  2005-04-16  150  
^1da177e4c3f41 Linus Torvalds  2005-04-16  151  	dprintk("lockd: nlmsvc_lookup_block f=%p pd=%d %Ld-%Ld ty=%d\n",
eb8ed7c6ab08cd Jeff Layton     2024-01-31  152  				file, lock->fl.c.flc_pid,
^1da177e4c3f41 Linus Torvalds  2005-04-16  153  				(long long)lock->fl.fl_start,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  154  				(long long)lock->fl.fl_end,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  155  				lock->fl.c.flc_type);
be2be5f7f44364 Alexander Aring 2023-07-20  156  	spin_lock(&nlm_blocked_lock);
68a2d76cea4234 Olaf Kirch      2006-10-04  157  	list_for_each_entry(block, &nlm_blocked, b_list) {
92737230dd3f14 Trond Myklebust 2006-03-20  158  		fl = &block->b_call->a_args.lock.fl;
^1da177e4c3f41 Linus Torvalds  2005-04-16  159  		dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
eb8ed7c6ab08cd Jeff Layton     2024-01-31  160  				block->b_file, fl->c.flc_pid,
^1da177e4c3f41 Linus Torvalds  2005-04-16  161  				(long long)fl->fl_start,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  162  				(long long)fl->fl_end, fl->c.flc_type,
92737230dd3f14 Trond Myklebust 2006-03-20 @163  				nlmdbg_cookie2a(&block->b_call->a_args.cookie));
^1da177e4c3f41 Linus Torvalds  2005-04-16  164  		if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) {
6849c0cab69f5d Trond Myklebust 2006-03-20  165  			kref_get(&block->b_count);
be2be5f7f44364 Alexander Aring 2023-07-20  166  			spin_unlock(&nlm_blocked_lock);
^1da177e4c3f41 Linus Torvalds  2005-04-16  167  			return block;
^1da177e4c3f41 Linus Torvalds  2005-04-16  168  		}
^1da177e4c3f41 Linus Torvalds  2005-04-16  169  	}
be2be5f7f44364 Alexander Aring 2023-07-20  170  	spin_unlock(&nlm_blocked_lock);
^1da177e4c3f41 Linus Torvalds  2005-04-16  171  
^1da177e4c3f41 Linus Torvalds  2005-04-16  172  	return NULL;
^1da177e4c3f41 Linus Torvalds  2005-04-16  173  }
^1da177e4c3f41 Linus Torvalds  2005-04-16  174  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error

In reply to Sean Chang
kernel test robot noticed the following build warnings:

Hi Sean,

kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on trondmy-nfs/linux-next net/main net-next/main linus/master v7.0-rc1 next-20260227] [cannot apply to horms-ipvs/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sean-Chang/sunrpc-simplify-dfprintk-macros-and-fix-nfsd-build-error/20260301-040617
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20260228180821.811683-2-seanwascoding%40gmail.com
patch subject: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error
config: i386-randconfig-141-20260301 (https://download.01.org/0day-ci/archive/20260301/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
smatch version: v0.5.0-8994-gd50c5a4c
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260301/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

fs/lockd/svclock.c:163:5: error: call to undeclared function 'nlmdbg_cookie2a'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

     163 |                                 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
         |                                 ^
>> fs/lockd/svclock.c:163:5: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
     159 |                 dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
         |                                                                       ~~
         |                                                                       %d
     160 |                                 block->b_file, fl->c.flc_pid,
     161 |                                 (long long)fl->fl_start,
     162 |                                 (long long)fl->fl_end, fl->c.flc_type,
     163 |                                 nlmdbg_cookie2a(&block->b_call->a_args.cookie));
         |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/sunrpc/debug.h:23:28: note: expanded from macro 'dprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |                            ~~~    ^~~~~~~~~~~
   include/linux/sunrpc/debug.h:55:40: note: expanded from macro 'dfprintk'
      55 | # define dfprintk(fac, ...)             no_printk(__VA_ARGS__)
         |                                                   ^~~~~~~~~~~
   include/linux/printk.h:134:18: note: expanded from macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                         ~~~    ^~~~~~~~~~~
   fs/lockd/svclock.c:202:47: error: call to undeclared function 'nlmdbg_cookie2a'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |                                                      ^
   fs/lockd/svclock.c:202:47: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
     202 |         dprintk("nlmsvc_find_block(%s): block=%p\n", nlmdbg_cookie2a(cookie), block);
         |                                    ~~                ^~~~~~~~~~~~~~~~~~~~~~~
         |                                    %d
   include/linux/sunrpc/debug.h:23:28: note: expanded from macro 'dprintk'
      23 |         dfprintk(FACILITY, fmt, ##__VA_ARGS__)
         |                            ~~~    ^~~~~~~~~~~
   include/linux/sunrpc/debug.h:55:40: note: expanded from macro 'dfprintk'
      55 | # define dfprintk(fac, ...)             no_printk(__VA_ARGS__)
         |                                                   ^~~~~~~~~~~
   include/linux/printk.h:134:18: note: expanded from macro 'no_printk'
     134 |                 _printk(fmt, ##__VA_ARGS__);            \
         |                         ~~~    ^~~~~~~~~~~

2 warnings and 2 errors generated.

vim +163 fs/lockd/svclock.c

^1da177e4c3f41 Linus Torvalds  2005-04-16  141  
^1da177e4c3f41 Linus Torvalds  2005-04-16  142  /*
d9f6eb75d49007 Trond Myklebust 2006-03-20  143   * Find a block for a given lock
^1da177e4c3f41 Linus Torvalds  2005-04-16  144   */
^1da177e4c3f41 Linus Torvalds  2005-04-16  145  static struct nlm_block *
d9f6eb75d49007 Trond Myklebust 2006-03-20  146  nlmsvc_lookup_block(struct nlm_file *file, struct nlm_lock *lock)
^1da177e4c3f41 Linus Torvalds  2005-04-16  147  {
68a2d76cea4234 Olaf Kirch      2006-10-04  148  	struct nlm_block	*block;
^1da177e4c3f41 Linus Torvalds  2005-04-16  149  	struct file_lock	*fl;
^1da177e4c3f41 Linus Torvalds  2005-04-16  150  
^1da177e4c3f41 Linus Torvalds  2005-04-16  151  	dprintk("lockd: nlmsvc_lookup_block f=%p pd=%d %Ld-%Ld ty=%d\n",
eb8ed7c6ab08cd Jeff Layton     2024-01-31  152  				file, lock->fl.c.flc_pid,
^1da177e4c3f41 Linus Torvalds  2005-04-16  153  				(long long)lock->fl.fl_start,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  154  				(long long)lock->fl.fl_end,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  155  				lock->fl.c.flc_type);
be2be5f7f44364 Alexander Aring 2023-07-20  156  	spin_lock(&nlm_blocked_lock);
68a2d76cea4234 Olaf Kirch      2006-10-04  157  	list_for_each_entry(block, &nlm_blocked, b_list) {
92737230dd3f14 Trond Myklebust 2006-03-20  158  		fl = &block->b_call->a_args.lock.fl;
^1da177e4c3f41 Linus Torvalds  2005-04-16  159  		dprintk("lockd: check f=%p pd=%d %Ld-%Ld ty=%d cookie=%s\n",
eb8ed7c6ab08cd Jeff Layton     2024-01-31  160  				block->b_file, fl->c.flc_pid,
^1da177e4c3f41 Linus Torvalds  2005-04-16  161  				(long long)fl->fl_start,
eb8ed7c6ab08cd Jeff Layton     2024-01-31  162  				(long long)fl->fl_end, fl->c.flc_type,
92737230dd3f14 Trond Myklebust 2006-03-20 @163  				nlmdbg_cookie2a(&block->b_call->a_args.cookie));
^1da177e4c3f41 Linus Torvalds  2005-04-16  164  		if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) {
6849c0cab69f5d Trond Myklebust 2006-03-20  165  			kref_get(&block->b_count);
be2be5f7f44364 Alexander Aring 2023-07-20  166  			spin_unlock(&nlm_blocked_lock);
^1da177e4c3f41 Linus Torvalds  2005-04-16  167  			return block;
^1da177e4c3f41 Linus Torvalds  2005-04-16  168  		}
^1da177e4c3f41 Linus Torvalds  2005-04-16  169  	}
be2be5f7f44364 Alexander Aring 2023-07-20  170  	spin_unlock(&nlm_blocked_lock);
^1da177e4c3f41 Linus Torvalds  2005-04-16  171  
^1da177e4c3f41 Linus Torvalds  2005-04-16  172  	return NULL;
^1da177e4c3f41 Linus Torvalds  2005-04-16  173  }
^1da177e4c3f41 Linus Torvalds  2005-04-16  174  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

Re: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error

In reply to Sean Chang

Hi Sean,

Quoted 17 lines · Sean Chang

When CONFIG_SUNRPC_DEBUG is disabled, the dfprintk() macros currently expand to empty do-while loops. This causes variables used solely within these calls to appear unused, triggering -Wunused-variable warnings.

Following David Laight's suggestion, simplify the macro definitions by removing the unnecessary 'fmt' argument and using no_printk(__VA_ARGS__) directly. This ensures the compiler performs type checking and "sees" the variables, silencing the warnings without emitting any code.

Additionally, fix a build error in fs/nfsd/nfsfh.c reported by syzbot. In nfsd_setuser_and_check_port(), the variable 'buf' is conditionally defined via RPC_IFDEBUG. Since no_printk() now performs type checking, it triggers an 'undeclared identifier' error when debug is disabled. Wrap the dprintk call in an #if block to synchronize its lifecycle with 'buf', following the pattern in svc_rdma_transport.c.

Quoted 4 lines

This should have been fixed alteady, cfr.
"Re: [PATCH v3 0/3] sunrpc: Fix make W=1 build issues"?
https://lore.kernel.org/[email protected]

Quoted 25 lines
---
 fs/nfsd/nfsfh.c              | 2 ++
 include/linux/sunrpc/debug.h | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/nfsfh.c +2 -0
index ed85dd43da18..f7386fd483a6 100644
@@ -106,8 +106,10 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
        /* 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)));
+#endif
                return nfserr_perm;
        }
 
include/linux/sunrpc/debug.h +0 -0
index eb4bd62df319..cb33c7e1f370 100644

include/linux/sunrpc/debug.h do { \ · line 58

Quoted 9 lines
include/linux/sunrpc/debug.h +2 -2
@@ -52,8 +52,8 @@ do {                                                                  \
 # define RPC_IFDEBUG(x)                x
 #else
 # define ifdebug(fac)          if (0)
-# define dfprintk(fac, fmt, ...)       do {} while (0)
-# define dfprintk_rcu(fac, fmt, ...)   do {} while (0)
+# define dfprintk(fac, ...)            no_printk(__VA_ARGS__)
+# define dfprintk_rcu(fac, ...)        no_printk(__VA_ARGS__)
 # define RPC_IFDEBUG(x)
 #endif

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#6 lore raw

Re: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error

Quoted 5 lines · Geert Uytterhoeven

This should have been fixed alteady, cfr.
"Re: [PATCH v3 0/3] sunrpc: Fix make W=1 build issues"?
https://lore.kernel.org/[email protected]

Hi Geert,
Thanks for the feedback. Regarding the patch you mentioned, I've actually addressed this in the v6 series sent yesterday [1].

My v6 approach is cleaner for a few reasons:
1. Compiler Optimization: In v6, we don't need explicit IS_ENABLED(CONFIG_SUNRPC_DEBUG) checks in files like fs/nfsd/nfsfh.c. With -O2, the compiler already proves these branches are unreachable and optimizes them away automatically.

2. Eliminating Redundancy: In include/linux/sunrpc/debug.h, the patch you cited adds no_printk inside an else branch of ifdebug, which is redundant. Since no_printk already performs type checking via ##__VA_ARGS__, simply refactoring the macro is sufficient:
-# define dfprintk(fac, fmt, ...) do {} while (0)
+# define dfprintk(fac, ...) no_printk(__VA_ARGS__)

3. Reducing Stubs: This also avoids the need for extra stub functions when CONFIG_SUNRPC_DEBUG is disabled, as seen in fs/lockd/svclock.c.

This v6 series has already been reviewed by Andrew Lunn. I would appreciate it if you could take a look at the updated logic there.

[1] https://lore.kernel.org/all/[email protected]/T/#u

Best Regards,
Sean

#7 lore raw

Re: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error

CC Andy

Quoted 33 lines · Sean Chang
Quoted 4 lines · Geert Uytterhoeven

This should have been fixed alteady, cfr.
"Re: [PATCH v3 0/3] sunrpc: Fix make W=1 build issues"?
https://lore.kernel.org/[email protected]

Hi Geert,
Thanks for the feedback. Regarding the patch you mentioned, I've actually addressed this in the v6 series sent yesterday [1].

My v6 approach is cleaner for a few reasons:
1. Compiler Optimization: In v6, we don't need explicit IS_ENABLED(CONFIG_SUNRPC_DEBUG) checks in files like fs/nfsd/nfsfh.c. With -O2, the compiler already proves these branches are unreachable and optimizes them away automatically.

2. Eliminating Redundancy: In include/linux/sunrpc/debug.h, the patch you cited adds no_printk inside an else branch of ifdebug, which is redundant. Since no_printk already performs type checking via ##__VA_ARGS__, simply refactoring the macro is sufficient:

include/linux/sunrpc/debug.h +1 -1
-# define dfprintk(fac, fmt, ...)  do {} while (0)
+# define dfprintk(fac, ...)       no_printk(__VA_ARGS__)

3. Reducing Stubs: This also avoids the need for extra stub functions when CONFIG_SUNRPC_DEBUG is disabled, as seen in fs/lockd/svclock.c.

This v6 series has already been reviewed by Andrew Lunn. I would appreciate it if you could take a look at the updated logic there.

[1] https://lore.kernel.org/all/[email protected]/T/#u

Best Regards,
Sean

#8 lore raw

Re: [PATCH v5 1/2] sunrpc: simplify dfprintk macros and fix nfsd build error

Quoted 1 line · Geert Uytterhoeven

CC Andy

Thanks!

Recently Chuck updated his nfsd-next, so please rebase and resend, Cc'ing me.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v5 2/2
#10 lore raw

Re: [PATCH v5 2/2] net: macb: use ethtool_sprintf to fill ethtool stats strings

In reply to Sean Chang
Quoted 7 lines · Sean Chang

The RISC-V toolchain triggers a stringop-truncation warning when using snprintf() with a fixed ETH_GSTRING_LEN (32 bytes) buffer.

Convert the driver to use the modern ethtool_sprintf() API from linux/ethtool.h. This removes the need for manual snprintf() and memcpy() calls, handles the 32-byte padding automatically, and simplifies the logic by removing manual pointer arithmetic.

This can go separately from patch 1. Dunno why this is a series...

And this one LGTM,

Signature · 2 lines
With Best Regards,
Andy Shevchenko