linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: Use ida to manage SPI bus number
@ 2017-09-06 11:26 Baolin Wang
  2017-09-06 13:28 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Baolin Wang @ 2017-09-06 11:26 UTC (permalink / raw)
  To: broonie; +Cc: linux-spi, linux-kernel, baolin.wang

This patch adds one static ida variable to manage SPI bus number, moreover
we can get dynamic bus number from ida instead of one "dynamic" IDs, which
can be removed.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/spi/spi.c |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 4fcbb0a..1498be2 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -40,10 +40,13 @@
 #include <linux/ioport.h>
 #include <linux/acpi.h>
 #include <linux/highmem.h>
+#include <linux/idr.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/spi.h>
 
+static DEFINE_IDA(spi_bus_ida);
+
 static void spidev_release(struct device *dev)
 {
 	struct spi_device	*spi = to_spi_device(dev);
@@ -2052,7 +2055,6 @@ static int of_spi_register_master(struct spi_controller *ctlr)
  */
 int spi_register_controller(struct spi_controller *ctlr)
 {
-	static atomic_t		dyn_bus_id = ATOMIC_INIT((1<<15) - 1);
 	struct device		*dev = ctlr->dev.parent;
 	struct boardinfo	*bi;
 	int			status = -ENODEV;
@@ -2076,12 +2078,15 @@ int spi_register_controller(struct spi_controller *ctlr)
 	if ((ctlr->bus_num < 0) && ctlr->dev.of_node)
 		ctlr->bus_num = of_alias_get_id(ctlr->dev.of_node, "spi");
 
-	/* convention:  dynamically assigned bus IDs count down from the max */
+	if (ctlr->bus_num >= 0)
+		ctlr->bus_num = ida_simple_get(&spi_bus_ida, ctlr->bus_num,
+					       ctlr->bus_num + 1, GFP_KERNEL);
+
 	if (ctlr->bus_num < 0) {
-		/* FIXME switch to an IDR based scheme, something like
-		 * I2C now uses, so we can't run out of "dynamic" IDs
-		 */
-		ctlr->bus_num = atomic_dec_return(&dyn_bus_id);
+		ctlr->bus_num = ida_simple_get(&spi_bus_ida, 0, 0, GFP_KERNEL);
+		if (ctlr->bus_num < 0)
+			return ctlr->bus_num;
+
 		dynamic = 1;
 	}
 
@@ -2128,7 +2133,10 @@ int spi_register_controller(struct spi_controller *ctlr)
 	/* Register devices from the device tree and ACPI */
 	of_register_spi_devices(ctlr);
 	acpi_register_spi_devices(ctlr);
+
+	return 0;
 done:
+	ida_simple_remove(&spi_bus_ida, ctlr->bus_num);
 	return status;
 }
 EXPORT_SYMBOL_GPL(spi_register_controller);
@@ -2202,6 +2210,7 @@ void spi_unregister_controller(struct spi_controller *ctlr)
 	list_del(&ctlr->list);
 	mutex_unlock(&board_lock);
 
+	ida_simple_remove(&spi_bus_ida, ctlr->bus_num);
 	dummy = device_for_each_child(&ctlr->dev, NULL, __unregister);
 	device_unregister(&ctlr->dev);
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: Use ida to manage SPI bus number
  2017-09-06 11:26 [PATCH] spi: Use ida to manage SPI bus number Baolin Wang
@ 2017-09-06 13:28 ` Mark Brown
  2017-09-08  6:26   ` Baolin Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2017-09-06 13:28 UTC (permalink / raw)
  To: Baolin Wang; +Cc: linux-spi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]

On Wed, Sep 06, 2017 at 07:26:51PM +0800, Baolin Wang wrote:
> This patch adds one static ida variable to manage SPI bus number, moreover
> we can get dynamic bus number from ida instead of one "dynamic" IDs, which
> can be removed.

Someone else actually addressed this TODO item just in the last
development cycle, v4.14 should contain an equivalent patch.  Always
best to check linux-next for the latest development state!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] spi: Use ida to manage SPI bus number
  2017-09-06 13:28 ` Mark Brown
@ 2017-09-08  6:26   ` Baolin Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Baolin Wang @ 2017-09-08  6:26 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, LKML

Hi Mark,

On 6 September 2017 at 21:28, Mark Brown <broonie@kernel.org> wrote:
> On Wed, Sep 06, 2017 at 07:26:51PM +0800, Baolin Wang wrote:
>> This patch adds one static ida variable to manage SPI bus number, moreover
>> we can get dynamic bus number from ida instead of one "dynamic" IDs, which
>> can be removed.
>
> Someone else actually addressed this TODO item just in the last
> development cycle, v4.14 should contain an equivalent patch.  Always
> best to check linux-next for the latest development state!

Yes, I saw that patch. Then ignore this patch, sorry.

-- 
Baolin.wang
Best Regards

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-08  6:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-06 11:26 [PATCH] spi: Use ida to manage SPI bus number Baolin Wang
2017-09-06 13:28 ` Mark Brown
2017-09-08  6:26   ` Baolin Wang

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).