Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1875210imm; Sat, 18 Aug 2018 06:19:18 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzA16TDPW9vsgUz+YikKP7rVG15HWqdt8QdasxJFtpMr+cG3FBVP5IAZ1W6LjksMvCKWQfd X-Received: by 2002:a63:d74f:: with SMTP id w15-v6mr36796323pgi.306.1534598358031; Sat, 18 Aug 2018 06:19:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534598358; cv=none; d=google.com; s=arc-20160816; b=pLMIX0LVweuSfJVca+Zj8fJt4EM7KH7dupzZR+Tcd+sTYfj6I4jzPASeTMNLAxuwhq +hJk8gfN40xQ1dDD1uI6z1yqxukaPBqiR7egWbluOiXyNx3fOZjJZRj4ehBVy65lVSTh hGhcnjQ8iYyXthYnUge0dXW1U7bF8ycOVnXBhYbvyJJiH17Ev/iFRS3rq5LUmLYfBZPq W40QGwm0mcprL9hvkHxf6eQLJr7UWnj4dQtbpM0AZ9xMjuvLX6YUj30dV/IhMvW4ERgv +d2lfKcOi3qpwLBYjmnkQHKe0f3e69oxarHLwhB+DvxfGvbbgm9+wB6YAOGotOpgBZSl zNEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Wv1XY51Lt2VJ9i95LO5VL5gr0Ba9AoWtqEVbo4MHCzo=; b=wjegSskEgOV+SgI2/1TOeMCRNDDLB56TdBIhTkI5vV1HVUWc/ow9wgBjDgJ4yJCiUJ kxutKHZAuvPbnhEFcCLIjDqWuJmtHVokbPaJDLkFXTZ2jIPugemnHIIDypqVVE0d5JN5 c3NpHMwzAT8XBzlScM2msT/ASYCKs49l+fo6tYH2V0GMWOi0rvb9tl3BJlwVO3UdXf92 5yO7xl1w7AHcyRFx1fBf3LcRsekYRp5VJ3ha3MF7QTnc3NlIcgoqEmBF6r8rO72xUeuE W4T/7PGpeG1p8Fqjs1CNPW7FGMeE13mJ9koosJozIPVaOskm///+U16J4nXR/JHCxhbM c67g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=PAsIvIBN; 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 196-v6si5036769pgh.55.2018.08.18.06.19.02; Sat, 18 Aug 2018 06:19:18 -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=pass header.i=@rasmusvillemoes.dk header.s=google header.b=PAsIvIBN; 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 S1726417AbeHRQYN (ORCPT + 99 others); Sat, 18 Aug 2018 12:24:13 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:34076 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbeHRQYM (ORCPT ); Sat, 18 Aug 2018 12:24:12 -0400 Received: by mail-ed1-f68.google.com with SMTP id h1-v6so5981205eds.1 for ; Sat, 18 Aug 2018 06:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Wv1XY51Lt2VJ9i95LO5VL5gr0Ba9AoWtqEVbo4MHCzo=; b=PAsIvIBNF1eghipQDa5XMNIzoDXoFWVMhVHzG7cnlURC1hEJ1RpOosAUNn9f9u5Xdv 2pY+nVWrVp33U9zRvT0vDqF0LFZPccMcyAuc6yshATP7FpCCOmft+2frBVP/A1oJGqx0 oMrscnrfA0du144r3FVf0gnHSj+9Jyyna9NEI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Wv1XY51Lt2VJ9i95LO5VL5gr0Ba9AoWtqEVbo4MHCzo=; b=JRvoEFjH5F1CU6A5e+3rlnowbO/gtP+rllQbvEycQDM2Q4H4nG5inyF6qxsNxOvZRL vSRbhjS2TM5fSqyMXYeDbdxvQhDwqag1UBlIRXVz4qNP0bVb39OUioYg1aG3IlsrDJqO n/WqvVggu3mrf4ZwqWVjIN6LCjNkhpNvw++otvO453bDRZEbmQCXRzywTcgnJH1Ts/BT AIHA2UZr8AjHY1p/V/HD8bS5fB0yUDfVkQJ8gpVgYpRBVenaYEhVjMFX8OK6S88dZS02 l1SxEihgvpX4JKvgRp2nGxC6L+nwCvQz9K2e+x3yhxt3H4HfKsdCWUGCEbZpj92vxdNQ Q8Cg== X-Gm-Message-State: AOUpUlEmH8CDhBQl2Q5LVyq7ZYTl2pdaRGMkJ5cht9n2z5C7lzPHWNQw jDjLO8eLc1bellGWxuVQBlB+eQ== X-Received: by 2002:a50:e0c9:: with SMTP id j9-v6mr46920228edl.198.1534598190183; Sat, 18 Aug 2018 06:16:30 -0700 (PDT) Received: from prevas-ravi.waoo.dk (dhcp-5-186-114-212.cgn.ip.fibianet.dk. [5.186.114.212]) by smtp.gmail.com with ESMTPSA id r11-v6sm2821403edp.60.2018.08.18.06.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Aug 2018 06:16:29 -0700 (PDT) From: Rasmus Villemoes To: Andrew Morton , Yury Norov Cc: Andy Shevchenko , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: [PATCH 2/7] linux/bitmap.h: handle constant zero-size bitmaps correctly Date: Sat, 18 Aug 2018 15:16:18 +0200 Message-Id: <20180818131623.8755-3-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180818131623.8755-1-linux@rasmusvillemoes.dk> References: <20180818131623.8755-1-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The static inlines in bitmap.h do not handle a compile-time constant nbits==0 correctly (they dereference the passed src or dst pointers, despite only 0 words being valid to access). I had the 0-day buildbot chew on a patch [1] that would cause build failures for such cases without complaining, suggesting that we don't have any such users currently, at least for the 70 .config/arch combinations that was built. Should any turn up, make sure they use the out-of-line versions, which do handle nbits==0 correctly. This is of course not the most efficient, but it's much less churn than teaching all the static inlines an "if (zero_const_nbits())", and since we don't have any current instances, this doesn't affect existing code at all. [1] lkml.kernel.org/r/20180815085539.27485-1-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes --- include/linux/bitmap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 1ee46f492267..b91a6b5d3e78 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -196,8 +196,13 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf, #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) +/* + * The static inlines below do not handle constant nbits==0 correctly, + * so make such users (should any ever turn up) call the out-of-line + * versions. + */ #define small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) + (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0) static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { -- 2.16.4