linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
	Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [PATCH 18/18] gpio: mockup: add helpers for accessing the gpio ranges
Date: Mon, 27 Nov 2017 11:48:54 +0100	[thread overview]
Message-ID: <20171127104854.333-19-brgl@bgdev.pl> (raw)
In-Reply-To: <20171127104854.333-1-brgl@bgdev.pl>

In order to avoid repeating the calculations on every access - add
helpers for gpio base and ngpio components of the ranges array.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/gpio/gpio-mockup.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index a6bfbe58bc63..ea8c730d8af1 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -81,6 +81,16 @@ module_param_named(gpio_mockup_named_lines,
 
 static struct dentry *gpio_mockup_dbg_dir;
 
+static int gpio_mockup_range_base(unsigned int index)
+{
+	return gpio_mockup_ranges[index * 2];
+}
+
+static int gpio_mockup_range_ngpio(unsigned int index)
+{
+	return gpio_mockup_ranges[index * 2 + 1];
+}
+
 static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset)
 {
 	struct gpio_mockup_chip *chip = gpiochip_get_data(gc);
@@ -351,7 +361,7 @@ static int __init gpio_mockup_init(void)
 	 * always be greater than 0.
 	 */
 	for (i = 0; i < num_chips; i++) {
-		if (gpio_mockup_ranges[i * 2 + 1] < 0)
+		if (gpio_mockup_range_ngpio(i) < 0)
 			return -EINVAL;
 	}
 
@@ -367,10 +377,10 @@ static int __init gpio_mockup_init(void)
 
 	for (i = 0; i < num_chips; i++) {
 		pdata.index = index++;
-		pdata.base = gpio_mockup_ranges[i * 2];
+		pdata.base = gpio_mockup_range_base(i);
 		pdata.ngpio = pdata.base < 0
-				? gpio_mockup_ranges[i * 2 + 1]
-				: gpio_mockup_ranges[i * 2 + 1] - pdata.base;
+				? gpio_mockup_range_ngpio(i)
+				: gpio_mockup_range_ngpio(i) - pdata.base;
 		pdata.named_lines = gpio_mockup_named_lines;
 
 		pdev = platform_device_register_resndata(NULL,
-- 
2.15.0

  parent reply	other threads:[~2017-11-27 10:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27 10:48 [PATCH 00/18] gpio: mockup: updates for v4.16 Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 01/18] gpio: mockup: add missing prefixes Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 02/18] gpio: mockup: parse the module params in init, not probe Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 03/18] gpio: mockup: verify the number of GPIO chips requested Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 04/18] gpio: mockup: rework device probing Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 05/18] gpio: mockup: implement gpio_mockup_err() Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 06/18] gpio: mockup: remove a stray tab Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 07/18] gpio: mockup: merge gpio_mockup_add() into gpio_mockup_probe() Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 08/18] gpio: mockup: pass the named_lines parameter over platform_data Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 09/18] gpio: mockup: extend the debugfs layout Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 10/18] gpio: mockup: change the type of value field in line state struct Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 11/18] gpio: mockup: group code by logic Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 12/18] gpio: mockup: fix debugfs handling Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 13/18] gpio: mockup: verify that ngpio > 0 Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 14/18] gpio: mockup: tweak line breaks Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 15/18] gpio: mockup: implement gpio_mockup_set_multiple() Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 16/18] gpio: mockup: modify the return value check for devm_irq_sim_init() Bartosz Golaszewski
2017-11-27 10:48 ` [PATCH 17/18] gpio: mockup: rename gpio_mockup_params_nr to gpio_mockup_num_ranges Bartosz Golaszewski
2017-11-27 10:48 ` Bartosz Golaszewski [this message]
2017-12-01 19:38 ` [PATCH 00/18] gpio: mockup: updates for v4.16 Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171127104854.333-19-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=bamvor.zhangjian@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).