Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2170375imm; Sat, 16 Jun 2018 11:03:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIGao1e8w0xKD7X4nYHbH8ydCruQVGpegTcilg6TSi4pQlD+yE+Z7YIrkpcay9EtQzK0CTe X-Received: by 2002:a17:902:1081:: with SMTP id c1-v6mr7392005pla.153.1529172190886; Sat, 16 Jun 2018 11:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529172190; cv=none; d=google.com; s=arc-20160816; b=Mxm6XT/7Orq5afj4yv9wLteNCSh++4JnXeCNLZAPTIeXFbtqeRkdYlxzzsZKLVFTGY DkmqZ0FdtmB2oQHFYbST+fS9ek3v/6bCuc/Tye9NFbyb1vC9NM0NwlVILbOeiNkJOEIP eTJqOqhNE8zKklnbvjK/k2OhfBxbCtPHIhvXaorP7C1vP4fCnsrRBzTkmARwE27Zk3Wj 1xHpqn7E/TylgBgKXyoBO13mIZA+B3SdzQDo4vdx35ZabT6ogczCNGiv8pjD9ej26Kqd ystKcqTaB7ZD/26gW5A3Illk3H327/ZyvtAyoZTBQZNKWvVMfRaAIb+0s05UK075+aKA sxpg== 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=dTCJ0Pqz4fXdx4/4ONALmo8fgSfecqceCrYkYaD/FIE=; b=P6+izeFuFCizwp6+3I6Q5BTNvvpiwOTUIPKzWQygMlzUcMAECeopbUyz4NoYvRf4+R aTvJkRWuz5mFxf2LFvt7Oo7wTXzUDdHUKsvXqT8wWEF8qYgnkV93+fzQj35WpLicuVMh 1A98Yj7OKtHsB1syUZIluUVlmusMHrZYpp0lXvupd7xxmycudOhjAf5wAcXIkUp779C5 1GSlw1QtRp9w7DmlEHhSeUtFrf0an4RRWov7uhL1mCYOuBFx/lX4xfWbphIgiPedhsMa b9yVAXWztMf8FqxBLB+IxnIS5tPQSpB6vt+KDr1NkYnRGat4dgnsMd3tBODZfKFvr4oP ygBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zstUFfSH; 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 z87-v6si10918619pff.159.2018.06.16.11.02.56; Sat, 16 Jun 2018 11:03:10 -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=zstUFfSH; 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 S1756326AbeFPSCd (ORCPT + 99 others); Sat, 16 Jun 2018 14:02:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:40078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752587AbeFPSCb (ORCPT ); Sat, 16 Jun 2018 14:02:31 -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 2172A20895; Sat, 16 Jun 2018 18:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529172151; bh=f4Hpcr2yf7YSkkI/+JVYbYIZUB4dBIhSbJeTlwlsILY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=zstUFfSHbQ5oO8ov2Tr8B7VMevAmVKLFrjVkgHTyVPAouswgW6Ep0Gby/Um/m6Oxx UZA9jO6qH5ItYgk2SJCOXsO62TDkj+rTQsT852ghJHqsPFs4EmvhmlXNDS5vXFhPXO TzRcMY6wJEqksi10Uj35DtDOkKcoOg3fuiDV3GSg= Date: Sat, 16 Jun 2018 19:02:26 +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 v2] staging:iio:accel:adis16240: sign extend function avoiding code duplication Message-ID: <20180616190226.4a6a5980@archlinux> In-Reply-To: <20180612162153.21789-1-karim.eshapa@gmail.com> References: <20180612162153.21789-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:21:53 +0200 Karim Eshapa wrote: > Use sign_extend32 kernel function instead of code duplication, > Safe also for 16 bit. and remove declaration of bits variable not needed. > > Signed-off-by: Karim Eshapa Please consider how a patch is applied and resend as a v3 which can actually be applied. Test it (by applying it yourself) to make sure you have everything correct... Jonathan > > >On Tue, 2018-06-12 at 01:38 +0200, Karim Eshapa wrote: > >> Use sign_extend32 kernel function instead of code duplication. > >> Safe also for 16 bit. > > > >Perhaps remove the bits declaration and assignments > >and just use 9 directly. > > > >> diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c > > > >> @@ -292,9 +292,7 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, > >> 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, bits - 1); > >> return IIO_VAL_INT; > >> case IIO_CHAN_INFO_PEAK: > >> bits = 10; > >> @@ -302,9 +300,7 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, > >> 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, bits - 1); > >> return IIO_VAL_INT; > >> } > >> return -EINVAL; > --- > drivers/staging/iio/accel/adis16240.c | 11 ++--------- > 1 file changed, 2 insertions(+), 9 deletions(-) > > diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c > index fff6d99089cc..24e525f1ef25 100644 > --- a/drivers/staging/iio/accel/adis16240.c > +++ b/drivers/staging/iio/accel/adis16240.c > @@ -250,7 +250,6 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, > { > struct adis *st = iio_priv(indio_dev); > int ret; > - int bits; > u8 addr; > s16 val16; > > @@ -287,24 +286,18 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, > *val = 25000 / 244 - 0x133; /* 25 C = 0x133 */ > return IIO_VAL_INT; > case IIO_CHAN_INFO_CALIBBIAS: > - bits = 10; > addr = adis16240_addresses[chan->scan_index][0]; > 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, 9); > return IIO_VAL_INT; > case IIO_CHAN_INFO_PEAK: > - bits = 10; > addr = adis16240_addresses[chan->scan_index][1]; > 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, 9); > return IIO_VAL_INT; > } > return -EINVAL;