Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4665596imm; Mon, 11 Jun 2018 16:59:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKItTP2ekUj9ETKb1H2X4FeCyT9/tLZ9FmBAJMdZAVxEeQJs0rQAHHhh+fix3QMAkJ4VDkWc X-Received: by 2002:a17:902:3f81:: with SMTP id a1-v6mr1318961pld.29.1528761594332; Mon, 11 Jun 2018 16:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528761594; cv=none; d=google.com; s=arc-20160816; b=S3/Hz21NL5JfBS0Ouaw6gJ18df1X8Nz3AW1nXYH2CvCnxI4cJVM43JLeP/adu9MFpd E23PEB37pvLxhab18cmK0ijL2DuQaFtOu5CXXIhEZx/3SXPrX2cEl1gQBlLLIvNonzMg 7DUu8gygsp+3LomgzBxBYdd/x5eUIxHnjoAH2SX0ItnXUV5mY3MsDS3cGj4rIJsByaM5 6Atc7jgpK6B0tTwuKosPo2NVga3UlwJGcUSfVb1+Ga4GOMwaCPYNtNTsk+mIRKptddzB qL+kCJc5AvRVBf+4uo+MNHn1POaCY9fQIxcZ8wYaKjXo/zk8mpTAWhcXwpsiDoyCwj0w BZWA== 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=58V13bEpgkJVmAM95/lcPd7lbiTZ2kJVWEyssf+mKO8=; b=Ec89VUAo/NSzAm6Cy3Os3YBnapfsgMAPm/EqLKQ+TRdHQVy9Hn0VExQ12klQ8K07pJ INOreE1DqqPG8NPD+p9ODIVr1hH4RuUm0rUIYCtMpxrxAERPwvdlpOZ2eOvia3W1RqSs q6rbI600+VEqu6+pOswME02CddCgpzg1IhR0NxVcfW70db+gbfD79GW78oEKxQ2uXdXa Ar66nOB/4UXCnMYUOzlpbGmwWxZ2A2V2USh9IuaJLgtgum88ejra2KtRgn/k56SEZfLd Ur1yzPRtrzT+cmdUoB5yHGEYKOxMUNtdyA+4AZshLLEEcVSQEe7lmGfKvGZcT5Q9KNfG 8TXQ== 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 u1-v6si22844659pgo.114.2018.06.11.16.59.27; Mon, 11 Jun 2018 16:59:54 -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 S933267AbeFKX53 (ORCPT + 99 others); Mon, 11 Jun 2018 19:57:29 -0400 Received: from smtprelay0154.hostedemail.com ([216.40.44.154]:48610 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932300AbeFKX52 (ORCPT ); Mon, 11 Jun 2018 19:57:28 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 2ECED1801E309; Mon, 11 Jun 2018 23:57:27 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:968: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:2559:2562:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3868:4321:5007:7875:10004:10400:10848:11026:11232:11473:11657:11658:11914:12043:12114:12296:12555:12740:12760:12895:13069:13255:13311:13357:13439:14096:14097:14659:14721:21080:21451:21611:21627:30012:30054: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:26,LUA_SUMMARY:none X-HE-Tag: cry03_40d20f7422201 X-Filterd-Recvd-Size: 2051 Received: from XPS-9350.home (unknown [47.151.150.235]) (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA; Mon, 11 Jun 2018 23:57:25 +0000 (UTC) Message-ID: <48143872d69d231273bd2c8ed835cbf0046a263d.camel@perches.com> Subject: Re: [PATCH] staging:iio:accel:adis16240: sign extend function avoiding code duplication From: Joe Perches To: Karim Eshapa , lars@metafoo.de 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: Mon, 11 Jun 2018 16:57:24 -0700 In-Reply-To: <20180611233814.18597-1-karim.eshapa@gmail.com> References: <20180611233814.18597-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 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;