Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3571749ybg; Mon, 28 Oct 2019 15:10:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4bwFDuuwEqTe1vFuGntrtuFGA6swj7ve7H5hSXt4tSuigsMKn1jlU7dEe1HVjJo0CTu5r X-Received: by 2002:a50:f40c:: with SMTP id r12mr22338710edm.50.1572300632914; Mon, 28 Oct 2019 15:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572300632; cv=none; d=google.com; s=arc-20160816; b=F17Pzedn91i+Imk/0sDd9eYKYY/pyPIBT/MvBkXCuQUAR2HJX1BVeQdQcdgijBT/v9 sAx6bbaSn1CMCSLMH9pLNJH3z30Gv5FbrKbWqKoPjyVWOBSRhqWjrDD8Gt/65UvCCcpe leacPxTCSfPp4yQ/Iz9pmIBGxJwBko9j0gL2IuBxW4N0DFMCyyVtfesSsQPuZZRA62vf lf/orGS5DOZyJ7pyF7QOSvAL+lQQ9KV+ThAowRQsU6AhyL2D+7EZrE9tiw7AGtTfDVHK +Noxy50N05NkCx4VLE2VN+aKE/z0HnzwwSQA1O1hGzXl5etdCJRnsBZcHnO9Qy9JQIRB YJIQ== 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:date:subject:cc:to:from; bh=1oBXLCEA6bDkeKywgn+CtEH0L7iMtQpOWpVW8yEPhC8=; b=B8i/ojwEdHCQQGZQgj3B4suWJHH5RtLVZSk+nlX7tJK4Wpl4muXLhxyeif6pHz2kok WKYrNQjojHAQjR/mzRTM5IlWdShgWxKsCMWsUa75oOJfD+EFdxcp11ha27s1BiC4Hvcg F6mzZBej0GoiTOkHw3E18jz7r/rJf1BkMmDAZvle2db/2iXXYEg2WSkmKwhCeuCO3gKJ W527fVtpMOB6m1gIRkufKmOJMwfHZBxo5d89FZadiduGAoGJmW+eQsSw1Hqa5+kddNlV /fJhy+9Yd33R8PMxMfRzm/nMQByPAAdsIrqHy76uOCLIUVwEmQaCVH6Bk74sO95Jnya/ CTuw== ARC-Authentication-Results: i=1; mx.google.com; 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 t16si6764217ejd.435.2019.10.28.15.10.09; Mon, 28 Oct 2019 15:10:32 -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; 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 S1732336AbfJ1UHS (ORCPT + 99 others); Mon, 28 Oct 2019 16:07:18 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41832 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732221AbfJ1UHP (ORCPT ); Mon, 28 Oct 2019 16:07:15 -0400 Received: by mail-pg1-f194.google.com with SMTP id l3so7651843pgr.8; Mon, 28 Oct 2019 13:07:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1oBXLCEA6bDkeKywgn+CtEH0L7iMtQpOWpVW8yEPhC8=; b=pZozOzvz5TipYCS9/zypTBWWMRY54LS7opQOiX6Esqx/bj3O2l7qz6FbxN+2QuK/8X aoUvy52Y4n3ktCunLan/FbPfF/BLN4UJse43ZKQVqtvZbhCwxwpqUun4AW/LQdjYnNHZ YejYl0VufjXXNnOSbOXjfJ/kccc21sW3uViFATXMqe/1Nkyd+jfiPGgzkn2MrPVd75Vu aofHNlHd7rmPQRyRKZ0kK3v9jyhSGNsrKc6ZRXP24MHeGm0tb2L27v9UmNyqXprqDpHg RzFMPr22Rax16MeNP6lKwYEA7bjN05NVo9C3iguh0PfCdCARoC3Mb8sPoyRWybly1i6Q JRCQ== X-Gm-Message-State: APjAAAVchpEhbnnUkC254jCJImMiDnxR5RbH4/PgfoQFeCVf11420uIS YXxBBye4FXic5+W3Qj9VPKo= X-Received: by 2002:aa7:8046:: with SMTP id y6mr21932294pfm.222.1572293234040; Mon, 28 Oct 2019 13:07:14 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id p3sm11084218pgp.41.2019.10.28.13.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 13:07:13 -0700 (PDT) From: Bart Van Assche To: Peter Zijlstra Cc: Ingo Molnar , Thomas Gleixner , Christoph Hellwig , "Martin K . Petersen" , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Bart Van Assche , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Subject: [PATCH 4/9] drivers/iio: Sign extend without triggering implementation-defined behavior Date: Mon, 28 Oct 2019 13:06:55 -0700 Message-Id: <20191028200700.213753-5-bvanassche@acm.org> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191028200700.213753-1-bvanassche@acm.org> References: <20191028200700.213753-1-bvanassche@acm.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 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); -- 2.24.0.rc0.303.g954a862665-goog