From patchwork Fri Mar 2 13:34:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shreeya Patel X-Patchwork-Id: 10254637 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 F15AA602B5 for ; Fri, 2 Mar 2018 13:34:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D395228990 for ; Fri, 2 Mar 2018 13:34:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C694E28996; Fri, 2 Mar 2018 13:34:56 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 5E86328990 for ; Fri, 2 Mar 2018 13:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424171AbeCBNez (ORCPT ); Fri, 2 Mar 2018 08:34:55 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34975 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423276AbeCBNey (ORCPT ); Fri, 2 Mar 2018 08:34:54 -0500 Received: by mail-pf0-f196.google.com with SMTP id y186so4015798pfb.2; Fri, 02 Mar 2018 05:34:54 -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=LvFCHHwV4itdj1VyQfRCsc9vIzfkqNgEESSHI0dHez0=; b=Um/6NQ9QbpVwwj0UyiwNS1QmbVJlpwBQL4FwtF8dJVbFjpMSLeZ4zZMYFAL9egpCdT Q13O8Bqt75YD/2FKpDySfsQwJniEodnrk7rb2bM++zO2Jzj71NGslGoYDEahvUNICQKs KX2CVcdd/EzTGGH7JnEtGq09Qi6r44UBJKpEsbFZMzGXH2T0TlH2W6IL72oq/rNkhyi7 fl5o0sSHdgz2m5PZSKzaz6AwrFHPoNhUaxajSlUqnDoVYkp0+w1ZXcR1q1gOo7eEWtGa Syl+UO9iRs3facLPyxVAEE3XDPF6GTkESF1DMI/CQX0fqeHvCdt7/TBIkY8Xnj4UYalV 8XOg== 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=LvFCHHwV4itdj1VyQfRCsc9vIzfkqNgEESSHI0dHez0=; b=c30dwTmtvQQZaQHPAZlHZ0+udpXuVAr7u3c6QjJ59YE1o0Db9B7E288PtJPwO7vrYX AptyjVY2bpnvmcDDXq83bJUaI5Gq+h5Zxz/uYY24VsytNSXfDA6VJZ4pGXtLAKUHwCaA QonA7vOAR0QK4IVHItAxcU/kzMuJ/bvIhNnZZ6aQX/nDLnV6jtflz802N/9xsfH82fYT yA7hbGYsveS5dk39bn7oY0dEUH73HtffsAtbYWTJa4PD8zxqaavdSIimRt5mE1G0+6sy Mw9deF4xEo62mInByyQknaLhA27zHVzbEsQMYEh7ikhRRkCqT3B9r07FOf53Q3cj3iUr zuCQ== X-Gm-Message-State: APf1xPBiWkCuIMJy2oAoZZ2+eXBLLGTlpr3IB4B/PnSI+I2bNXEGfEGX hCKNsXQAk1fzC//H1xJcTQE= X-Google-Smtp-Source: AG47ELsTODnHHWPNCZi6rcWmBNX3Yzn0SfVSOOhGGP3MrvpplbLYFA7B0fMpy84umNS6OaAJfYmiSA== X-Received: by 10.98.8.219 with SMTP id 88mr5737774pfi.4.1519997694284; Fri, 02 Mar 2018 05:34:54 -0800 (PST) Received: from shreeya-VirtualBox ([103.212.140.150]) by smtp.gmail.com with ESMTPSA id s78sm13407064pfa.161.2018.03.02.05.34.53 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Mar 2018 05:34:53 -0800 (PST) From: Shreeya Patel To: lars@metafoo.de, 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, daniel.baluta@gmail.com Cc: Shreeya Patel Subject: [PATCH 6/6] Staging: iio: adis16209: Use sign_extend32 and adjust a switch statement Date: Fri, 2 Mar 2018 19:04:49 +0530 Message-Id: <982b80d683b8c8e8c61cbc5b0864c265ea2ac768.1519995673.git.shreeya.patel23498@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: 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 makes the code semantically more clear. Signed-off-by: Shreeya Patel --- drivers/staging/iio/accel/adis16209.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index 7363fd0..5ab44a4 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -150,10 +150,16 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, switch (chan->type) { case IIO_VOLTAGE: *val = 0; - if (chan->channel == 0) + switch (chan->channel) { + case 0: *val2 = 305180; /* 0.30518 mV */ - else + break; + case 1: *val2 = 610500; /* 0.6105 mV */ + break; + default: + return -EINVAL; + } return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP: *val = -470; @@ -197,9 +203,8 @@ static int adis16209_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 - 1); return IIO_VAL_INT; } return -EINVAL;