Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3394965imm; Sun, 10 Jun 2018 15:35:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLt6U1Flk0zzRpukNlxdJWx3bZw/QI82A5NCmZ/JYSG7HfvWhTXa5UY8TJlS9M7poGpgOMy X-Received: by 2002:a63:2682:: with SMTP id m124-v6mr12664502pgm.56.1528670155290; Sun, 10 Jun 2018 15:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528670155; cv=none; d=google.com; s=arc-20160816; b=w+c3L3IP+ELFWeN7hmnImrwexCgzAZ4Q1vTn7Blz75Lejy1fjfOkxKgEsP4e+riJZT +PEiumIzvgkLabH5ESnrnlLMUdNuTZEQf8lezK4oKdhgj0nyAZRYm7LdOqCFGiNY3Yzl JkwbElZUDy4GJE6R1xfQCnZyaCHa9GTQrtwU1RMBEvAkqu11CnFPmfW4csWJ4ygJX162 jTeQ5VuCUVnuLuDd4i80wJWTam31CWb/56msUx/nflT27HDk4USKIGgXcWgEKoCIu/qf YxvzuRrcE2gNGRNX6yCTRdc6VwyJtouCwDxxp2SuarMoCBe4e6F5Dr4k8OJS70bD09Fm 6bOg== 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:date:cc:to:from:subject:message-id :arc-authentication-results; bh=JaBoFiW6jZzGN57Fya/S65iu429B+Ln5GJF7pWi5vfM=; b=BB2fEUZD7AeXbOtjiXLLOdVVFxSinE2joAfUVjoSBwoXXQCLsLu/lim3YQKv/IY0tZ CnXu6Rsox74rE/7cj8H++mytg2Utn3E7yEmTuArrVCI9mdhZjzWBr+rYl5kWhg+KOo+4 hunPUcVKEBYCyvxoFwZNPC5CEpNAEuY+4HkVdlxu38uXEaSXjzwjsLDLI1PM6aYqw3M5 J6d2tcuMYfVFJ1v2aKdKUzy13TcK1fAWym6DGQY9HWYUxCL1q3SOGZlNRU8fEV9bFdCz KcTJqCIsHqFuRU+Y1FTn6NA3Cv/MylaSCMUjn3vCVakkBZDefyONeSFydFifLPL0HTSZ qY9Q== 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 b18-v6si61675423pfi.254.2018.06.10.15.35.27; Sun, 10 Jun 2018 15:35:55 -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 S1753566AbeFJWeu (ORCPT + 99 others); Sun, 10 Jun 2018 18:34:50 -0400 Received: from smtprelay0062.hostedemail.com ([216.40.44.62]:50168 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753486AbeFJWes (ORCPT ); Sun, 10 Jun 2018 18:34:48 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id 92C24100E86C3; Sun, 10 Jun 2018 22:34:47 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2828:2915:3138:3139:3140:3141:3142:3353:3622:3865:3866:3870:3871:4321:4605:5007:7514:7875:9121:10004:10400:10848:11026:11232:11233:11473:11657:11658:11914:12043:12262:12296:12438:12555:12679:12740:12760:12895:13069:13255:13311:13357:13439:14096:14097:14181:14659:14721:21080:21365:21451:21627:30012:30054:30069:30091,0,RBL:47.151.150.235:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:28,LUA_SUMMARY:none X-HE-Tag: cast97_c79105329649 X-Filterd-Recvd-Size: 2945 Received: from XPS-9350.home (unknown [47.151.150.235]) (Authenticated sender: joe@perches.com) by omf04.hostedemail.com (Postfix) with ESMTPA; Sun, 10 Jun 2018 22:34:45 +0000 (UTC) Message-ID: Subject: Re: [PATCH] staging:iio:accel: use sign extend function avoiding code duplication From: Joe Perches To: Karim Eshapa , lars@metafoo.de, Himanshu Jha Cc: Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Date: Sun, 10 Jun 2018 15:34:44 -0700 In-Reply-To: <20180610220920.12244-1-karim.eshapa@gmail.com> References: <20180610220920.12244-1-karim.eshapa@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 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, 2018-06-11 at 00:09 +0200, Karim Eshapa wrote: > Use sign_extend32 kernel function instead of code duplication. > This function is also safe for 16 bits. Firstly: This file is not in staging anymore. Please use the -next tree for patches. > diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c [] > @@ -227,9 +227,7 @@ static int adis16201_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); > return IIO_VAL_INT; > } Secondly: A similar patch with a different bits value was already applied. Please verify the appropriate bits value. commit e7f3bfb7eb7d9307c0c157f82fceb228f0aec1d9 Author: Himanshu Jha Date: Sat Mar 17 01:36:23 2018 +0530 Staging: iio: accel: adis16201: Use sign_extend32 function Use sign_extned32() for 32 bit sign extending rather than hard coding. Signed-off-by: Himanshu Jha Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16201.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c index 87ad3d421c12..526dde481f84 100644 --- a/drivers/staging/iio/accel/adis16201.c +++ b/drivers/staging/iio/accel/adis16201.c @@ -173,9 +173,8 @@ static int adis16201_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; }