From patchwork Mon Nov 3 17:39:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime COQUELIN X-Patchwork-Id: 40062 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B467E20560 for ; Mon, 3 Nov 2014 17:40:54 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id w7sf1223851lbi.4 for ; Mon, 03 Nov 2014 09:40:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=qqKTvzXWDF3pOikTNahT7cyszLbcCPYKTI8Ogo1UdQE=; b=fp4glp030L2xzLEy4jlOEoabGVPCA0KrqJ3/C1/Ga/lek6k9yb5WgzUKYOvmP5oVt7 V/4XQ47Js/H8tm2ShsTUkXfvS+uJhvlP/zBSwpVQVKJRlUjZ/2gmO5YoAz/igmyU/adz vO8OzJ+WKshbVr8dd8hJjxbq2t1hJeYztC8yfVNxnuzQ+lccDb5M429zvolye2+Xg71n ENsJIQrY6IYr3Si4O8y7yYwAuXe6jl1dlWSBo33hfMT1rbMA9RGCrP8+OJ6qCbu0xC4B a4u9IWeyHeCTqIL538/Aq/2X26iloYIQDKNCUW4nQa4jOeVqUQvmNlbxkqjra/tYDoI3 tbwA== X-Gm-Message-State: ALoCoQnoiWCI07UkGAMuGd2yrGwhHJ06QPCY7C8syQFYbELo8oaxJa9vnqG34UCzobKZ01StaYWl X-Received: by 10.180.72.141 with SMTP id d13mr3148464wiv.6.1415036453499; Mon, 03 Nov 2014 09:40:53 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.5 with SMTP id a5ls771784lae.19.gmail; Mon, 03 Nov 2014 09:40:53 -0800 (PST) X-Received: by 10.152.19.133 with SMTP id f5mr51753908lae.87.1415036453339; Mon, 03 Nov 2014 09:40:53 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id uc5si33434723lbb.31.2014.11.03.09.40.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Nov 2014 09:40:53 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id z12so1308326lbi.15 for ; Mon, 03 Nov 2014 09:40:53 -0800 (PST) X-Received: by 10.112.130.41 with SMTP id ob9mr51756058lbb.74.1415036453179; Mon, 03 Nov 2014 09:40:53 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.141.34 with SMTP id rl2csp28611lbb; Mon, 3 Nov 2014 09:40:52 -0800 (PST) X-Received: by 10.70.35.229 with SMTP id l5mr44120695pdj.47.1415036451670; Mon, 03 Nov 2014 09:40:51 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kt8si15716432pdb.238.2014.11.03.09.40.51 for ; Mon, 03 Nov 2014 09:40:51 -0800 (PST) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752413AbaKCRku (ORCPT + 1 other); Mon, 3 Nov 2014 12:40:50 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:39791 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752340AbaKCRkt (ORCPT ); Mon, 3 Nov 2014 12:40:49 -0500 Received: from pps.filterd (m0046670.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.14.5/8.14.5) with SMTP id sA3HZLCj032033; Mon, 3 Nov 2014 18:40:07 +0100 Received: from beta.dmz-us.st.com (beta.dmz-us.st.com [167.4.1.35]) by mx07-00178001.pphosted.com with ESMTP id 1qcs6sa4pf-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 03 Nov 2014 18:40:07 +0100 Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 282F826; Mon, 3 Nov 2014 17:40:03 +0000 (GMT) Received: from mail7.sgp.st.com (unknown [164.129.223.81]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id A4B90B1; Mon, 3 Nov 2014 17:40:01 +0000 (GMT) Received: from lmecul0520.lme.st.com (lmecul0520.lme.st.com [10.201.23.80]) by mail7.sgp.st.com (MOS 4.3.3-GA) with ESMTP id BZR62377 (AUTH lme00137); Mon, 3 Nov 2014 18:39:51 +0100 From: Maxime COQUELIN To: gong.chen@linux.intel.com, Peter Zijlstra , Ingo Molnar , " Paul E. McKenney" , tytso@mit.edu, linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: kernel@stlinux.com, maxime.coquelin@st.com, eric.paire@st.com Subject: [PATCH] bitops: Fix shift overflow in GENMASK macros Date: Mon, 3 Nov 2014 18:39:58 +0100 Message-Id: <1415036398-26984-1-git-send-email-maxime.coquelin@st.com> X-Mailer: git-send-email 1.9.1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52, 1.0.28, 0.0.0000 definitions=2014-11-03_02:2014-11-03, 2014-11-03, 1970-01-01 signatures=0 Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxime.coquelin@st.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On some 32 bits architectures, including x86, GENMASK(31, 0) returns 0 instead of the expected ~0UL. This is the same on some 64 bits architectures with GENMASK_ULL(63, 0). This is due to an overflow in the shift operand, 1 << 32 for GENMASK, 1 << 64 for GENMASK_ULL. Fixes: 10ef6b0dffe404bcc54e94cb2ca1a5b18445a66b Cc: #v3.13+ Reported-by: Eric Paire Signed-off-by: Maxime Coquelin --- include/linux/bitops.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index be5fd38..81f9725 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -18,8 +18,12 @@ * position @h. For example * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. */ -#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l)) -#define GENMASK_ULL(h, l) (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l)) +#define GENMASK(h, l) \ + ((~0UL >> ((BITS_PER_LONG - 1) - (h))) & ~((1UL << (l)) - 1)) + +#define GENMASK_ULL(h, l) \ + ((~0ULL >> ((BITS_PER_LONG_LONG - 1) - (h))) & ~((1ULL << (l)) - 1)) + extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w);