Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1208551ybi; Fri, 2 Aug 2019 11:09:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAYRiIc11GsckI+XJ/PmM7SBk/4MkfivBaCzpYeuylUN1bo5SVjOn1DSxHwuWk6Huglh2K X-Received: by 2002:a65:458d:: with SMTP id o13mr123599696pgq.34.1564769394203; Fri, 02 Aug 2019 11:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564769394; cv=none; d=google.com; s=arc-20160816; b=cdeF4pbrRpPqH16XQFAUECdAaVmOBNdtG06OaziDScrkl57iRDFmcf9LhLo+ZrqzBR XA7uTcNgs2BtFvYDUf0I/tE4WHP3G11tHx9PyqCA47tjDiquwM6pstOqz2KB7LBKGxHM RkjEw4wBdMHaH/LUxUgiErQ/lEwDo9Qmp+dhjN/8pjPN+HO7xi4rn2v+c3lYLYxoGTVA /SSomKz4EU5hdgHbH5wF5iN6vTvF8Mk9Wbecn0eEOFD6RcVLh8qMQ8R+rsqEuS3cmwOu vlbTHhuY68bxfTNLUGfbGypfP9LjBYfoCbCPE4mAp25vLv2m9cDcGrE+l057zRqJ3Y4i ze3Q== 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=nFnw66Q8fJzXCoC9cpQsk6hCyBTYRdcWNvNm6bgB4sk=; b=IRLzTunS+N4+kCejpRO4ZZGY17aDUYLb8c9FtpShIPks9Z1DhZWPcfnV/AYnZCLTpT mVPeE/nCJQIIBGQoSQFZdh82kbueJsmmQL+2x/sWgEw7RT+6I1zAuXyHHUf27QWuad3X bezuTqPIciNOhVpEhQFVS0X0uEsSoFdDtnNJV/8tP1GOUDTuKpv1EEzQdGSgX1CCeSOc qo4WO+AWTmdXpuYVmomXCQulp7lDxFgcG88dpOsfcAvVDrETmS23phFtuV+GfoEeKjMk mg0JdjpJ5AoWce7Lrwv8BcW1apXzol/pWNT8xsjNnswjKM92Kdi/wM/NJCbAyPCAz7nb 037w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yDJkTTpS; 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 w12si35385900plq.92.2019.08.02.11.09.38; Fri, 02 Aug 2019 11:09:54 -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=yDJkTTpS; 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 S2392203AbfHBJwR (ORCPT + 99 others); Fri, 2 Aug 2019 05:52:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:57780 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405459AbfHBJwO (ORCPT ); Fri, 2 Aug 2019 05:52:14 -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 19CCB206A2; Fri, 2 Aug 2019 09:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564739533; bh=5QHtL0XNAjyJtuF2bZOQbdAb4gdb/YztsPUiD+UjgXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yDJkTTpSuiV+trDLZJzhok2pMfVIVtrFUiJJ7VaH5YWxIgN9SQX/PuCMCZBR0s9f6 3ZjNHJmGLslCtjsuraVbFpUx6l7qencAyuL+jx+00X9OjHsS84vULCQG1A0d8/dXUW Ebjc4YU4ph1VFR59b2wyZ1zztFaZKttyPTJE4CI8= 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 4.9 179/223] iio: iio-utils: Fix possible incorrect mask calculation Date: Fri, 2 Aug 2019 11:36:44 +0200 Message-Id: <20190802092249.313005775@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802092238.692035242@linuxfoundation.org> References: <20190802092238.692035242@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 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