Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4720884imm; Mon, 11 Jun 2018 18:07:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJI7zhl7fq7IvD5geAYeoLVRhhfgnabEBeNWYP445KLbAhR7RtcF8Ntf3zTtdEmDF4Y2Tiq X-Received: by 2002:a62:5991:: with SMTP id k17-v6mr1518425pfj.94.1528765673979; Mon, 11 Jun 2018 18:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528765673; cv=none; d=google.com; s=arc-20160816; b=vJe5qcGZnCLN6fMOq+Ct9P2SOr2vavRbbYqIRwU5NFhv3hf6NV6a3U8TWqp24/Z5mo C7RrI8oRxWKzYjZYnww8KWkCOsWgJRHuWxDOhb53iiT7bYYgfveRw+scHRiEkGgOByUx niS2ae6IOLQ4cuBuDKCMbWmKt9mabspd0MxpZUGn/sOwpBfYZJh17lAXz4DO0N5MC/QL c6lPm+v2CCVjbSID8wGo/Ysr4UCXl/pY9a7bk1UHChIkLg5G1oKEhke7NpcE5Cq45hwB 5QdXA/BGb4lzN1gPuXZECtzfm1BW2xHC1kz90SpPyI8OUErP7P0HQfm34gYWXqNinv2y mucQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=huRr0IxaPrA/WyKuTOWDsm6UmZ0pmfjvJxO9p5TkmcE=; b=Iq0WxQi3p0vq8+YTxhRAxWK36wBCQuok4WTziuTlxJ2TF8UfDY6DJG6AShCQVi0+yU wDvak7d3xVkaCxztRDe/pnFS9j/Hu5j+t2C1xvKBZ6SW882qakcoHydGzBTd1TLW4XvO 3hWAvraBcOlpO7N+rsU4d7eG3LSlfWu+N+eKlodiWGlIreoafzD1Lyn5oP6GRy4xWEvu q6MEQwthkfvTkJuqawc+G74FTnl7jENFbKlFUG8cHB7PRjw9uIr4pTUtG8USXPucLwcu DqDPe3O7fJWAMfTG0LQUg5DDK67Vjs8bOby1nTOhB5vv36wUL3icRDtGAO+/QrIygfbX YZtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NIFjWdpe; 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 j195-v6si18793390pgc.543.2018.06.11.18.07.27; Mon, 11 Jun 2018 18:07:53 -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=NIFjWdpe; 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 S934762AbeFLA57 (ORCPT + 99 others); Mon, 11 Jun 2018 20:57:59 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:40266 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933405AbeFLA56 (ORCPT ); Mon, 11 Jun 2018 20:57:58 -0400 Received: by mail-wm0-f67.google.com with SMTP id n5-v6so19850151wmc.5; Mon, 11 Jun 2018 17:57:57 -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:in-reply-to:references; bh=huRr0IxaPrA/WyKuTOWDsm6UmZ0pmfjvJxO9p5TkmcE=; b=NIFjWdper875cajcBmixEbIKZdF39cvzXcNlGLWJu4O0G4wR+F7EQlCnEYX3e+aACi xqeBJMx9U6k1WtCw4zHz1c/GRxCpR9Td9DNYaSP42agYNVhvp38VjYgV+k7uL8AfHYoZ jLJx8PXC2hQrxek+13zkdgWZMQqH6F2Me43PdJ+zqqd+NfZtUor7NxlBYbjqMILpYD2s CWfnt6gY1qA1adfP/vsb8I+BqHM273DBqu9jJBUiL1q4b5Its6xa5QqS5T2bhu/Xkqlq st8lzS/jYlf8JE7S7W+ZeOV8WInnvBEWm/8VdrEg74xb3JgYOL2egMhFucRkC+v2PDwd sivg== 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:in-reply-to :references; bh=huRr0IxaPrA/WyKuTOWDsm6UmZ0pmfjvJxO9p5TkmcE=; b=OwFqB3TZyD4ZWOhe6ykZiQFkGShM9qr0T5HJxluOLYVesABUp98pfCpF43R96qMMY0 QS8wFlCbmgZCnrj7ipuzTi2qzhVPfK+eQwBDijrH9WPr66LTBFahvudwkBkMvSuc+EU0 HfSFZyWQpGvq51wyy86M62vXm5uGzkAzfKoCTuFoKGk/5gobRCwDrWFfXTiXcxK9EDq2 o2Qu2V51Qr2CiJsr7MD3WwydON6GLvLEIURiu2NnWp/0yKrYavjosOifi93plMRckFh1 ujJKg69HYWSf85ecUijSudM7tHsLRg0gPKVlok3GTmC1kH91Q5U2bK5hKaZfcLB3pCiY ccWg== X-Gm-Message-State: APt69E1gC0oWUJz8qYRdASKehBaXKAfiJizDPywyCU6E4P5wsHbf94dZ W1slBVviolePAF73etmHN7s= X-Received: by 2002:a1c:7506:: with SMTP id o6-v6mr678699wmc.60.1528765076941; Mon, 11 Jun 2018 17:57:56 -0700 (PDT) Received: from localhost.localdomain ([156.219.155.97]) by smtp.gmail.com with ESMTPSA id l84-v6sm12076119wmi.3.2018.06.11.17.57.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 17:57:56 -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: Re: [PATCH] staging:iio:accel:adis16240: sign extend function avoiding code duplication Date: Tue, 12 Jun 2018 02:57:48 +0200 Message-Id: <20180612005748.3546-1-karim.eshapa@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <48143872d69d231273bd2c8ed835cbf0046a263d.camel@perches.com> References: <48143872d69d231273bd2c8ed835cbf0046a263d.camel@perches.com> 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. Safe also for 16 bit. Signed-off-by: Karim Eshapa --- drivers/staging/iio/accel/adis16240.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c index fff6d99089cc..24e525f1ef25 100644 --- a/drivers/staging/iio/accel/adis16240.c +++ b/drivers/staging/iio/accel/adis16240.c @@ -250,7 +250,6 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, { struct adis *st = iio_priv(indio_dev); int ret; - int bits; u8 addr; s16 val16; @@ -287,24 +286,18 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, *val = 25000 / 244 - 0x133; /* 25 C = 0x133 */ return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBBIAS: - bits = 10; addr = adis16240_addresses[chan->scan_index][0]; 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, 9); return IIO_VAL_INT; case IIO_CHAN_INFO_PEAK: - bits = 10; addr = adis16240_addresses[chan->scan_index][1]; 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, 9); return IIO_VAL_INT; } return -EINVAL; -- 2.17.1