Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1658966imu; Tue, 6 Nov 2018 02:09:00 -0800 (PST) X-Google-Smtp-Source: AJdET5fejnUx3OOU4sOJkJLJrg0VcD9tJHhNpCxQ07EW6Gc3oTYcTXjQI15kTC4NArlUbschFjk2 X-Received: by 2002:a62:d58a:: with SMTP id d132-v6mr10641137pfg.103.1541498940085; Tue, 06 Nov 2018 02:09:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541498940; cv=none; d=google.com; s=arc-20160816; b=cxdzcnH5etr9K5nT+0wlT2aPxTgHJ1abrCO48DRw4KwzJybIqolnDiVrlKuLufLcY/ MLNB92VE2dynvECDcUmhacxPRCnlHW8Kzlj40WSfbddb4d5mc/P2DF8Q0Cqd+/PsvUxA hlqoBKYS8zbUJALIL4FYujjIxWniOvTqk0niuziKf6Vvj067BAKVtx9K/c9Jx1iUMK2Z Thg4qQOch3m8ujBJRDfihGmWyA4IvU2K5vzsQ7yvXEGtpd2sCzP5eFhAnh2ee1iJJThM sz4BzTq0GbqO5+yxq7gfD7M3N7r4/HrcTe6LbauCX3X6ct5jCQ/auFtYD7A/XEk2Rprd JZ4A== 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 :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=GMelerImah8wr3F0C/fdQUr+56tyTurYgQ8rU3/bwWQ=; b=lgBH3RMFSHGRDTZW25frdQ6ITMzOViIh1epH0Qffqhou+TnvwarN1Zs/03bodgvPN/ IOS5f/rLTXbpV83SELMUn0A73XaTisEPGNT/UePMLngUvziF/kqK2tAdRf6Q4tTS6Cs2 twkIa3FeyFTa/l7PlT6UU03zx9eMt4u4X/Exc8zuTA3XRhREL4O43myXtVHkBo4pZsan LTWttLwPtYRz0SWQX5FMlZQ5Sxt92zs4GO9IVt8UkTnrb5a/Xd2wg10y1ouIcR3MOOGk tyVXJPIot4hqgyEOi9IhgVI7ccCaZyEG8W8NoJwE0d90k04V4UDHgYs7JUUQZqyGcJ/J bl3w== 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 h2-v6si30993675plh.157.2018.11.06.02.08.44; Tue, 06 Nov 2018 02:09:00 -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 S2387739AbeKFTcv convert rfc822-to-8bit (ORCPT + 99 others); Tue, 6 Nov 2018 14:32:51 -0500 Received: from eu-smtp-delivery-151.mimecast.com ([146.101.78.151]:53788 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387480AbeKFTcv (ORCPT ); Tue, 6 Nov 2018 14:32:51 -0500 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by dkim.mimecast.com with ESMTP id uk-mta-5-pdxC1B2ZMQ-NsC89g71rTA-1; Tue, 06 Nov 2018 10:08:20 +0000 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 6 Nov 2018 10:08:26 +0000 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 6 Nov 2018 10:08:26 +0000 From: David Laight To: 'Bart Van Assche' , Andrew Morton CC: "linux-kernel@vger.kernel.org" , "Vlastimil Babka" , Mel Gorman , "Christoph Lameter" , Roman Gushchin Subject: RE: [PATCH] slab.h: Avoid using & for logical and of booleans Thread-Topic: [PATCH] slab.h: Avoid using & for logical and of booleans Thread-Index: AQHUdUfJjxPqMWIPVkCDxWbeIJk+/6VCg0ZQ Date: Tue, 6 Nov 2018 10:08:26 +0000 Message-ID: <62188a351f2249188ce654ee03c894b1@AcuMS.aculab.com> References: <20181105204000.129023-1-bvanassche@acm.org> In-Reply-To: <20181105204000.129023-1-bvanassche@acm.org> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-MC-Unique: pdxC1B2ZMQ-NsC89g71rTA-1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche > Sent: 05 November 2018 20:40 > > This patch suppresses the following sparse warning: > > ./include/linux/slab.h:332:43: warning: dubious: x & !y > > Fixes: 1291523f2c1d ("mm, slab/slub: introduce kmalloc-reclaimable caches") > Cc: Vlastimil Babka > Cc: Mel Gorman > Cc: Christoph Lameter > Cc: Roman Gushchin > Signed-off-by: Bart Van Assche > --- > include/linux/slab.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/slab.h b/include/linux/slab.h > index 918f374e7156..97d0599ddb7b 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -329,7 +329,7 @@ static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags) > * If an allocation is both __GFP_DMA and __GFP_RECLAIMABLE, return > * KMALLOC_DMA and effectively ignore __GFP_RECLAIMABLE > */ > - return type_dma + (is_reclaimable & !is_dma) * KMALLOC_RECLAIM; > + return type_dma + is_reclaimable * !is_dma * KMALLOC_RECLAIM; ISTM that changing is_dma and is_reclaimable from int to bool will stop the bleating. It is also strange that this code is trying so hard here to avoid conditional instructions and then uses several to generate the boolean values in the first place. OTOH I'd probably write: int gfp_dma = 0; #ifdef CONFIG_ZONE_DMA gfp_dma = __GFP_DMA; #endif return flags & gfp_dma ? KMALLOC_DMA : flags & __GFP_RECLAIMABLE ? KMALLOC_RECLAIM : 0; That might generate cmovs, but is may be better to put unlikely() around both conditional expressions. Or redo as: return !unlikely(flags & (dfp_dma | __GFP_RECLAIMABLE)) ? 0 : flags & gfp_dma ? KMALLOC_DMA : KMALLOC_RECLAIM; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)