Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2172830imm; Sat, 16 Jun 2018 11:06:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLlqpSiWmPn3L8c5DDGDR+NA3zF1Fy31Po8PQuuyrglaUcxUIC9bin1Xe51luWGdwrms33v X-Received: by 2002:a17:902:76c4:: with SMTP id j4-v6mr7343663plt.19.1529172368187; Sat, 16 Jun 2018 11:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529172368; cv=none; d=google.com; s=arc-20160816; b=fxDXNs/eHrEsjBkMyG3kFa1F3L1xT4C9dNETB8sAHeSPFPcUBI0d2xTd0+CbQJKiDb UtLKvBb54RfjnvjJiz1vx11BLAZbd1omGnkrATrrq9+xCz9+YkTZUzGeFgmApz8w1V84 8wFd4xUGU7cd+DW7vw2ZFmCRRvCk6CpiyqC17SwAzrvhXmpHwWhcT18mh0NjH+MsCno1 RicIMPqfzRgFy60Ov6ZKqQfl27jpMjuIAWL5LVWaDXUg3puPF4V54EMKggy1gkJN66re C4GjDXmMDr1m6SDuNzm3Db3Audt1KGrcge+jA6HmI1sZeyDDvAPELF9Go08TpMsGASqr WjpQ== 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:arc-authentication-results; bh=dD/hYcRP3xbuzBj6X7aVw0X7fCIx/ByZrTA4L8+MgDc=; b=0NOzo6ByGuQ+YQ4eaxayqZy2dGrirljfUdzgJiqpUq/8jK35c2XNvwjidd4iemGaCK uoWJ8OSOlo7ZmYxlawqDrmjDDgEETxqc7YPPWRIPmA0IeUotvfB/oSU7P2pPN+DdfNLQ 4/NFVlD7rdNIX9XIA4cnPJY+a3+GtEZleen7MjIS389L2C70Vaw+tPVrbLOWqv2FxJzL 6VjzLt2daD8nLcY39xa9F33MJ0CfsWsEb+fLhgjN74ykSeaneK8LzD6zBrKFygl+gY1O RN8iXbM4Z5x1f5VNzSX8m/sxo1gWY1WE+2vMWj97GccxG4exdUMvA+gfURT5ujBjgGsu pe/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AFyJmKUL; 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 c125-v6si8336866pga.413.2018.06.16.11.05.52; Sat, 16 Jun 2018 11:06:08 -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=AFyJmKUL; 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 S1756547AbeFPSF3 (ORCPT + 99 others); Sat, 16 Jun 2018 14:05:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:42394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752587AbeFPSF1 (ORCPT ); Sat, 16 Jun 2018 14:05:27 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 074BF2087E; Sat, 16 Jun 2018 18:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529172327; bh=16LoKHHZ3Y20F+neKHN1J3a/5E5tr6koIyufwGiWbXQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=AFyJmKULKTpiIkEBBmdxutUE3Ge0gRwsojJJUYNFjEk3qhV+Ec1ZZPfR6OWoC4YkJ XxsVzTQnuaNbO9bumaJ6PlPJy2fplSIUvaLeIGZu0o1ivDHk6Zvvj5Qi8ScuufrIei 8zV1DCEWwd1oNu9yep1f2KyrN9omwluhwElz/3lg= Date: Sat, 16 Jun 2018 19:05:20 +0100 From: Jonathan Cameron To: Karim Eshapa Cc: lars@metafoo.de, Michael.Hennerich@analog.com, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging:iio:accel:adis16203: sign extend function rather code duplication Message-ID: <20180616190520.7996a010@archlinux> In-Reply-To: <20180612164838.22961-1-karim.eshapa@gmail.com> References: <20180612164838.22961-1-karim.eshapa@gmail.com> X-Mailer: Claws Mail 3.16.0 (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 Tue, 12 Jun 2018 18:48:38 +0200 Karim Eshapa wrote: > Use sign_extend32 kernel function instead of code duplication. > This function is also safe for 16 bits. > > Signed-off-by: Karim Eshapa Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > drivers/staging/iio/accel/adis16203.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/drivers/staging/iio/accel/adis16203.c b/drivers/staging/iio/accel/adis16203.c > index b3e4571340ab..5cc96c8086b5 100644 > --- a/drivers/staging/iio/accel/adis16203.c > +++ b/drivers/staging/iio/accel/adis16203.c > @@ -168,7 +168,6 @@ static int adis16203_read_raw(struct iio_dev *indio_dev, > { > struct adis *st = iio_priv(indio_dev); > int ret; > - int bits; > u8 addr; > s16 val16; > > @@ -202,14 +201,11 @@ static int adis16203_read_raw(struct iio_dev *indio_dev, > *val = 25000 / -470 - 1278; /* 25 C = 1278 */ > return IIO_VAL_INT; > case IIO_CHAN_INFO_CALIBBIAS: > - bits = 14; > addr = adis16203_addresses[chan->scan_index]; > ret = adis_read_reg_16(st, addr, &val16); > if (ret) > return ret; > - val16 &= (1 << bits) - 1; > - val16 = (s16)(val16 << (16 - bits)) >> (16 - bits); > - *val = val16; > + *val = sign_extend32(val16, 13); > return IIO_VAL_INT; > default: > return -EINVAL;