Thread (30 messages) 30 messages, 8 authors, 2018-03-14

Re: [PATCH v3] kernel.h: Skip single-eval logic on literals in min()/max()

flat view

From: Kees Cook <hidden>
Date: 2018-03-13 04:28:57
Also in: lkml

On Mon, Mar 12, 2018 at 4:57 PM, Linus Torvalds
[off-list ref] wrote:
On Mon, Mar 12, 2018 at 3:55 PM, Andrew Morton
[off-list ref] wrote:
quoted
Replacing the __builtin_choose_expr() with ?: works of course.
Hmm. That sounds like the right thing to do. We were so myopically
staring at the __builtin_choose_expr() problem that we overlooked the
obvious solution.

Using __builtin_constant_p() together with a ?: is in fact our common
pattern, so that should be fine. The only real reason to use
__builtin_choose_expr() is if you want to get the *type* to vary
depending on which side you choose, but that's not an issue for
min/max.
This doesn't solve it for -Wvla, unfortunately. That was the point of
Josh's original suggestion of __builtin_choose_expr().

Try building with KCFLAGS=-Wval and checking net/ipv6/proc.c:

net/ipv6/proc.c: In function ‘snmp6_seq_show_item’:
net/ipv6/proc.c:198:2: warning: ISO C90 forbids array ‘buff’ whose
size can’t be evaluated [-Wvla]
  unsigned long buff[SNMP_MIB_MAX];
  ^~~~~~~~


-Kees

-- 
Kees Cook
Pixel Security
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help