Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp985165imm; Sat, 14 Jul 2018 18:51:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfVlcFpuDz5n+0MkbKvBkwTdCnPfQaIxycqsv7K88EmqO3EwR1mMpuY+50s9PfmdnoHiH7h X-Received: by 2002:a17:902:22cc:: with SMTP id o12-v6mr11589270plg.68.1531619480085; Sat, 14 Jul 2018 18:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531619480; cv=none; d=google.com; s=arc-20160816; b=ocwQrtSxYNRwYEHnYQvJNslwhT0uQwIp23t5OsuA9qYbMid0vzxQx1Kmt15YbfSglb xYpumvG3zYWEQfPupmnHCN/g/ILPZdDoatfyzKlvV/jalr43amp/+Vmfygsea7qHyDhk Zb0FT0Rq8J85nNaBoITyIz1JIylh+2aqua+1tjmBz5xyO2wmElgTbuyNWWck0IOt+N6u KG7NRgquE2UIuac64aAUiKBYWUjMpCF015ToWsajR8KSY+dCpMXKS1cT4xFZt77TZnnh 6YlDuYXFRWEvfsrlynKqSylpTPnTIJPLk/ZMc4mxqqIoD5nBIp8MhDXP6slEtgZE5nP9 439Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=7XpD6qbQsRu/9MCwId1Gu1dCBvskrl8mWMeOZWorsA0=; b=C3NFIZkflYO4FpBnTFPAVDFWCdXDHa9xS2k0+75RGh7BMt0tkxEmrgBzk3i4yeYeJA w6uKlMg50J2seqDPnnVPMqlcDaZyKJu8O+io72TDo3QyZ46VQFGHgJRHOuW8kb0uIuX5 K6b7ftwurbQW0SVIqYCC8dg0Bj++LNaORy/uQRogsP7sSBYOUlCidx+yxRTto3aCPP27 qqiPXfGlm8uliRbQVObgVp6PaB/5RxJQI06wULFgjNM+RGuq5qn2OgPNuSFrPWXq5yeN 4Gd9BpmOLmmfD8jNG80Iy0rbgjru9cagbM97Bt102yqMPD971chcLoDQ5/7Z1I6+BvCd oSwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=hkET5GiQ; dkim=fail header.i=@chromium.org header.s=google header.b=K8Znm6EP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k190-v6si26136595pge.276.2018.07.14.18.50.53; Sat, 14 Jul 2018 18:51:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=hkET5GiQ; dkim=fail header.i=@chromium.org header.s=google header.b=K8Znm6EP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732677AbeGOCKa (ORCPT + 99 others); Sat, 14 Jul 2018 22:10:30 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:41378 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731956AbeGOCKa (ORCPT ); Sat, 14 Jul 2018 22:10:30 -0400 Received: by mail-yw0-f195.google.com with SMTP id q129-v6so10290419ywg.8 for ; Sat, 14 Jul 2018 18:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=7XpD6qbQsRu/9MCwId1Gu1dCBvskrl8mWMeOZWorsA0=; b=hkET5GiQYYsSeFbvSca/Bn35CXwjaLsvDskCDWJkXPAENX5k4K400pEf39vH0B5VEC z/K3i+RVQWbA3tAerFfwwifCBaNkyje+VvXveg7R/+ZhkSE56KCnYhAhI9UbwEaai6/2 zOoVCaeNRikMNitS3CJmO0RNzCxKfXZ1yQPn4BURNEOQri2bYR9QxXDUd5YxQU7Col7g piiEnW6CLaVGrMQ5gu5W/QeiD+Cw13acCpOoeTowpKTSOCDN38AaKCqQf7O7rDH3NMNd 8hMVIWIO6ovxtYTSvZFht9Kt2aHXf9VsAP2b0js0f68o/yyEmJKEirxNC0ZisCsmaRl5 iopg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=7XpD6qbQsRu/9MCwId1Gu1dCBvskrl8mWMeOZWorsA0=; b=K8Znm6EPVeqjKZPNfgXJuMuk07Mvw2u9nrTsg2exnpqCM4darl5woJKPzYULODbvjR 08au7YzmPw3mZtEnGj9LLmJWxZqZO1+TGEUoxmA9bAXZUI4rB19IjWaADy4wBDreixSr eqnU5L1o1LljciO+TohPniGloxB3Pt8EX/HKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=7XpD6qbQsRu/9MCwId1Gu1dCBvskrl8mWMeOZWorsA0=; b=D76BqQGB+VanStr7GsgY4/Nfr10jrq8x6BQg+ohSFUAYb9YDEzBvmdJT2NN8qmWYQI VKb26nSNaDxmA1ezKKC32ceoWBQ8UP4QXVSydZ9iNMN4PiPVt4teF/t6GTFvtzmCY4dX PtLwvVQiVEmxT/w9OuvwQ16h8pAFwPrhhaEl+zibJm1yT1kaJwDcWM75z3FcW5B4q3gG iYrPqDR3E1i+UZO3XbBNSZIY8t4sFIZRBRSDV/MOjmX7rm/akzIscQnvwLLz2fNLSZ3f unkMRjP+PQIljdRZl4iJR1LvzhTdRIR3YG0RsO3EzIhl+kRoRG6NxKr0flhRVjZJGY3j dD5w== X-Gm-Message-State: AOUpUlGMuOsirffmJCtKYpNFUT7VhOeWeBLwg/73dENmSfc7BU4fLhza 7M3JnAFR1h0WkRd9YAs8mzGAUqjyArDUMp4klKT1RA== X-Received: by 2002:a0d:e2cd:: with SMTP id l196-v6mr5705907ywe.38.1531619364867; Sat, 14 Jul 2018 18:49:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a25:6602:0:0:0:0:0 with HTTP; Sat, 14 Jul 2018 18:49:24 -0700 (PDT) In-Reply-To: <20180705161709.17028-1-bart.vanassche@wdc.com> References: <20180705161709.17028-1-bart.vanassche@wdc.com> From: Kees Cook Date: Sat, 14 Jul 2018 18:49:24 -0700 X-Google-Sender-Auth: jLGmqQNtZjy5pJ7GFKlkuwIC-6c Message-ID: Subject: Re: [PATCH] kernel.h: Avoid that sparse complains about using sizeof(void) To: Bart Van Assche , Linus Torvalds Cc: LKML , Martin Uecker , Ingo Molnar , Miguel Ojeda , "# 3.4.x" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 5, 2018 at 9:17 AM, Bart Van Assche wrote: > The macro __is_constexpr() causes sparse to report the following: > > warning: expression using sizeof(void) > > Avoid this by using __builtin_constant_p() instead. > > Fixes: 3c8ba0d61d04 ("kernel.h: Retain constant expression output for max()/min()") > Signed-off-by: Bart Van Assche > Cc: Linus Torvalds > Cc: Martin Uecker > Cc: Kees Cook > Cc: Ingo Molnar > Cc: Miguel Ojeda > Cc: > --- > include/linux/kernel.h | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h > index d23123238534..a9f0d0d48971 100644 > --- a/include/linux/kernel.h > +++ b/include/linux/kernel.h > @@ -811,13 +811,19 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } > #define __typecheck(x, y) \ > (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) > > +#ifndef __CHECKER__ > /* > * This returns a constant expression while determining if an argument is > * a constant expression, most importantly without evaluating the argument. > - * Glory to Martin Uecker > + * Glory to Martin Uecker . However, this > + * macro causes sparse to report the warning "expression using sizeof(void)". > + * Hence use __builtin_constant_p() instead when using sparse. > */ > #define __is_constexpr(x) \ > (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) > +#else > +#define __is_constexpr(x) __builtin_constant_p((x)) > +#endif > > #define __no_side_effects(x, y) \ > (__is_constexpr(x) && __is_constexpr(y)) I'm fine with this; it'll only activate for sparse. I'd like to get Linus's eyes on it, though, since this macro caused us SO much pain that I'm nervous to change it without some greater level of review. :) Acked-by: Kees Cook Thanks! -Kees -- Kees Cook Pixel Security