All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [PATCH] gpio: sim: allocate IDA numbers earlier
Date: Fri, 23 Apr 2021 17:23:33 +0200	[thread overview]
Message-ID: <20210423152333.6299-1-brgl@bgdev.pl> (raw)

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Instead of allocating the device ID number for gpio-sim platform devices
when the associated configfs item is committed, do it already when the
item is created. This way we can display the device name even when the
chip is still pending. Once it's committed the user can easily identify
the chip by its real device name. This will allow launching concurrent
user-space test suites with gpio-sim.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
Hi all! This is a late one for which I'm sorry but I realized that this
change will allow us to launch test-suites concurrently if we allow the
user-space to read the device name before the device is created and then
wait for this specific name to appear in a udev add event.

 drivers/gpio/gpio-sim.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 92493b98c51b..2e2e6399e453 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -409,6 +409,7 @@ struct gpio_sim_chip_config {
 	 * item is 'live'.
 	 */
 	struct platform_device *pdev;
+	int id;
 
 	/*
 	 * Each configfs filesystem operation is protected with the subsystem
@@ -442,7 +443,7 @@ static ssize_t gpio_sim_config_dev_name_show(struct config_item *item,
 	if (pdev)
 		ret = sprintf(page, "%s\n", dev_name(&pdev->dev));
 	else
-		ret = sprintf(page, "none\n");
+		ret = sprintf(page, "gpio-sim.%d\n", config->id);
 	mutex_unlock(&config->lock);
 
 	return ret;
@@ -724,6 +725,7 @@ static void gpio_sim_chip_config_release(struct config_item *item)
 	struct gpio_sim_chip_config *config = to_gpio_sim_chip_config(item);
 
 	mutex_destroy(&config->lock);
+	ida_free(&gpio_sim_ida, config->id);
 	kfree_strarray(config->line_names, config->num_line_names);
 	kfree(config);
 }
@@ -747,6 +749,12 @@ gpio_sim_config_make_item(struct config_group *group, const char *name)
 	if (!config)
 		return ERR_PTR(-ENOMEM);
 
+	config->id = ida_alloc(&gpio_sim_ida, GFP_KERNEL);
+	if (config->id < 0) {
+		kfree(config);
+		return ERR_PTR(config->id);
+	}
+
 	config_item_init_type_name(&config->item, name,
 				   &gpio_sim_chip_config_type);
 	config->num_lines = 1;
@@ -781,18 +789,12 @@ static int gpio_sim_config_commit_item(struct config_item *item)
 						config->line_names,
 						config->num_line_names);
 
-	pdevinfo.id = ida_alloc(&gpio_sim_ida, GFP_KERNEL);
-	if (pdevinfo.id < 0) {
-		mutex_unlock(&config->lock);
-		return pdevinfo.id;
-	}
-
 	pdevinfo.name = "gpio-sim";
 	pdevinfo.properties = properties;
+	pdevinfo.id = config->id;
 
 	pdev = platform_device_register_full(&pdevinfo);
 	if (IS_ERR(pdev)) {
-		ida_free(&gpio_sim_ida, pdevinfo.id);
 		mutex_unlock(&config->lock);
 		return PTR_ERR(pdev);
 	}
@@ -806,15 +808,12 @@ static int gpio_sim_config_commit_item(struct config_item *item)
 static int gpio_sim_config_uncommit_item(struct config_item *item)
 {
 	struct gpio_sim_chip_config *config = to_gpio_sim_chip_config(item);
-	int id;
 
 	mutex_lock(&config->lock);
-	id = config->pdev->id;
 	platform_device_unregister(config->pdev);
 	config->pdev = NULL;
 	mutex_unlock(&config->lock);
 
-	ida_free(&gpio_sim_ida, id);
 	return 0;
 }
 
-- 
2.30.1


             reply	other threads:[~2021-04-23 15:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 15:23 Bartosz Golaszewski [this message]
2021-04-23 15:40 ` [PATCH] gpio: sim: allocate IDA numbers earlier Andy Shevchenko
2021-04-26  7:16   ` Bartosz Golaszewski

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=20210423152333.6299-1-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.