[PATCH v2] nfsd: use correct format characters

Bill Wendling posted 1 patch 4 years, 3 months ago
fs/nfsd/flexfilelayout.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] nfsd: use correct format characters
Posted by Bill Wendling 4 years, 3 months ago
When compiling with -Wformat, clang emits the following warnings:

fs/nfsd/flexfilelayout.c:120:27: warning: format specifies type 'unsigned
char' but the argument has type 'int' [-Wformat]
                         "%s.%hhu.%hhu", addr, port >> 8, port & 0xff);
                             ~~~~              ^~~~~~~~~
                             %d
fs/nfsd/flexfilelayout.c:120:38: warning: format specifies type 'unsigned
char' but the argument has type 'int' [-Wformat]
                         "%s.%hhu.%hhu", addr, port >> 8, port & 0xff);
                                  ~~~~                    ^~~~~~~~~~~
                                  %d

The types of these arguments are unconditionally defined, so this patch
updates the format character to the correct ones for ints and unsigned
ints.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Bill Wendling <morbo@google.com>
---
v2 - Fixed "Link" to be a valid URL.
---
 fs/nfsd/flexfilelayout.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/nfsd/flexfilelayout.c b/fs/nfsd/flexfilelayout.c
index 2e2f1d5e9f62..070f90ed09b6 100644
--- a/fs/nfsd/flexfilelayout.c
+++ b/fs/nfsd/flexfilelayout.c
@@ -117,7 +117,7 @@ nfsd4_ff_proc_getdeviceinfo(struct super_block *sb, struct svc_rqst *rqstp,
 
 	da->netaddr.addr_len =
 		snprintf(da->netaddr.addr, FF_ADDR_LEN + 1,
-			 "%s.%hhu.%hhu", addr, port >> 8, port & 0xff);
+			 "%s.%d.%d", addr, port >> 8, port & 0xff);
 
 	da->tightly_coupled = false;
 
-- 
2.35.1.723.g4982287a31-goog
Re: [PATCH v2] nfsd: use correct format characters
Posted by Chuck Lever III 4 years, 3 months ago

> On Mar 17, 2022, at 2:42 PM, Bill Wendling <morbo@google.com> wrote:
> 
> When compiling with -Wformat, clang emits the following warnings:
> 
> fs/nfsd/flexfilelayout.c:120:27: warning: format specifies type 'unsigned
> char' but the argument has type 'int' [-Wformat]
>                         "%s.%hhu.%hhu", addr, port >> 8, port & 0xff);
>                             ~~~~              ^~~~~~~~~
>                             %d
> fs/nfsd/flexfilelayout.c:120:38: warning: format specifies type 'unsigned
> char' but the argument has type 'int' [-Wformat]
>                         "%s.%hhu.%hhu", addr, port >> 8, port & 0xff);
>                                  ~~~~                    ^~~~~~~~~~~
>                                  %d
> 
> The types of these arguments are unconditionally defined, so this patch
> updates the format character to the correct ones for ints and unsigned
> ints.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Signed-off-by: Bill Wendling <morbo@google.com>
> ---
> v2 - Fixed "Link" to be a valid URL.

Hi Tom, can I get a Reviewed-by from you?


> ---
> fs/nfsd/flexfilelayout.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/nfsd/flexfilelayout.c b/fs/nfsd/flexfilelayout.c
> index 2e2f1d5e9f62..070f90ed09b6 100644
> --- a/fs/nfsd/flexfilelayout.c
> +++ b/fs/nfsd/flexfilelayout.c
> @@ -117,7 +117,7 @@ nfsd4_ff_proc_getdeviceinfo(struct super_block *sb, struct svc_rqst *rqstp,
> 
> 	da->netaddr.addr_len =
> 		snprintf(da->netaddr.addr, FF_ADDR_LEN + 1,
> -			 "%s.%hhu.%hhu", addr, port >> 8, port & 0xff);
> +			 "%s.%d.%d", addr, port >> 8, port & 0xff);
> 
> 	da->tightly_coupled = false;
> 
> -- 
> 2.35.1.723.g4982287a31-goog
> 

--
Chuck Lever