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=-12.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 autolearn=ham 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 692BAC48BE4 for ; Thu, 27 Jun 2019 19:38:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26E9E20B7C for ; Thu, 27 Jun 2019 19:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561664326; bh=fiwmCE6GCb6TF6KF/QxYIB81jrEtg/6+MmofeaLxQ7M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=cHmKNiarHhM2TQ91gMS7D2P/hLTAmkmUhVikv+zfoJIQ9JmZTQ0/jF2Mt8n0gZ4rB TruKab1pyVooPLQyypFRINpvavIzA8KyWcpH6D0lD5DiM5UUJA5OfY+7AoDNNAlK/0 7PiK8D1TdS89MEyJB9CTnQ1eJg3FFrC3/fMpLAg0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726484AbfF0Tip (ORCPT ); Thu, 27 Jun 2019 15:38:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:48284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfF0Tip (ORCPT ); Thu, 27 Jun 2019 15:38:45 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 0CF3720665; Thu, 27 Jun 2019 19:38:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561664324; bh=fiwmCE6GCb6TF6KF/QxYIB81jrEtg/6+MmofeaLxQ7M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GEhONFXlClLLfF1SkNmCwqyS0jKnNmLvFg37edRwSjBlP9H8yZGAvV+uHawvbh4C8 0QhKr+fHowf1bptuKZOo1vQo8jvsvxmORpsQEpCPoq/G53IHVIDVubvopByzycHA2y f6XymkJo/xPoVABZBW0FJxMszS2Dke+dZ11cvMZ8= Date: Thu, 27 Jun 2019 20:38:40 +0100 From: Jonathan Cameron To: Bastien Nocera Cc: linux-iio@vger.kernel.org Subject: Re: [PATCH v2] iio: iio-utils: Fix possible incorrect mask calculation Message-ID: <20190627203840.75328b15@archlinux> In-Reply-To: <8b5ad111c555eb548c4f3da6d55e426a15ebf59b.camel@hadess.net> References: <8b5ad111c555eb548c4f3da6d55e426a15ebf59b.camel@hadess.net> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Thu, 27 Jun 2019 09:20:45 +0200 Bastien Nocera wrote: > 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 Applied to the togreg branch of iio.git. thanks, Jonathan > --- > 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)) { >