From patchwork Sun Jun 10 22:09:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Eshapa X-Patchwork-Id: 10456789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4124E60234 for ; Sun, 10 Jun 2018 22:09:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 262CE27816 for ; Sun, 10 Jun 2018 22:09:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1631327853; Sun, 10 Jun 2018 22:09:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6809227816 for ; Sun, 10 Jun 2018 22:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753714AbeFJWJc (ORCPT ); Sun, 10 Jun 2018 18:09:32 -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-Google-Smtp-Source: ADUXVKKXJ0zv7PzPTpFWGDNrLAg4uNRKzO93BHHpkhAK/qkySt0QSVIw0ltoLIuZwt884jMxBY/INQ== 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-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }