lkml.org 
[lkml]   [2022]   [Jun]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH] include/uapi/linux/swab.h: add __u16 cast to __swab16 conditional
Date
From: Nick Desaulniers
> Sent: 08 June 2022 20:35
....
> The issue we're facing is more so that `ntohs` is being used in
> printf-like expressions; clang's -Wformat warns about default argument
> promotion so we need to clean up cases where smaller-than-int format
> flags are being used for promoted-to-int params. While looking at
> that, Nathan noticed that __swab16 will return either a __u16 or an
> int based on whether __HAVE_BUILTIN_BSWAP16__ is defined, which
> depends on BOTH the compiler being used and target architecture. This
> patch from Justin just cleans that up.

The 'problem' is that the (__u16) cast is likely to add an
extra '& 0xffff' instruction that is almost certainly not
required.

OTOH the lack of this masking has always been a difference between
htons() on BE and LE systems.

But clang is also being over-enthusiastic with its warnings.
IIRC varargs parameters always get integer promotion.
So if %hd ever makes sense for printf then it implies a
mask inside printf.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
\
 
 \ /
  Last update: 2022-06-10 09:21    [W:0.090 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site