Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3379352imm; Sun, 10 Jun 2018 15:10:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKT+C2OOS73djIgkhhmAhxOwzSKTU5XBzQjILuqW40+Q5aSTPSnI3nJeW1ceTtYxW1qH2rk X-Received: by 2002:a63:3115:: with SMTP id x21-v6mr12333142pgx.373.1528668627206; Sun, 10 Jun 2018 15:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528668627; cv=none; d=google.com; s=arc-20160816; b=1KaswUyMEisGMiPzavn1osVbRLSuUAqlo7K7dY1J5SmfdJQlNHUf9Xkz53/6pQaeza ZfEkAkWbne4jgL0GrIX74px+Mqw57yEWoYhdWIqUQn5ii9A/6epCasvGEINt/4SImPw5 HueyspOdaiDODOA9s+rcZIPx2vIIhkaAna8WTW11fhn8qA34l2FpdFKPdHkcn2bPseOT VCTXmH31dxvKQOGgeNQf8occEUi3RVJ3cIx8WEgSM8F5g8TUnKDVVSaCIHvqPQT1Y9nx y9AM8zDOMvt0/P7JnQ0t6VHXWtUGuflozj0Hiofh7lvXCPb8WiMZDOxTzEo7yB9+znrd 6htQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=+Ryou1q5Q3g/roVK0v7fUP83I81z53Iy7orrPMdRuUM=; b=US5y+U3irsinSg8G/G+GI2bt4JKYCGGyDyzb6pdHuCwAJcSWe+l3HTMAP0xtMk47Z+ oZJHsmFfgBEm5ZThv5gaZ7xAdMxyfVRvN+IyisHgy87zTCAB1cttPTigQonSb5UiDm/l OTwbpNl3krJSNJsJW9DBZoxKujo+e/+sJ4Qm5ps6gGYyNV+Qc+AOLyem/aJrqRfEX1RZ l0ik35AtObydyPoaJkHgpteJmppDau/D4Rps8bp8+3kGsnA+8f+TtIpJachylvlPQ29+ rbA3RK4/tYu5ugQQDkH/QGQLbtQe/iWyeozuv0LRscT14YFZ6RH3EHoXHGKxyRW0sdqm rCPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MMbx12dD; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g65-v6si35388468pfa.304.2018.06.10.15.10.13; Sun, 10 Jun 2018 15:10:27 -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=@gmail.com header.s=20161025 header.b=MMbx12dD; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932081AbeFJWJd (ORCPT + 99 others); Sun, 10 Jun 2018 18:09:33 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:54908 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753692AbeFJWJb (ORCPT ); Sun, 10 Jun 2018 18:09:31 -0400 Received: by mail-wm0-f67.google.com with SMTP id o13-v6so11434559wmf.4; Sun, 10 Jun 2018 15:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=+Ryou1q5Q3g/roVK0v7fUP83I81z53Iy7orrPMdRuUM=; b=MMbx12dD4auWrfcO0iyvCPGZXwwYEpzCWRIkG9CNx5r9Lkyt+wKrI+z7nmB5/iBymN lOAV2MPgaNTSkKvEdaxhE+Pv9FGTQcW9Z6sm/6vhRGU9EER4xo7BEDX+I7Th4PSTAewj nkqCKXOjSxGniHAZ8vYHhBlj87b5S6J+LbbvR/8DNk2pOc4Gh6m5YVLhZDBpX08r4+Yy KQjk+YrhicjQJ86+NL4rJJrsreNaOosbVb6CfYywadXcTraRZP4KL61uCfl0zF7fFrjr Bh5sv0ex2i6wmwVTjHT0kdpMhzVMwMhcDZ5T4LStJzGgy60TMJpjkAYO4UimDxQ0z4Rd ErrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+Ryou1q5Q3g/roVK0v7fUP83I81z53Iy7orrPMdRuUM=; b=P+ZBcQTwXbgcvnf/UrIAFUNeP4/IUAdL5l5KSsh9mDLEFtzVvCJGhlzTqHRXUlz82y 4ad65YwBvyZtO05qNvAtGUYPpQ1iqY13uiyymImtq5juPjUWTlz2FVIKym09n9Cy7epK TB1rym/CS7WBSrv0YuZCYVA1dH4p3rSywNaX6F0eAPGflAVtpqkbIKZsU+WMtggfagZZ YJxGNU15Lx3RuYC+RhxaaPrzNFbGzxsNm4JfvQ+gVHW1Lb5PvoIlr/OOrC1MfxYdcMsf Tearv6kLcC1sGNAWe5UWNm271HnQJSasPqBPuaoCoDqwAgAUA+8MT7k+Qr1E5WFms7yV B/iQ== X-Gm-Message-State: APt69E3SUXW4wCp9bMGbTjsaLQUM6ICDcLQViyfYwV3sPWjVeeASaxgG I1h9drDpoqlS+Lh9uN8Ikbo= X-Received: by 2002:a1c:c342:: with SMTP id t63-v6mr7066365wmf.123.1528668570445; Sun, 10 Jun 2018 15:09:30 -0700 (PDT) Received: from localhost.localdomain ([156.219.244.88]) by smtp.gmail.com with ESMTPSA id v138-v6sm11049162wmd.47.2018.06.10.15.09.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Jun 2018 15:09:29 -0700 (PDT) From: Karim Eshapa To: 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, Karim Eshapa Subject: [PATCH] staging:iio:accel: use sign extend function avoiding code duplication Date: Mon, 11 Jun 2018 00:09:20 +0200 Message-Id: <20180610220920.12244-1-karim.eshapa@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use sign_extend32 kernel function instead of code duplication. This function is also safe for 16 bits. Signed-off-by: Karim Eshapa --- drivers/staging/iio/accel/adis16201.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c index 0fae8aaf1cf4..fe4494e65395 100644 --- 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; } -- 2.17.1