Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2877382imm; Sun, 24 Jun 2018 06:34:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIiz/xVu1APo18L3F0CKZ3y425e7N35V2DY0ZIWqNp9UWh+9CowxkZsOZmjUs5rbR2HC/dj X-Received: by 2002:a63:7886:: with SMTP id t128-v6mr7611767pgc.429.1529847264456; Sun, 24 Jun 2018 06:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529847264; cv=none; d=google.com; s=arc-20160816; b=A/QEJ4ydFuDqEK9N7V3OUqTuIy7JdrTJXr1p1rJd4Xt0pmUmci6SS+Qn+Ap4+qsKGc m8KKfKsLDovRGAUebu3rVoRMavi+nyq33EzmaqYr+tIOmj/pmCKLeLToGjsG2f6gd5hW NOX70PHnzxwOXYtQk3OAIJKj1TdJFQPmKA3aypLkWdxbXW8myc/OvTRHtkCvK1QZ/I2e w0uB1hpjEDcSM8Ie48Y0o+BylDDA6CwPht33dACU1KI1bKgGRE53vpOL0W726o30jTQL k3wWeADVZvevy/OUnIRrMCSuNIkU73qHT1T4lnfTNlCXGnMPaR2Q28JHvNY70YA7mtwl PFTQ== 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=zNUs/+l9cHfdLsW0cgtW5/wIss0wVXrvqL7IUu0RV4k=; b=g77w7p8ugy736nGc0mvqDwdSlDcI2nMRLnGyD7L6SDEFLfMLVgl/BWMMRlut6++rlr BMcKyLnH9ZnHbJWHVYY0b0rTa172gDLRreCuR+jsSPw8cu0BNhbjaysct/vt7XNTE/UX RgyoyyUaSZ7zcq6s9PLZCorWCLPwBfXFNEAH+YjJc//f6Kxpe42rvTurz9OBxRv7+98L 8I9PQRV4KeAWHiNzDk7TiNUX9NVKypoWkf8atTeGiDaWvgaEtufA9ABJEMBoaap+FrRk Em/M2nFPdqOD+8ZCZk2yBQCU0ShRyyyOQhb+47P7I0tyGa2d19fCZeN1cx88QAujSfW+ Ki0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=feJIUfeY; 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 f34-v6si11689088ple.165.2018.06.24.06.34.09; Sun, 24 Jun 2018 06:34:24 -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=feJIUfeY; 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 S1751971AbeFXNcQ (ORCPT + 99 others); Sun, 24 Jun 2018 09:32:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:38624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751183AbeFXNcO (ORCPT ); Sun, 24 Jun 2018 09:32:14 -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 6972D21757; Sun, 24 Jun 2018 13:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1529847134; bh=GS0oHGQNE38um9ffxc4zQoEJq/Z6/i+L1FrzRNcIQq8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=feJIUfeYrbEBZVHH89bdb5d0dU0co8nhfftG4Diblvz93KFZIIBDaln1yeqW5cunP Q/X2zfqKUqQsHFvJGWprr+vIrtRDsd10Zh4TRxawyP3kGtK9cI9V/XmDopwpLH2t8f teoWtlt/sS/rcN0crUpT1C5l6MnfhEuwoAXsaVnE= Date: Sun, 24 Jun 2018 14:32:08 +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 v3] staging:iio:accel:adis16240: sign extend function replace hard code duplication Message-ID: <20180624143208.7686711d@archlinux> In-Reply-To: <20180618174450.3399-1-karim.eshapa@gmail.com> References: <20180618174450.3399-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 Mon, 18 Jun 2018 19:44:50 +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 Applied, thanks. Jonathan > --- > 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;