RE: [PATCH v2] afs: use correct format characters

From: David Laight
Date: Fri Apr 12 2019 - 11:47:14 EST


From: Nick Desaulniers
> Sent: 10 April 2019 23:52
> On Wed, Apr 10, 2019 at 3:41 PM Louis Taylor <louis@xxxxxxxxxx> wrote:
> >
> > When compiling with -Wformat, clang warns:
> >
> > fs/afs/flock.c:632:29: warning: format specifies type 'short' but the argument has type
> > 'unsigned char' [-Wformat]
> > _leave(" = %d [%hd]", ret, fl->fl_type);
> > ~~~ ^~~~~~~~~~~
> >
> > fs/afs/dir.c:138:11: warning: format specifies type 'unsigned short' but
> > the argument has type 'int' [-Wformat]
> > ntohs(dbuf->blocks[tmp].hdr.magic));
> > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > fl_type is declared as an unsigned char unconditionally in
> > include/linux/fs.h, so use the correct format characters.
>
> Thanks for the v2, probably should include a note about ntohs. That
> case in particular looks more complicated, due to the definition of
> ntohs (which uses __swab16).
>
> If you keep the previous flag of %04hx, but add an explicit cast to
> u16, does the warning go away? If so, that might be a better fix.
>
> - ntohs(dbuf->blocks[tmp].hdr.magic));
> + (u16)ntohs(dbuf->blocks[tmp].hdr.magic));

Or just append '+ 0u' forcing the type to 'unsigned int'.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)