Skip to contentSkip to conversation

gnss: Remove usage of the deprecated ida_simple_xxx API

PATCH In review Bo Liu 3 participants 3 messages Jun 16, 2022 – Jun 21, 2022 Gnss

lore
Share & tools
lore

Bo Liu

author
#0 lore raw

PATCH 1/1 gnss: Remove usage of the deprecated ida_simple_xxx API

Use ida_alloc_xxx()/ida_free() instead of
ida_simple_get()/ida_simple_remove().
The latter is deprecated and more verbose.

---
 drivers/gnss/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gnss/core.c +2 -2
index e6f94501cb28..1e82b7967570 100644
@@ -217,7 +217,7 @@ static void gnss_device_release(struct device *dev)
 
 	kfree(gdev->write_buf);
 	kfifo_free(&gdev->read_fifo);
-	ida_simple_remove(&gnss_minors, gdev->id);
+	ida_free(&gnss_minors, gdev->id);
 	kfree(gdev);
 }
 
@@ -232,7 +232,7 @@ struct gnss_device *gnss_allocate_device(struct device *parent)
 	if (!gdev)
 		return NULL;
 
-	id = ida_simple_get(&gnss_minors, 0, GNSS_MINORS, GFP_KERNEL);
+	id = ida_alloc_max(&gnss_minors, GNSS_MINORS - 1, GFP_KERNEL);
 	if (id < 0) {
 		kfree(gdev);
 		return NULL;
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw

Le 16/06/2022 à 06:47, Bo Liu a écrit :

Quoted 5 lines

Use ida_alloc_xxx()/ida_free() instead of
ida_simple_get()/ida_simple_remove().
The latter is deprecated and more verbose.

Hi,

even if a more detailed description about the reason of the added -1 would be welcomed:

Quoted 26 lines
---
  drivers/gnss/core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gnss/core.c +2 -2
index e6f94501cb28..1e82b7967570 100644
@@ -217,7 +217,7 @@ static void gnss_device_release(struct device *dev)
 
  	kfree(gdev->write_buf);
  	kfifo_free(&gdev->read_fifo);
-	ida_simple_remove(&gnss_minors, gdev->id);
+	ida_free(&gnss_minors, gdev->id);
  	kfree(gdev);
  }
 
@@ -232,7 +232,7 @@ struct gnss_device *gnss_allocate_device(struct device *parent)
  	if (!gdev)
  		return NULL;
 
-	id = ida_simple_get(&gnss_minors, 0, GNSS_MINORS, GFP_KERNEL);
+	id = ida_alloc_max(&gnss_minors, GNSS_MINORS - 1, GFP_KERNEL);
  	if (id < 0) {
  		kfree(gdev);
  		return NULL;
maintainer
#2 lore raw
Quoted 11 lines · Christophe JAILLET

Le 16/06/2022 à 06:47, Bo Liu a écrit :

Quoted 5 lines

Use ida_alloc_xxx()/ida_free() instead of
ida_simple_get()/ida_simple_remove().
The latter is deprecated and more verbose.

even if a more detailed description about the reason of the added -1 would be welcomed:

I agree, that should have been mentioned. And thanks for reviewing.

Quoted 17 lines
Quoted 17 lines
---
  drivers/gnss/core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gnss/core.c +1 -1
index e6f94501cb28..1e82b7967570 100644
@@ -217,7 +217,7 @@ static void gnss_device_release(struct device *dev)
 
  	kfree(gdev->write_buf);
  	kfifo_free(&gdev->read_fifo);
-	ida_simple_remove(&gnss_minors, gdev->id);
+	ida_free(&gnss_minors, gdev->id);
  	kfree(gdev);
  }
 
Quoted 6 lines

drivers/gnss/core.c struct gnss_device *gnss_allocate_device(struct device *parent) · line 235

Quoted 6 lines
drivers/gnss/core.c +1 -1
@@ -232,7 +232,7 @@ struct gnss_device *gnss_allocate_device(struct device *parent)
  	if (!gdev)
  		return NULL;
 
-	id = ida_simple_get(&gnss_minors, 0, GNSS_MINORS, GFP_KERNEL);
+	id = ida_alloc_max(&gnss_minors, GNSS_MINORS - 1, GFP_KERNEL);

I'm also not sure about the claim that the new interface is less verbose.

The above line is exactly as long as the old one, but somewhat harder to read due to the inclusive upper bound and the various allocator flavors (ε, max, min, range).

Quoted 3 lines

drivers/gnss/core.c struct gnss_device *gnss_allocate_device(struct device *parent) · line 238

Quoted 3 lines
drivers/gnss/core.c +0 -0
  	if (id < 0) {
  		kfree(gdev);
  		return NULL;

Now applied with an amended commit message:

	https://git.kernel.org/pub/scm/linux/kernel/git/johan/gnss.git/commit/?h=gnss-next&id=c0c725d7350ec8b8453257676a440bb4b2df2422

Johan