Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3117932ybi; Thu, 18 Jul 2019 21:22:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyewYjSu+XzjQ3hJ0/fc/UZGLAsHWNCI/Gk80tS3FcKzH1NtTgTQhuoOt0phA3T3ofaTwS3 X-Received: by 2002:a65:620a:: with SMTP id d10mr6293231pgv.8.1563510146234; Thu, 18 Jul 2019 21:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563510146; cv=none; d=google.com; s=arc-20160816; b=zdARVxIRkc4Pystv8g+EvPCywyOgkZlN5jhcP+aZaVnV9DVJ0sJDcElZu068G/plDc IKi7SGfK2Ivzp5STO0EIMztH0Ct+tM7J9yVRA/jx9gvdDMwXpagMpRuCRbUk+Qxy9Gf+ u1NCA2ocCrpJvua66fgDivNd9n88ofaktWu0f8/2CA73AD7vyLL1D5qbT2hkaozY4Tfd 80+vodzK25KYaMf1KoulvtZ4xFShj1p8QZ+plHSvKNDdYXxFrF6/WSIV70b68DKJ2qbL QTgsuhRQUz5yFki7I/6gxgl/PLu6h2p0AN4o3g6hv4fqLV7X9pHWgS9RCuaHTYT2QTH+ ZPkg== 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:message-id:date:subject:cc:to:from :dkim-signature; bh=0hAhtFZQyE/UK9bOO8/X+G6KqwhzhsiQkG4NfvKFAzA=; b=yMHdLckV8FeEl8pF1GOgErSZ9wLKBBiH7yaLAI3lD8+fYh1TqLo3362yr1L4UZK8eT GzvrA0dtTOXd5PfnaXneJ7L1jwDnLUqatyg1UFtdMKSwslS3hS93Xsup/AMwDrxSbZBO 3eVRnXEmIeX7NgCDfGPm3UKMLqCUDjDawu1Hf6eMSJNqpdVdPK0qbdTXhiuCERCizX4H rDrk0C1hj9ZDgN4IbCrcUsBM0rXtGenAidU3gkG7fhYI/2m8opx3pwfypNYn/3WD4iQb 28NvCY9zMBGFQCIa+pBCONcJrzby2lgDKSZPqK2CO+Uv0vcqdKsOqfvXQegJY8lSfuHC tcmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FqqvpKgB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si476164pfh.218.2019.07.18.21.22.10; Thu, 18 Jul 2019 21:22:26 -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=@kernel.org header.s=default header.b=FqqvpKgB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388554AbfGSEVS (ORCPT + 99 others); Fri, 19 Jul 2019 00:21:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:47262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388653AbfGSEMF (ORCPT ); Fri, 19 Jul 2019 00:12:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DD19E21873; Fri, 19 Jul 2019 04:12:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509524; bh=iZ67JdgCIuYaVGiGuIHDqG7PjRoM2Dbn3bbUpNl2z/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FqqvpKgB5fkuNSFugf/VFASx2vTNBrFsKqC1rLceKNxss8OIGFs74MtJut7k5ER/h Ye3KWTZe1mAHnzjRG+tR+MeBwFmI7NFS+BtLAH/aOUF8UhGf0ZYW2/jaqWr9fwnIVQ ZGeb8uADpPt4RUgnCA/OKvwPx3dWQxU9EUl+DadY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bastien Nocera , Jonathan Cameron , Sasha Levin , linux-iio@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 30/60] iio: iio-utils: Fix possible incorrect mask calculation Date: Fri, 19 Jul 2019 00:10:39 -0400 Message-Id: <20190719041109.18262-30-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719041109.18262-1-sashal@kernel.org> References: <20190719041109.18262-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bastien Nocera [ Upstream commit 208a68c8393d6041a90862992222f3d7943d44d6 ] On some machines, iio-sensor-proxy was returning all 0's for IIO sensor values. It turns out that the bits_used for this sensor is 32, which makes the mask calculation: *mask = (1 << 32) - 1; If the compiler interprets the 1 literals as 32-bit ints, it generates undefined behavior depending on compiler version and optimization level. On my system, it optimizes out the shift, so the mask value becomes *mask = (1) - 1; With a mask value of 0, iio-sensor-proxy will always return 0 for every axis. Avoid incorrect 0 values caused by compiler optimization. See original fix by Brett Dutro in iio-sensor-proxy: https://github.com/hadess/iio-sensor-proxy/commit/9615ceac7c134d838660e209726cd86aa2064fd3 Signed-off-by: Bastien Nocera Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- tools/iio/iio_utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c index 7a6d61c6c012..55272fef3b50 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -159,9 +159,9 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used, *be = (endianchar == 'b'); *bytes = padint / 8; if (*bits_used == 64) - *mask = ~0; + *mask = ~(0ULL); else - *mask = (1ULL << *bits_used) - 1; + *mask = (1ULL << *bits_used) - 1ULL; *is_signed = (signchar == 's'); if (fclose(sysfsfp)) { -- 2.20.1