From patchwork Thu Mar 22 19:12:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Himanshu Jha X-Patchwork-Id: 10302167 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 94653600F6 for ; Thu, 22 Mar 2018 19:13:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85AEE28814 for ; Thu, 22 Mar 2018 19:13:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A0B0288F3; Thu, 22 Mar 2018 19:13:47 +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=-5.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, 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 1A7DC28814 for ; Thu, 22 Mar 2018 19:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751894AbeCVTNN (ORCPT ); Thu, 22 Mar 2018 15:13:13 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:32920 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751831AbeCVTNK (ORCPT ); Thu, 22 Mar 2018 15:13:10 -0400 Received: by mail-pl0-f68.google.com with SMTP id c11-v6so5928120plo.0; Thu, 22 Mar 2018 12:13:10 -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=4PpvmNGRuHtFZUjwvJ3trU7QaYWdtfqKyOw8Zc+BfKk=; b=TJdkwzDZTyyxeK46gSyCR9FOQwBfnGJE4He6uTV++rrhVfD+PGzIFvI0BOOztyFkhS VxQyMfTjPje8bZXvS5sxdcUBPV+xEntHVnnOfYZLy+Ay5eWottmTWycq07bDdSRTIRQG sJ2JFQ2QWTUgPlm/tO+uvBbszczq0piMVR68iLS8Yn3FvbkzZPIfMqJO1FNl5oTOPN3O PzLHC/7Jr1dcQG9Equ98N9n+zM/IWrCWmI7A0E0JjuHTxb9DorEZOfHx7s/BnmHtEtJA h3R7luV43eKSZMBLWcAENe1O86kW5txI007AaZkLLL3N7H2nCmpUEZcqEFzjiWoS2q/F +0WA== 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=4PpvmNGRuHtFZUjwvJ3trU7QaYWdtfqKyOw8Zc+BfKk=; b=hbZYF67g9S/frSU8a9ZO+ipKCHfMI4ezoEybi1rXMOuBFQ2ROcsx9vp3a39Qv7Z6iS ZcdjLFAdygeYIgyVZ1KIcbDoG6TW5HGjbacu9nPGgmwzut8sBQLoFBayYWZfKp7ZM6LQ npvrn95N7fd0N5xtCSkzcpER1f5d2SV1dl2iqJD7CyPkfesBhYpoGLJJ8PQlOeKKPU8/ 3iNbjseuL+9qyPn2JlPkZ/wFuypA0SIZASRDvsb2F0MNRqgxpg7UHZ1tefBSULxst09j L9OJ2u/pkQriPIbvYh7ApKuGAK2b5PZYT7/AmYOTxKurm5LxaH2RalmoJQqEfaYccuy0 Gk4Q== X-Gm-Message-State: AElRT7FeUYp6853nB4xPDffTSvaNuEKnn6Ya8Hibt5lH9dHAgSRHyVpl F1xjSEBjGr4na+O9RhtMIavCVA== X-Google-Smtp-Source: AG47ELt7hGIxGLzPxvtVj0xXLLJEp0tOAVOIa5ufW6sbCs4Ll8KpbAhXZ9mpTxW8w2HTw7e6daxVwA== X-Received: by 2002:a17:902:8206:: with SMTP id x6-v6mr19660253pln.256.1521745990085; Thu, 22 Mar 2018 12:13:10 -0700 (PDT) Received: from localhost.localdomain ([103.46.193.14]) by smtp.gmail.com with ESMTPSA id w83sm15089628pfi.33.2018.03.22.12.13.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Mar 2018 12:13:09 -0700 (PDT) From: Himanshu Jha To: 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, 21cnbao@gmail.com, Himanshu Jha Subject: [PATCH 2/4] Staging: iio: accel: adis16201: Use GENMASK Date: Fri, 23 Mar 2018 00:42:43 +0530 Message-Id: <1521745965-26972-2-git-send-email-himanshujha199640@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521745965-26972-1-git-send-email-himanshujha199640@gmail.com> References: <1521230786-18155-10-git-send-email-himanshujha199640@gmail.com> <1521745965-26972-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 GENMASK to improve readability and remove the local variables used to store intermediate data. Signed-off-by: Himanshu Jha --- drivers/staging/iio/accel/adis16201.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c index b04dbb3..e7593fa 100644 --- a/drivers/staging/iio/accel/adis16201.c +++ b/drivers/staging/iio/accel/adis16201.c @@ -185,28 +185,24 @@ static int adis16201_write_raw(struct iio_dev *indio_dev, long mask) { struct adis *st = iio_priv(indio_dev); - int bits; - s16 val16; - u8 addr; + int m; - switch (mask) { - case IIO_CHAN_INFO_CALIBBIAS: - switch (chan->type) { - case IIO_ACCEL: - bits = 12; - break; - case IIO_INCLI: - bits = 9; - break; - default: - return -EINVAL; + if (mask != IIO_CHAN_INFO_CALIBBIAS) + return -EINVAL; + + switch (chan->type) { + case IIO_ACCEL: + m = GENMASK(11, 0); + break; + case IIO_INCLI: + m = GENMASK(8, 0); + break; + default: + return -EINVAL; } - val16 = val & ((1 << bits) - 1); - addr = adis16201_addresses[chan->scan_index]; - return adis_write_reg_16(st, addr, val16); - } - return -EINVAL; + return adis_write_reg_16(st, adis16201_addresses[chan->scan_index], + val & m); } static const struct iio_chan_spec adis16201_channels[] = {