Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5573179imm; Tue, 12 Jun 2018 09:49:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJXCXIImWps9W2c9r577Q/0r9VL3lsLho9AN0EOdX4TP+/tFSNcfr2GBs3anCbXmyA4+4a1 X-Received: by 2002:a65:4308:: with SMTP id j8-v6mr947878pgq.351.1528822188340; Tue, 12 Jun 2018 09:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528822188; cv=none; d=google.com; s=arc-20160816; b=L+u9JXi7YDxUN2sGNQod04tbta/Eu92njJM+m6+Q9Oed6NPdUdDzy0oAjJi8vvUcpj DubTcoO68KkpxQ5eOPXw341GIAY/OOKlom2y/nnqiyxBmSPkjh2rVjFDn0pnntzJts1R plRfsdNbEVd6qIuU5rgaabBHcFU+XqeG7fOVIdWt+I9gjNLx5PLgWJ7tYhLXOk/ZBqEd 6zDVI/4IzGOnMq/MmwKqIzfnNuT85MJe0QQu44I0942oAKYlRyLc/pyW/QVXHjotc5/r J2QcWG7nc34qQ9X6Ossv/l+6nNSxotNbHbrdkyKQfX4AOqSmdoIEiXUFIzRLUY3g8y1f kemw== 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=DYS7Mf7H3RVCufF92B/vQD0QXiXp3YbGArlPeqOubXI=; b=ZngsBj6TDdlhlEr//p2i2mlXrD5hmtAdl945H7ieKzJd+9HuO9Ps+YOdkd2Yr4f4wh c2ukoDgsxCaHajaf7+IgiDEPGPIjBvpRbcajHElOk6UA8AyPW6mO+PFl4ACvqLDAp9yc V+MlPYZgmLVjkFUUugWPHxq+E4u9mnJLI9Eaw5WbXLZLYxKGENRPMy9B+i5NFuH2X0Ok qLAUfKDt9WgebuMOCtv8GyqSu4XNpLwRuC3l36PuZrsf6cZurU7hqOFDmUJAhMQJIBCq mHvczCodE/paeQClllOB822hDvqYd5epwoS19DdCm/zVMBEuW70EygkkgSIVkxebkIS6 9idA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KneQnyne; 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 l187-v6si507305pfc.87.2018.06.12.09.49.33; Tue, 12 Jun 2018 09:49:48 -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=KneQnyne; 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 S935075AbeFLQsr (ORCPT + 99 others); Tue, 12 Jun 2018 12:48:47 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:39361 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935040AbeFLQsp (ORCPT ); Tue, 12 Jun 2018 12:48:45 -0400 Received: by mail-wr0-f195.google.com with SMTP id w7-v6so24826875wrn.6; Tue, 12 Jun 2018 09:48:44 -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=DYS7Mf7H3RVCufF92B/vQD0QXiXp3YbGArlPeqOubXI=; b=KneQnyne9zAWoDjVkZzVXORg2/FFTwBtPWVi4SUOa+dTnW9+viux52nrrBBN9rsNwj KpyeAZSd0IVW41pWgm7iCek5tAgOrAu8E4a47pIg/OzqBaN9zwsKsfeSfoQUNJGra+XE Zq665XTONRTM9gwEUWvDeD7L4Q1tg2rIr0wTi8zuB85UtebPFm/k/cYIO/Nj5GyrQ30F 6eI6RIsYWBlLPjMo8HhNe/m3+u+X3XeZWz0Q8HBrweRvqNm6fAufyUk5ZETir290qgc5 7FY32FpdtsIqwKZd7GrfIVAKv6keesMAtjO42APx3UikZo78r0sdDKTh77Hf4k3KkXpI s75g== 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=DYS7Mf7H3RVCufF92B/vQD0QXiXp3YbGArlPeqOubXI=; b=ansE0DzUrAt5J3VNTICpNPT7odMTeZhnafTCpR+G1yNBzNH4QRCf1SKSAGiR7kjcH1 zui4zzDbIbvi/RFqkyg9qycXgXQHZ/OpGarYGx9yzQaAkN+VW0Q2bZBbtCcA/STDOjPp w21AVoXOeQOs/CxP8OexLBevcidNMu6MrHmxTiQkJhPG7gX2WNqmyRYILaZn1C2g6QNl N0ka6QKfZbWuL7VQgqufqclWFgwZNGZYk4D3BnBoGIPALLtL/+ut3zoc9wdkA8ELrKOJ G9FBKjtP6aOXhbj2jMJcE11Ut2x5QpieQtNWEIydtvqRBUgmIslH4OnCzNVu2xi4J/HZ KHhg== X-Gm-Message-State: APt69E28T42kQWS2Nye+P+V9u2lXSxhRwaafCbDxJusKtEImasYVWq8H zlGjXyhXrohTmxC3hNcN+tA= X-Received: by 2002:a5d:4206:: with SMTP id n6-v6mr914025wrq.13.1528822123850; Tue, 12 Jun 2018 09:48:43 -0700 (PDT) Received: from localhost.localdomain ([197.54.242.32]) by smtp.gmail.com with ESMTPSA id s191-v6sm1417442wmd.27.2018.06.12.09.48.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 09:48:42 -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:adis16203: sign extend function rather code duplication Date: Tue, 12 Jun 2018 18:48:38 +0200 Message-Id: <20180612164838.22961-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/adis16203.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/staging/iio/accel/adis16203.c b/drivers/staging/iio/accel/adis16203.c index b3e4571340ab..5cc96c8086b5 100644 --- a/drivers/staging/iio/accel/adis16203.c +++ b/drivers/staging/iio/accel/adis16203.c @@ -168,7 +168,6 @@ static int adis16203_read_raw(struct iio_dev *indio_dev, { struct adis *st = iio_priv(indio_dev); int ret; - int bits; u8 addr; s16 val16; @@ -202,14 +201,11 @@ static int adis16203_read_raw(struct iio_dev *indio_dev, *val = 25000 / -470 - 1278; /* 25 C = 1278 */ return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBBIAS: - bits = 14; addr = adis16203_addresses[chan->scan_index]; 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, 13); return IIO_VAL_INT; default: return -EINVAL; -- 2.17.1