lkml.org 
[lkml]   [2022]   [Aug]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH 1/3] modpost: fix TO_NATIVE() with expressions and consts
On Thu, Aug 18, 2022 at 01:53:04PM +0200, Alexander Lobakin wrote:
> Macro TO_NATIVE() directly takes a reference to its argument @x
> without making an intermediate variable. This makes compilers
> emit build warnings and errors if @x is an expression or a deref
> of a const pointer (when target Endianness != host Endianness):
>
> >> scripts/mod/modpost.h:87:18: error: lvalue required as unary '&' operand
> 87 | __endian(&(x), &(__x), sizeof(__x)); \
> | ^
> scripts/mod/sympath.c:19:25: note: in expansion of macro 'TO_NATIVE'
> 19 | #define t(x) TO_NATIVE(x)
> | ^~~~~~~~~
> scripts/mod/sympath.c:100:31: note: in expansion of macro 't'
> 100 | eh->e_shoff = t(h(eh->e_shoff) + off);
>
> >> scripts/mod/modpost.h:87:24: warning: passing argument 2 of '__endian'
> discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
> 87 | __endian(&(x), &(__x), sizeof(__x)); \
> | ^~~~~~
> scripts/mod/sympath.c:18:25: note: in expansion of macro 'TO_NATIVE'
> 18 | #define h(x) TO_NATIVE(x)
> | ^~~~~~~~~
> scripts/mod/sympath.c:178:48: note: in expansion of macro 'h'
> 178 | iter < end; iter = (void *)iter + h(eh->e_shentsize)) {

How come this hasn't shown up in cross-builds today?


>
> Create a temporary variable, assign @x to it and don't use @x after
> that. This makes it possible to pass expressions as an argument.
> Also, do a cast-away for the second argument when calling __endian()
> to avoid 'discarded qualifiers' warning, as typeof() preserves
> qualifiers and makes compilers think that we're passing pointer
> to a const.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@vger.kernel.org # 4.9+

Where are these build warnings showing up at that we don't see them
today, yet this is needed to go back to all stable trees?

still confused,

greg k-h

\
 
 \ /
  Last update: 2022-08-18 14:26    [W:1.064 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site