Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2207624imu; Tue, 6 Nov 2018 10:39:58 -0800 (PST) X-Google-Smtp-Source: AJdET5frImpxf7l7nBg5/q8Rc2WGmtpRE30P4RBIjfX6svHwJRIvnJ49kTPDUlx/LA/htE7FELz0 X-Received: by 2002:a62:6801:: with SMTP id d1-v6mr27283152pfc.7.1541529598314; Tue, 06 Nov 2018 10:39:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541529598; cv=none; d=google.com; s=arc-20160816; b=n4DBJbIpg3IFRtawWyietEV2jcspdhrAneEssjkoAqnr0VNKYQGqYAo/acD2WaAcfm HELihas2FAuwkytsDTflLoxlTxuSLax8UsrLVhXoK3BseVmwsn/NnrjZQZ4Nb+MTVL6Y E++WYGchYO3+xhRE9fS0jrs7OAFzWxTVKw5JMTdfKh5AkcDikk5sXQ6tw07rEbn4WfyH SU8YNJvzPZmsJtezgHYPwTjG8VqNDYjYDR+eb7tgj4ny++5EPgUm9P6MQMu9O29JKJbO WiwkHmCpilHiOVBirtj4+UxBj8PgYbNLIX+6gmzB39nuWZnzy11J/3Ib3IducQMo8m5G smgQ== 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 :in-reply-to:references:mime-version:dkim-signature; bh=oLO1X+nqAa14kF/ox2hW7N4LJ2zLmtf2ThCzUCMiwdU=; b=M1NsivJyy6tRZH2U33LwKnoTHB8HgYAafBqglZJytElJRHucCqudiMQdO1J+as7gT7 uvWLiLJ0sjuAsNTVFULDZ3WrDQZ2IcPysKWeSyX6qSjkpK72gqGRTyKJGbrLvL1XAZ89 xvqm3pdv01ScfT2AawkNnKIwwdJFnJVc9TO/pwFs2QVJ1tpfoaq+ff2rCplQpHlHLoWs CPe1+p/7nWQqa4xGt6RiLko4KytmLpbz22CQI6p6Rnetyfzhd+u1GlfTdzgf7OPTI/h6 pp/VQSn5RD5Wtd7tcBCSEMnyY72WQedQyTaOAOW715CJYU0KmJhnnX7FMtjSYQO0hddz EUTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mNifF26O; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y40-v6si28598541pla.391.2018.11.06.10.39.43; Tue, 06 Nov 2018 10:39:58 -0800 (PST) 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=pass header.i=@gmail.com header.s=20161025 header.b=mNifF26O; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388185AbeKGDoR (ORCPT + 99 others); Tue, 6 Nov 2018 22:44:17 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:34064 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388158AbeKGDoR (ORCPT ); Tue, 6 Nov 2018 22:44:17 -0500 Received: by mail-it1-f194.google.com with SMTP id t189-v6so11050204itf.1 for ; Tue, 06 Nov 2018 10:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oLO1X+nqAa14kF/ox2hW7N4LJ2zLmtf2ThCzUCMiwdU=; b=mNifF26OprBlTgZK9McZye3mV2U4hCEeRWsOkrLwyuGpugIK6i5eAardKowb7JCZuD mIg138Z0Kia/FWIA/hoDRRVgLiFqRFExulLsEyR+WVvuTPRUFBcI0Y3gy6WzVJb3j3Vt rPdUVgVtWIdJrW+AU+ecoFSP+2tI+bnAx5GDU9hs8d0N8128wlno5+dCjCa27a5kXA1h Zil4ijpse5oIUJH/pf9fy1ZlCvKUF79tXlWtt9lRJrGkV0u5Em5n5ifircmz++7TGKa+ Ask5nNNLLv25reSfDfAZ3xBhHDwfWbdxDPjD7gLsm7iVe+nb+JCAjQoIrBMOnWAZz62M 5ZPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oLO1X+nqAa14kF/ox2hW7N4LJ2zLmtf2ThCzUCMiwdU=; b=am4KO0z2mW+xDl+wTewwa0g5ljYiMNP//3w//NRer7fxW1SfIoO6tBJps8dVxhTxCl FEGDdfYvp59DWOStjHLGQlbt8qOaNZOCS9a6qnfFHt1vUrVZTr2JTsGJiEHxPU6Oylqe 4qOKkOp7qTI08sXUBgrtJ6hgzl3ZnsMVTB77dMcDeDzz8ATF6Js0x4oIq/08eOI2ULfB hlp4av/r4v73a9HJIqRMYSUHdPLi8hf+sUKguhQ2CjispTz4t2r5FGOpkTpk1/Ug2SUK EtKBCvVsDbp4BNyytQJK/LcxLVCxI9H2rAc7CVgbmRdoGIGLB3NGqfDzM1rsQeswoJsj dcOQ== X-Gm-Message-State: AGRZ1gIETG4MtcnqEUJ6K3awRydI59uCJQ048m5gZYTkIJ+CbhzcfCkr ZsfZ/9C7vYzC3MGyUZPwdtouAghe5ya7G3nZqsY= X-Received: by 2002:a24:5308:: with SMTP id n8-v6mr2957155itb.146.1541528268278; Tue, 06 Nov 2018 10:17:48 -0800 (PST) MIME-Version: 1.0 References: <20181105204000.129023-1-bvanassche@acm.org> <20181105131305.574d85469f08a4b76592feb6@linux-foundation.org> <1541454489.196084.157.camel@acm.org> <1541457654.196084.159.camel@acm.org> <1541462466.196084.163.camel@acm.org> <1541464370.196084.166.camel@acm.org> <1541526521.196084.184.camel@acm.org> In-Reply-To: <1541526521.196084.184.camel@acm.org> From: Alexander Duyck Date: Tue, 6 Nov 2018 10:17:36 -0800 Message-ID: Subject: Re: [PATCH] slab.h: Avoid using & for logical and of booleans To: bvanassche@acm.org Cc: linux@rasmusvillemoes.dk, Andrew Morton , LKML , Vlastimil Babka , Mel Gorman , Christoph Lameter , guro@fb.com, Pekka Enberg , David Rientjes , Joonsoo Kim , linux-mm 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 Tue, Nov 6, 2018 at 9:48 AM Bart Van Assche wrote: > > On Tue, 2018-11-06 at 09:20 -0800, Alexander Duyck wrote: > > On Mon, Nov 5, 2018 at 4:32 PM Bart Van Assche wrote: > > > > > > On Mon, 2018-11-05 at 16:11 -0800, Alexander Duyck wrote: > > > > If we really don't care then why even bother with the switch statement > > > > anyway? It seems like you could just do one ternary operator and be > > > > done with it. Basically all you need is: > > > > return (defined(CONFIG_ZONE_DMA) && (flags & __GFP_DMA)) ? KMALLOC_DMA : > > > > (flags & __GFP_RECLAIMABLE) ? KMALLOC_RECLAIM : 0; > > > > > > > > Why bother with all the extra complexity of the switch statement? > > > > > > I don't think that defined() can be used in a C expression. Hence the > > > IS_ENABLED() macro. If you fix that, leave out four superfluous parentheses, > > > test your patch, post that patch and cc me then I will add my Reviewed-by. > > > > Actually the defined macro is used multiple spots in if statements > > throughout the kernel. > > The only 'if (defined(' matches I found in the kernel tree that are not > preprocessor statements occur in Perl code. Maybe I overlooked something? You may be right. I think I was thinking of "__is_defined", not "defined". > > The reason for IS_ENABLED is to address the fact that we can be > > dealing with macros that indicate if they are built in or a module > > since those end up being two different defines depending on if you > > select 'y' or 'm'. > > From Documentation/process/coding-style.rst: > > Within code, where possible, use the IS_ENABLED macro to convert a Kconfig > symbol into a C boolean expression, and use it in a normal C conditional: > > .. code-block:: c > > if (IS_ENABLED(CONFIG_SOMETHING)) { > ... > } > > Bart. Right. Part of the reason for suggesting that is that depending on how you define "CONFIG_SOMETHING" it can actually be defined as "CONFIG_SOMETHING" or "CONFIG_SOMETHING_MODULE". I was operating under the assumption that CONFIG_ZONE_DMA wasn't ever going to be built as a module. Thanks. - Alex