Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp159938ybx; Wed, 30 Oct 2019 12:58:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZeqUYhpqdAuAmCb0udEEKIF3N3riRxkpskr8J68+8qd9iYT9ExkVqks/hIaXlhXYPoe3b X-Received: by 2002:a50:b6e1:: with SMTP id f30mr1704453ede.212.1572465514718; Wed, 30 Oct 2019 12:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572465514; cv=none; d=google.com; s=arc-20160816; b=PadAYPGfRL6bO1/zmvbBPTekW2UJBcn67un0zQs57Z2Dj9nku/+oGN3auhRvuJWuzz bdydEceI6mDkCXkv1YF9M0vavaxTU/XcbrAqNe/83HfOMCdoDpbKMWYkD0ktP3h/Rtw6 ELhmGA4LGfKZQJDxtyxlvHCOAcdQxPLthdhFTduIEHjYxUIMOm9FX9hUsVDmc2GQRI3h 1dfsDHntWFwh9jRdaNsixqpoiz6IfFyeEGH4nlQ91E6ZHVKXQVKQ+Pd8SdwWOBMdUtIq hPDlsMqOVqxKq7FyIqfgXyrivqDEWj+g7qp9wtdlncwcAX8NMVlJizFwNdG5vAECrnPJ krug== 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:subject:cc:to:from:date :dkim-signature; bh=U9AgRc2n19Y0XEl4ADe++EwViKLtAApXB4lCuBgDMMg=; b=uAShqsfQi8U3k+463y72qdZdDmW/FmsMcsWI3AF5Xyh0wsLNW8kPMv6e0lSYUNq0Gs peZr0HYpFWKaEbGlwy8kt63MJqocA3yyAC4TnpfzAzbgpsvl28WwIkO88MMWjzV1j1CR BdlkGt9D5O8RA/Of7dcVcVSxOaYhgR9m2hEhwQULQqTZ9so3wkmGH0FM5a+O5HFKPOd2 VqpwhwlUVMmQ7fC2Ve9037ZTT3qhwSiaeM4snqKaFDWp0u0wZCD+DYx/B3SZCuNZ0IJb pydn1InNLzunG722XKcgeiYBiBfZjkMwfBiOr+ZlIExK+oCt0rQhQtUdEvG+DAYoqgbE kk2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qhMfLygR; 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 p15si2432546edi.27.2019.10.30.12.58.08; Wed, 30 Oct 2019 12:58:34 -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=qhMfLygR; 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 S1726472AbfJ3Tne (ORCPT + 99 others); Wed, 30 Oct 2019 15:43:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:35244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfJ3Tne (ORCPT ); Wed, 30 Oct 2019 15:43:34 -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 E6997205C9; Wed, 30 Oct 2019 19:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572464613; bh=SvrbAEw49Plnafe/VzNSWq8FLiN2PZsNxZj5PIYPCAQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qhMfLygR9U7KoGtM2N9i/dXW6g1ijNGhj7Oz//aFnrSyQHID47A0Xju37huThLgpU h2ojTqe8N+JdKsUkmDhwMG6UVR57UeaIW3J+7nW8m+arNodehDgUpxDiZMAUYkY6hF qhqdix6PJKUna/ZSbL6CNrR4Cu4Vn9z04ds/n3uw= Date: Wed, 30 Oct 2019 19:43:25 +0000 From: Jonathan Cameron To: Bart Van Assche Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Christoph Hellwig , "Martin K . Petersen" , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org Subject: Re: [PATCH 4/9] drivers/iio: Sign extend without triggering implementation-defined behavior Message-ID: <20191030194325.2ad20a8e@archlinux> In-Reply-To: <20191028200700.213753-5-bvanassche@acm.org> References: <20191028200700.213753-1-bvanassche@acm.org> <20191028200700.213753-5-bvanassche@acm.org> X-Mailer: Claws Mail 3.17.4 (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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 28 Oct 2019 13:06:55 -0700 Bart Van Assche wrote: > From the C standard: "The result of E1 >> E2 is E1 right-shifted E2 bit > positions. If E1 has an unsigned type or if E1 has a signed type and a > nonnegative value, the value of the result is the integral part of the > quotient of E1 / 2E2 . If E1 has a signed type and a negative value, the > resulting value is implementation-defined." > > Hence use sign_extend_24_to_32() instead of "<< 8 >> 8". +CC linux-iio > > Cc: Jonathan Cameron > Cc: Hartmut Knaack > Cc: Lars-Peter Clausen > Cc: Peter Meerwald-Stadler > Signed-off-by: Bart Van Assche > --- > drivers/iio/common/st_sensors/st_sensors_core.c | 7 +------ > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c > index 4a3064fb6cd9..94a9cec69cd7 100644 > --- a/drivers/iio/common/st_sensors/st_sensors_core.c > +++ b/drivers/iio/common/st_sensors/st_sensors_core.c > @@ -21,11 +21,6 @@ > > #include "st_sensors_core.h" > > -static inline u32 st_sensors_get_unaligned_le24(const u8 *p) > -{ > - return (s32)((p[0] | p[1] << 8 | p[2] << 16) << 8) >> 8; > -} > - > int st_sensors_write_data_with_mask(struct iio_dev *indio_dev, > u8 reg_addr, u8 mask, u8 data) > { > @@ -556,7 +551,7 @@ static int st_sensors_read_axis_data(struct iio_dev *indio_dev, > else if (byte_for_channel == 2) > *data = (s16)get_unaligned_le16(outdata); > else if (byte_for_channel == 3) > - *data = (s32)st_sensors_get_unaligned_le24(outdata); > + *data = get_unaligned_signed_le24(outdata); > > st_sensors_free_memory: > kfree(outdata);