Received: by 10.223.185.116 with SMTP id b49csp8768123wrg; Fri, 2 Mar 2018 07:38:07 -0800 (PST) X-Google-Smtp-Source: AG47ELtg7q8n7kaRZ93nBuJRpD6MXySndDuwnzHEciSmfXFWcfa+X3iumH3f3mQ47K4qZyT7qEgC X-Received: by 10.99.165.9 with SMTP id n9mr4895696pgf.324.1520005087401; Fri, 02 Mar 2018 07:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520005087; cv=none; d=google.com; s=arc-20160816; b=CDmJnBXp4yHDx1H1VYIAlPqCC0k2UXvPv+AyzH9ZGGTy9UJE+fvZ/QzcNYJqo2nU58 k8gKcYgX92e5TJLrZ2LhNBpWLJ9P89tgRCntDqB6oNJ6lMd7G/WzNig+svMspcAOlM9y gyNJtMzl4sS9s0RI3cNj3DID8yRSGs3taEELIXFvxXgvrT99/ZXtaIUFMqVyfenqxNdn 9WrQ0dCrlgLkbbu+Kl27UsKTPPTi0K61c9ANiQyACQlpfXVza1/Tr8uuaiC++Oa4UW0a 99kjoAX1i8COKawqOrha7mMgzwQS6n3drGEcwNA2wXMiIWe0FpSREAeugSDt+dZYq7m2 /v1A== 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=LvFCHHwV4itdj1VyQfRCsc9vIzfkqNgEESSHI0dHez0=; b=m81yeWwLrqpH7U6nhvcdq1JSSiXcrLthL00HdxPY5KTUJN1xTPvcI309RQq70iqR3e 6Mfw3eTR4ciKoXILhz+JPQDMEzikRv0uZBUgEcfyKYoV5wl9HtKB8VSFZsn9lOiGMKav 1jvfBq5g/LluswtFcOypHJ38wNhk+4TdhDovfE/J+uKY2VltbuWeJgrZy7ErxGly45ei IWxzVJzspuXMYi6J+KgtbAvr0q//PbcjrN4y43kuvQYOVbLbV2F7XPvTsoN0pk7QS0PO 0bU2aJE/1hbaSGPemjVAeAJ8cRQM0eH+9uGWVQ1kdAMxigdVF845kwntdVU0bVVWCsH4 rRSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Um/6NQ9Q; 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 d5-v6si5029571plm.759.2018.03.02.07.37.46; Fri, 02 Mar 2018 07:38:07 -0800 (PST) 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=Um/6NQ9Q; 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 S1946611AbeCBNe4 (ORCPT + 99 others); Fri, 2 Mar 2018 08:34:56 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.7.4