From patchwork Tue Nov 4 10:58:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime COQUELIN X-Patchwork-Id: 40125 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1DACD240A6 for ; Tue, 4 Nov 2014 10:59:12 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf3835105wiv.10 for ; Tue, 04 Nov 2014 02:59:11 -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=lDo7STynHtIcULlHwszgIQWFoxJ8UgfYVmzX7yfgfqQ=; b=kwAJWZyEbKreljztS9R68jaoIAOCvr3Hai1vk2N/ASq8imB9TKt9OZ1rqnjviy29M2 rUNoPQXW5wcHQ9a18hEhqlMpSp6EotawjJEbssynVqsdWrqhugsrJ8hvev3ZoeLkY3yW JH2do3ViXPOdCOZJw4VKQyPnltd4bCXBneK2JKVx9/JzLd5bxbKTBK+Ci+DS1oMjC2Au nag551OrWeDcCWHIqCgDDQUUi8sWORkbqSfunqlEjF/WxG6vMdE1SYC2e6wHgbRmTxVi WhSQcEopEFeUCDgv4L2PdJpADeIf5pywaII0bWzNLCiRLNs2gODb+GPhixaSySj+hC5K cv8w== X-Gm-Message-State: ALoCoQlvGivFSB0KNc83XFQVC5M7tmRUW6WYJZHNpd+xtM0mSmOKlIC+c9FZOltIzwV8GuV+QRoG X-Received: by 10.194.242.36 with SMTP id wn4mr454785wjc.4.1415098751328; Tue, 04 Nov 2014 02:59:11 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.103 with SMTP id l7ls585089laf.6.gmail; Tue, 04 Nov 2014 02:59:11 -0800 (PST) X-Received: by 10.152.21.199 with SMTP id x7mr23028011lae.66.1415098751168; Tue, 04 Nov 2014 02:59:11 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id wm6si129935lbb.49.2014.11.04.02.59.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 02:59:11 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id s18so651664lam.28 for ; Tue, 04 Nov 2014 02:59:11 -0800 (PST) X-Received: by 10.152.29.8 with SMTP id f8mr58407492lah.56.1415098751057; Tue, 04 Nov 2014 02:59:11 -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.184.201 with SMTP id ew9csp96581lbc; Tue, 4 Nov 2014 02:59:10 -0800 (PST) X-Received: by 10.68.246.229 with SMTP id xz5mr9486074pbc.131.1415098749352; Tue, 04 Nov 2014 02:59:09 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id uv6si17561120pbc.255.2014.11.04.02.59.08 for ; Tue, 04 Nov 2014 02:59:09 -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 S1751553AbaKDK7H (ORCPT + 1 other); Tue, 4 Nov 2014 05:59:07 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:35801 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750727AbaKDK7G (ORCPT ); Tue, 4 Nov 2014 05:59:06 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.14.5/8.14.5) with SMTP id sA4AdKYp016001; Tue, 4 Nov 2014 11:58:28 +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 1qeqj01kpc-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 04 Nov 2014 11:58:28 +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 20FE326; Tue, 4 Nov 2014 10:58:22 +0000 (GMT) Received: from mail7.sgp.st.com (unknown [164.129.223.81]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id D3EA83F; Tue, 4 Nov 2014 10:58:19 +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 BZR62656 (AUTH lme00137); Tue, 4 Nov 2014 11:58:09 +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 v3] bitops: Fix shift overflow in GENMASK macros Date: Tue, 4 Nov 2014 11:58:17 +0100 Message-Id: <1415098697-16304-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-04_05:2014-11-03, 2014-11-04, 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.215.41 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 Suggested-by: Peter Zijlstra Signed-off-by: Maxime Coquelin --- include/linux/bitops.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index be5fd38..c2ce66c 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -18,8 +18,11 @@ * 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 - ((h) - (l) + 1))) << (l)) + +#define GENMASK_ULL(h, l) \ + ((~0ULL >> (BITS_PER_LONG_LONG - ((h) - (l) + 1))) << (l)) extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w);