lkml.org 
[lkml]   [2019]   [Dec]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] fix cast of gfp_t to ulong in __def_gfpflag_names
On Wed, Dec 04, 2019 at 06:54:25PM +0100, Luc Van Oostenryck wrote:
> The macro '__def_gfpflag_names' is used to define arrays of
> struct trace_print_flags. This structure is defined as being
> a pair of 'unsigned long' - 'const char *'.
>
> However, the macro __def_gfpflag_names is used to for GFP flags
> and thus take entries of type gfp_t (plus their name) which
> is a bitwise type, non-convertible to usual integers.
> These entries are casted to 'unsigned long' but this doesn't
> prevent Sparse to rughtfully complain:
> warning: cast from restricted gfp_t
>
> The correct way to cast a bitwise type to a normal integer
> (which is OK here) is to use '__force'.
>
> So, fix the cast by adding the '__force' required for such casts.

Ugh...
> - {(unsigned long)GFP_TRANSHUGE, "GFP_TRANSHUGE"}, \
<plenty of such>
> + {(__force ulong)GFP_TRANSHUGE, "GFP_TRANSHUGE"}, \

# operator is there for purpose; as in
#define FOO(name) {(__force unsigned long)name, #name}
with those becoming
#define __def_gfpflag_names \
FOO(GFP_TRANSHUGE), \
FOO(GFP_TRANSHUGE_LIGHT), \
etc.

\
 
 \ /
  Last update: 2019-12-05 03:09    [W:0.038 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site