From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3811C76196 for ; Fri, 19 Jul 2019 04:16:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7436321873 for ; Fri, 19 Jul 2019 04:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509791; bh=lubXuxwygME8x4y6Ygu0b8VBQMGO9MrPhG1pQyoiVqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=oFAuR1pr16QsouH7Q4Qmesp/uA2iLRk3UOcLtcEiDrUglPZhsDQuovFedO2YDRwag 03lDkdvSXZTup+DAaJG51pFAHcogaG9zM4hX9c3XlWzk7zQldLsKmckw0silXrv+jZ yGkTUCCyypWuWHYfmQe0gjfyz6sAtgFZ6Gi7ZygM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389966AbfGSEPC (ORCPT ); Fri, 19 Jul 2019 00:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:51282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389941AbfGSEO6 (ORCPT ); Fri, 19 Jul 2019 00:14:58 -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 6F24D21873; Fri, 19 Jul 2019 04:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509698; bh=lubXuxwygME8x4y6Ygu0b8VBQMGO9MrPhG1pQyoiVqY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y/INPsOXU7YqrNmJ7BuU1mfuADraz690aydaalMfQIvO0NJexrxkebxR7GheKd7LQ bWhnyK0YeR33RgI/s8A4rc4YBouav+LEUprfIHLMTddeJ9lNii/sJP1Icpt+iesqu0 nJgTUvSJ5avaC2ov7pmp6bcf1Nkj3S9nJUaYtu8M= 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.4 18/35] iio: iio-utils: Fix possible incorrect mask calculation Date: Fri, 19 Jul 2019 00:14:06 -0400 Message-Id: <20190719041423.19322-18-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719041423.19322-1-sashal@kernel.org> References: <20190719041423.19322-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@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 5eb6793f3972..2d0dcd6fc64c 100644 --- a/tools/iio/iio_utils.c +++ b/tools/iio/iio_utils.c @@ -163,9 +163,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