Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4083656ybi; Mon, 29 Jul 2019 18:54:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhXLdJ6jlFKiQInVdcRqOhb+v5Vo/OL5V0MAbuzKKNR0qMEpr2+QUgsg54NPKXlOrrR5SH X-Received: by 2002:a17:90a:d343:: with SMTP id i3mr119552409pjx.15.1564451688918; Mon, 29 Jul 2019 18:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564451688; cv=none; d=google.com; s=arc-20160816; b=oCe+RN0yDD8apgBYWV6zGVZ4yAMtEfe7rOPtTj7bwMIuOXEjB7hxL12gh825SfspQW Se15su/8Vv5S2qdLn6v3Rl5D3CjC4klmB+12sveSeQ7hEFdXz3Cp+JT8cmlbMe+BWaQi AtH1SDbHZvAkBVbXbdiFw6g7Jgok87vz7g6yoJv5AFemO/aH06/tlagm6PF8wIiqzRia IexiuNh6oLCiO34O6GD2FlQhUH7RaxUf9+lmpD8/+o5CrwNyK2a92w9ePHAgKbUTmzEk 6WdpTW0DLyLlCKcfkd5djFxCkDMwoLe3i2k/358GzjscKe619/KKr0O8Jg0TPx6nmYcG 5OwQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F70DYVZs3e5o1PjsTX7YjdDgWZ7NO8yInfVFIfeub9w=; b=k+1Lzwz+t1+uNvTGRjTdjOIe03+MN4IQS36G0K5uyefR0vqw7LfxluvbziiLGKeurC ZIVZHpk7h+00jMWiU6jla3dpiSxRe/EB0XWo5WIKdcB/CFl1EdxjFd3QoCxykrjDOTtF o4GKkjJ0XsGb2ikc5GGR816DvjOx8SBNgbQQrsB0c8FK/CGVIo//k5PRRDLnJcyfHQf6 Uf5AEs5XGwK99cxajgYG0JbCG24pDpI0R7CYEY2gLBUVjcBfyX/l6mo/b4Y32i8WsFu3 iE5YJORg+s8suQAzwQS7Qvd4UKZFJRfpT6WxIZU4PxRZCP0EQfy+tEHX8Y0NGHOl55aS go0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="XLCFZ/2B"; 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 o8si28243270pgj.239.2019.07.29.18.54.34; Mon, 29 Jul 2019 18:54:48 -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="XLCFZ/2B"; 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 S2390529AbfG2TtZ (ORCPT + 99 others); Mon, 29 Jul 2019 15:49:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:39898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728749AbfG2TtX (ORCPT ); Mon, 29 Jul 2019 15:49:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 609952171F; Mon, 29 Jul 2019 19:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429762; bh=JjSn7E8NOcXhxNkF6xu/DWhQxbmtqDQN5Q/q+1angIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XLCFZ/2Bj5YB+Am0egIwCdvbQLRWNNOAjzYvf/EaGYCM+d2bEALE4pIj8zyLeeLQb BQAiPY1+ywACXMmmDW3yN0OUMQ9MVKk1ZzVUIUd5esItNU9QqxWGI4kCLyxDJhjcjz 9daetLb1JfiCI0TCBAwbVwWHwr7/BgCZjaL0oW0s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bastien Nocera , Jonathan Cameron , Sasha Levin Subject: [PATCH 5.2 088/215] iio: iio-utils: Fix possible incorrect mask calculation Date: Mon, 29 Jul 2019 21:21:24 +0200 Message-Id: <20190729190754.684061423@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 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 [ 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 a22b6e8fad46..7399eb7f1378 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -156,9 +156,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