From patchwork Sat Feb 17 16:21:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shreeya Patel X-Patchwork-Id: 10226245 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 1F780601D4 for ; Sat, 17 Feb 2018 16:21:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09A4D2894F for ; Sat, 17 Feb 2018 16:21:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F251828964; Sat, 17 Feb 2018 16:21:42 +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 90CBB2894F for ; Sat, 17 Feb 2018 16:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751029AbeBQQVl (ORCPT ); Sat, 17 Feb 2018 11:21:41 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:42423 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751151AbeBQQVj (ORCPT ); Sat, 17 Feb 2018 11:21:39 -0500 Received: by mail-pl0-f65.google.com with SMTP id 31so3331648ple.9 for ; Sat, 17 Feb 2018 08:21:39 -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=t71cys8crxh9zMheRjAWaRAL0CQDio2M6+/3INZexSs=; b=SfXlX/98A7rV3Vt57dL3xr9kcZ0ig8A8UiqgLv8WET5LK8URMXmqbeOwlbWaG3gHJX 0hycxngCRk+T5bT35/3r0VIRp5UDsPnqiLyCtfJEq4IhtiDHcvSUsjLy3YYjENts5v9r WbsOZdcCCZH712Qzzkg+uje6PW+cuuFDMtFKfHvYa7WBe8V5mdOzkjd094Yl4DH3cP0P XfD6FUli/VejhQvKO9zj+fvmuv1uxccygapoPj06CUADx0jye93Z2T032hQReRR279NC oFoc1wzMW6wJEQ7DzHOUDjkegK+Nbk8uW3kgnKoUR+KIlDauiMinsXb4BgYe5cdvO1rC 88Xg== 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=t71cys8crxh9zMheRjAWaRAL0CQDio2M6+/3INZexSs=; b=NY2i1gxGI+n85OMkQvw2y4mUDAtyOa6VqAixOCARPeC/Qav/XsvdxvY2iscOsbzZez YNwmoNnw2FcTejmdgJix87Ik/Zxtg2nQa4YUZgXYLqfWfFkNtSCLVlT+6yYyKM2KUMCn dVX9Bi+aLLdsQMIHisu1go5xGzrlXn2tKQ6ry0/4ERbN8H6Atq49y6TtaQ+QyS18ZPbH c00ZA6NDF9fJ86ouIHyA9s/ddMISbojUq4Be5P7YSomOZfVShJdZxayFM3ez2M4KqV1X cVJBakaBTpRGLH9O6viptGG0+6xPqQ7A2KV0rywjXSK5WdVZjqzbG4W9luNy8IqGYcGL pclw== X-Gm-Message-State: APf1xPBLTUjtVcFwV6PeMtIjdGj8n8RpfaRCwKoDjcVsnI4CQhNjqCdU dp7p38niqy3YFJkTxODVH9k= X-Google-Smtp-Source: AH8x226IAZFAcGXdMMQoDGaHbZyzHiMszSETlK0E2mtcWScf76uAJ8kbOBOxp5FYv+rCRfS5tXsH7w== X-Received: by 2002:a17:902:a617:: with SMTP id u23-v6mr9126970plq.201.1518884499377; Sat, 17 Feb 2018 08:21:39 -0800 (PST) Received: from shreeya-VirtualBox ([103.212.140.154]) by smtp.gmail.com with ESMTPSA id g1sm53461621pfk.98.2018.02.17.08.21.38 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Feb 2018 08:21:38 -0800 (PST) From: Shreeya Patel To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, daniel.baluta@nxp.com Cc: Shreeya Patel Subject: [PATCH 3/3] Staging: iio: adis16209: Use sign_extend32 and adjust a switch statement Date: Sat, 17 Feb 2018 21:51:35 +0530 Message-Id: <317f97b7a3b53bf3ae1457d7c38f78befc4b99db.1518883035.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 improves code readability. 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 6101212..f7c228b 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; - else + break; + case 1: *val2 = 610500; + break; + default: + return -EINVAL; + } return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP: *val = -470; @@ -187,9 +193,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;