Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2186070imu; Tue, 6 Nov 2018 10:19:16 -0800 (PST) X-Google-Smtp-Source: AJdET5esj7TPzUL9oNBB1Vy2+9kwGAyAmRYkrXc+NGikog9MdYOwZxmAsckTr70BaRo6CHoqnHVb X-Received: by 2002:a63:86c2:: with SMTP id x185mr22831009pgd.230.1541528355990; Tue, 06 Nov 2018 10:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541528355; cv=none; d=google.com; s=arc-20160816; b=Raf6WkSq3I5DdlKluUNviOKPvbDYSucdxi64Tb58NgT28mAxBYIqXjcoh7FlrDD5K1 r8u/KhT8l1FqD2ejNwmW7WliEAK28D94hjhhAaa/PXGF/PvRqsDUKD572BYmiqswD8iU 46mzh2JY+q5XcxD8Nfca1vJhg1aOPAWnbcfJ39hs00l7boYQM+4pht7D5uyUkaqVpidq h+4k+EsMqJytVRbiwCGJgI8fYDRSKYBiyYAtOo6nIGf03eDZvJY8htD1dcrXdWKujznu N8gMS3g3R8k3tHL1knx1DgagxQLT67jAlC6dYm8k3pT9rTtCJlpkTgXHW5/PDSlyf4EW u22A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=1X++K30qlocAaocdfUugyzmpdC+vrNZ6Xh46RqadmCM=; b=Qy+mA7CVgxCuGlontElRUDtHaMWsZvvmbDXDoMYHaQoznZL0W8uMN1pQauCpD9MI96 V5/ixcC95HQGzqXdf8vzW5uT7TF1tLvYfDZAq0kseeOwFtGIFL3Ror0AwdnrAPhIGOuX 1lL1ncxo7q9QEr9P18O/GZcFQK9bKhlid6Uik36X6XiW18/6slc7lUH6twbS0SXlkfAu B6v5FEb+/rfJE7wDYl6Ph+KGJignEUUWSMvwcwltqOMzefI9DXLu7V5XlJ4AFVgnmDmm SVcOdUeKhfLM8PdmNeYZEoawKlwTMfde51FgW1SmDmXKZmvXTWgEYIuX8SVbJJ1jXWaI SBjw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7-v6si527525pgj.116.2018.11.06.10.19.00; Tue, 06 Nov 2018 10:19:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389769AbeKGDPE (ORCPT + 99 others); Tue, 6 Nov 2018 22:15:04 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42660 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389573AbeKGDPE (ORCPT ); Tue, 6 Nov 2018 22:15:04 -0500 Received: by mail-pg1-f194.google.com with SMTP id i4-v6so6128548pgq.9 for ; Tue, 06 Nov 2018 09:48:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=1X++K30qlocAaocdfUugyzmpdC+vrNZ6Xh46RqadmCM=; b=cJVeTFkSHcqistFCtlDmYQ+vPwzGfeTA+s/CEcHOoUJbwZUL2j5Av1u9p6UqlqB88O GeiMrADVKmeosob5MuLYl57N7wtjjQNdbsIPBk0uvKuXZ8cyiZPEMccOL3bNahCuPkce qp7xcvsHcWMQnNsAm/Mercn4IzdLG4Tgzkj/m82Kf2wnEQklsks4SoYF9dHlLzC+vlOL wKPSMloC4TuNYFXeBK44f5qHs9HwHY6/fbRkSJ3eZZu7kQhjVHxkfyG4SCscgp8v4RBu euWg9z0CKT/nRGXJXy2ToMbMHOmbme04GVITV6akHR+leqAjP3C/NawpwgiIqpgcpR9O JCqw== X-Gm-Message-State: AGRZ1gLUyaLiTGYHN54G/feBw1LlHOrUw51K4PcA1soF69nF+guykHyf IuNLoPjQFLshEi4PdB+eMy4= X-Received: by 2002:a62:995c:: with SMTP id d89-v6mr26898974pfe.11.1541526523366; Tue, 06 Nov 2018 09:48:43 -0800 (PST) Received: from ?IPv6:2620:15c:2cd:203:5cdc:422c:7b28:ebb5? ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id g3-v6sm31281642pgr.40.2018.11.06.09.48.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 09:48:42 -0800 (PST) Message-ID: <1541526521.196084.184.camel@acm.org> Subject: Re: [PATCH] slab.h: Avoid using & for logical and of booleans From: Bart Van Assche To: Alexander Duyck Cc: linux@rasmusvillemoes.dk, Andrew Morton , LKML , Vlastimil Babka , Mel Gorman , Christoph Lameter , guro@fb.com, Pekka Enberg , David Rientjes , Joonsoo Kim , linux-mm Date: Tue, 06 Nov 2018 09:48:41 -0800 In-Reply-To: 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> Content-Type: text/plain; charset="UTF-7" X-Mailer: Evolution 3.26.2-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-11-06 at 09:20 -0800, Alexander Duyck wrote: +AD4 On Mon, Nov 5, 2018 at 4:32 PM Bart Van Assche +ADw-bvanassche+AEA-acm.org+AD4 wrote: +AD4 +AD4 +AD4 +AD4 On Mon, 2018-11-05 at 16:11 -0800, Alexander Duyck wrote: +AD4 +AD4 +AD4 If we really don't care then why even bother with the switch statement +AD4 +AD4 +AD4 anyway? It seems like you could just do one ternary operator and be +AD4 +AD4 +AD4 done with it. Basically all you need is: +AD4 +AD4 +AD4 return (defined(CONFIG+AF8-ZONE+AF8-DMA) +ACYAJg (flags +ACY +AF8AXw-GFP+AF8-DMA)) ? KMALLOC+AF8-DMA : +AD4 +AD4 +AD4 (flags +ACY +AF8AXw-GFP+AF8-RECLAIMABLE) ? KMALLOC+AF8-RECLAIM : 0+ADs +AD4 +AD4 +AD4 +AD4 +AD4 +AD4 Why bother with all the extra complexity of the switch statement? +AD4 +AD4 +AD4 +AD4 I don't think that defined() can be used in a C expression. Hence the +AD4 +AD4 IS+AF8-ENABLED() macro. If you fix that, leave out four superfluous parentheses, +AD4 +AD4 test your patch, post that patch and cc me then I will add my Reviewed-by. +AD4 +AD4 Actually the defined macro is used multiple spots in if statements +AD4 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? +AD4 The reason for IS+AF8-ENABLED is to address the fact that we can be +AD4 dealing with macros that indicate if they are built in or a module +AD4 since those end up being two different defines depending on if you +AD4 select 'y' or 'm'. From Documentation/process/coding-style.rst: Within code, where possible, use the IS+AF8-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+AF8-ENABLED(CONFIG+AF8-SOMETHING)) +AHs ... +AH0 Bart.