From patchwork Mon Feb 12 11:54:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Jha X-Patchwork-Id: 10212261 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 C283160467 for ; Mon, 12 Feb 2018 11:56:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A50DE28BBA for ; Mon, 12 Feb 2018 11:56:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9971B28C3B; Mon, 12 Feb 2018 11:56:36 +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=-2.0 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SBL_CSS, RCVD_IN_SORBS_WEB, T_DKIM_INVALID autolearn=no 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 5A40D28BBA for ; Mon, 12 Feb 2018 11:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932944AbeBLL4X (ORCPT ); Mon, 12 Feb 2018 06:56:23 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:37290 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934327AbeBLLzm (ORCPT ); Mon, 12 Feb 2018 06:55:42 -0500 Received: by mail-it0-f67.google.com with SMTP id d10so241629itj.2; Mon, 12 Feb 2018 03:55:41 -0800 (PST) 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=ySil++Rfnu75f9AEE2bA9Z+SidJcSFrHc7SQsrtG9Ww=; b=tN3Uvh8zx6Q0tu8+dUGePaiLvE7WeUk/uWvQTNNDawimzMh3c1BgOim/PGfs96qBiw vmdUOc+l4/JdeDRQSqeUKvzbHQRruSvhz6so47M2oqQnq9ZL4UAmTyxd3R+LrgdiFOKS 8U5DhtLyf46rGvcrpZ64UWHxf0y542wgqB/UZ68OAX4M/NIIYrMCeb1kfayLZBC0me/R Qbd4KrRsW2aHrRoW5CxZ2M2VUUBRFqpOrl1pcg84A7CFzn7xMX9503nEe4N6GKsUbODL Swc4jKYqU8VH2HjLxmvjA4+TV5x0PDjRKzO2cXWx3hkN471CY22PaJcjPzNlEnUANy0e XJxA== 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=ySil++Rfnu75f9AEE2bA9Z+SidJcSFrHc7SQsrtG9Ww=; b=BjHxwlgTujOm8i7//mHqxi2t+Fm88Ka7uV8qfxU9/Ug/PmOATVEvuOv39kh1zWVenD lfZ2jk0IH0S+303jJrKkSRIcq7+mVHCJJ5qu4Mqvlp81tfESrj7UOFbfgq+6H8S8kWr2 6S5txfHgD4V7RESK61m8bsg+N8MoboR5O1IPwoYqy8+ZTp4x0eZGpKVzg0aXQFlFBLRq rnGlNovxrgGapti4RXscrx0yz+EHMSTfdlb0t/xlcU/gQO8m9ypKbEeyUSs4jYSwEEOl /qsbJJ9bhiK6hfV85lAcmV4kOU4ruIO6WcV8cJLd88cyj6djZr0TpS72pdWxVzMMiS+x 1NZg== X-Gm-Message-State: APf1xPAm/kyrrWikPDO+eT1ZYuB1A0HTkqQ7xN9+dwMFsOe2tI3v4r2X Ve+qixabrsgmSBlVbhbkyeA= X-Google-Smtp-Source: AH8x2267XZ02TZ/KMsDPaUzaSdpeTClMNY9RoHwYszARR4g19IjegvlIfH4pskl+s2AnfBetEokUeA== X-Received: by 10.36.104.149 with SMTP id v143mr4888126itb.2.1518436541522; Mon, 12 Feb 2018 03:55:41 -0800 (PST) Received: from localhost.localdomain ([103.46.193.14]) by smtp.gmail.com with ESMTPSA id n73sm10923915ioi.84.2018.02.12.03.55.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Feb 2018 03:55:40 -0800 (PST) From: Himanshu Jha To: 21cnbao@gmail.com, jic23@kernel.org Cc: lars@metafoo.de, Michael.Hennerich@analog.com, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Himanshu Jha Subject: [PATCH 3/4] staging: iio: accel: Use sign_extend32 and adjust a switch statement Date: Mon, 12 Feb 2018 17:24:58 +0530 Message-Id: <1518436499-8584-4-git-send-email-himanshujha199640@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518436499-8584-1-git-send-email-himanshujha199640@gmail.com> References: <1518436499-8584-1-git-send-email-himanshujha199640@gmail.com> 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 function instead of manually coding it. Also, adjust a switch block to explicitly match channels and return -EINVAL as default case which improves code readability. Signed-off-by: Himanshu Jha --- drivers/staging/iio/accel/adis16201.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c index 011d2c5..6800347 100644 --- a/drivers/staging/iio/accel/adis16201.c +++ b/drivers/staging/iio/accel/adis16201.c @@ -112,12 +112,17 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_VOLTAGE: - if (chan->channel == 0) { + switch (chan->channel) { + case 0: *val = 1; *val2 = 220000; - } else { + break; + case 1: *val = 0; *val2 = 610000; + break; + default: + return -EINVAL; } return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP: @@ -155,9 +160,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, 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; }