public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmem: switch to simpler IDA interface
@ 2020-09-08 13:27 Bartosz Golaszewski
  2020-09-11 12:04 ` Srinivas Kandagatla
  0 siblings, 1 reply; 2+ messages in thread
From: Bartosz Golaszewski @ 2020-09-08 13:27 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We don't need to specify any ranges when allocating IDs so we can switch
to ida_alloc() and ida_free() instead of the ida_simple_ counterparts.

ida_simple_get(ida, 0, 0, gfp) is equivalent to
ida_alloc_range(ida, 0, UINT_MAX, gfp) which is equivalent to
ida_alloc(ida, gfp). Note: IDR will never actually allocate an ID
larger than INT_MAX.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/nvmem/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 6cd3edb2eaf6..cd332d711dd1 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -321,7 +321,7 @@ static void nvmem_release(struct device *dev)
 {
 	struct nvmem_device *nvmem = to_nvmem_device(dev);
 
-	ida_simple_remove(&nvmem_ida, nvmem->id);
+	ida_free(&nvmem_ida, nvmem->id);
 	gpiod_put(nvmem->wp_gpio);
 	kfree(nvmem);
 }
@@ -596,7 +596,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (!nvmem)
 		return ERR_PTR(-ENOMEM);
 
-	rval  = ida_simple_get(&nvmem_ida, 0, 0, GFP_KERNEL);
+	rval  = ida_alloc(&nvmem_ida, GFP_KERNEL);
 	if (rval < 0) {
 		kfree(nvmem);
 		return ERR_PTR(rval);
@@ -608,7 +608,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 		nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
 						    GPIOD_OUT_HIGH);
 	if (IS_ERR(nvmem->wp_gpio)) {
-		ida_simple_remove(&nvmem_ida, nvmem->id);
+		ida_free(&nvmem_ida, nvmem->id);
 		rval = PTR_ERR(nvmem->wp_gpio);
 		kfree(nvmem);
 		return ERR_PTR(rval);
-- 
2.17.1


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

* Re: [PATCH] nvmem: switch to simpler IDA interface
  2020-09-08 13:27 [PATCH] nvmem: switch to simpler IDA interface Bartosz Golaszewski
@ 2020-09-11 12:04 ` Srinivas Kandagatla
  0 siblings, 0 replies; 2+ messages in thread
From: Srinivas Kandagatla @ 2020-09-11 12:04 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-kernel, Bartosz Golaszewski



On 08/09/2020 14:27, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> We don't need to specify any ranges when allocating IDs so we can switch
> to ida_alloc() and ida_free() instead of the ida_simple_ counterparts.
> 
> ida_simple_get(ida, 0, 0, gfp) is equivalent to
> ida_alloc_range(ida, 0, UINT_MAX, gfp) which is equivalent to
> ida_alloc(ida, gfp). Note: IDR will never actually allocate an ID
> larger than INT_MAX.
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>   drivers/nvmem/core.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

thanks Applied!

--srini
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 6cd3edb2eaf6..cd332d711dd1 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -321,7 +321,7 @@ static void nvmem_release(struct device *dev)
>   {
>   	struct nvmem_device *nvmem = to_nvmem_device(dev);
>   
> -	ida_simple_remove(&nvmem_ida, nvmem->id);
> +	ida_free(&nvmem_ida, nvmem->id);
>   	gpiod_put(nvmem->wp_gpio);
>   	kfree(nvmem);
>   }
> @@ -596,7 +596,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   	if (!nvmem)
>   		return ERR_PTR(-ENOMEM);
>   
> -	rval  = ida_simple_get(&nvmem_ida, 0, 0, GFP_KERNEL);
> +	rval  = ida_alloc(&nvmem_ida, GFP_KERNEL);
>   	if (rval < 0) {
>   		kfree(nvmem);
>   		return ERR_PTR(rval);
> @@ -608,7 +608,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   		nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
>   						    GPIOD_OUT_HIGH);
>   	if (IS_ERR(nvmem->wp_gpio)) {
> -		ida_simple_remove(&nvmem_ida, nvmem->id);
> +		ida_free(&nvmem_ida, nvmem->id);
>   		rval = PTR_ERR(nvmem->wp_gpio);
>   		kfree(nvmem);
>   		return ERR_PTR(rval);
> 

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

end of thread, other threads:[~2020-09-11 12:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-08 13:27 [PATCH] nvmem: switch to simpler IDA interface Bartosz Golaszewski
2020-09-11 12:04 ` Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox