From 898768a97656c128a75563107a5b428d8f2b90f6 Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Mon, 11 Feb 2019 16:56:34 -0500 Subject: [PATCH] c2port: Convert IDR to IDA Signed-off-by: Matthew Wilcox --- drivers/misc/c2port/core.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index 33bba1802289..aa869fce1bcc 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -23,8 +23,7 @@ #define DRIVER_NAME "c2port" #define DRIVER_VERSION "0.51.0" -static DEFINE_SPINLOCK(c2port_idr_lock); -static DEFINE_IDR(c2port_idr); +static DEFINE_IDA(c2ports); /* * Local variables @@ -903,14 +902,9 @@ struct c2port_device *c2port_device_register(char *name, if (unlikely(!c2dev)) return ERR_PTR(-ENOMEM); - idr_preload(GFP_KERNEL); - spin_lock_irq(&c2port_idr_lock); - ret = idr_alloc(&c2port_idr, c2dev, 0, 0, GFP_NOWAIT); - spin_unlock_irq(&c2port_idr_lock); - idr_preload_end(); - + ret = ida_alloc(&c2ports, GFP_KERNEL); if (ret < 0) - goto error_idr_alloc; + goto error_ida; c2dev->id = ret; bin_attr_flash_data.size = ops->blocks_num * ops->block_size; @@ -940,11 +934,9 @@ struct c2port_device *c2port_device_register(char *name, return c2dev; error_device_create: - spin_lock_irq(&c2port_idr_lock); - idr_remove(&c2port_idr, c2dev->id); - spin_unlock_irq(&c2port_idr_lock); + ida_free(&c2ports, c2dev->id); -error_idr_alloc: +error_ida: kfree(c2dev); return ERR_PTR(ret); @@ -958,9 +950,7 @@ void c2port_device_unregister(struct c2port_device *c2dev) dev_info(c2dev->dev, "C2 port %s removed\n", c2dev->name); - spin_lock_irq(&c2port_idr_lock); - idr_remove(&c2port_idr, c2dev->id); - spin_unlock_irq(&c2port_idr_lock); + ida_free(&c2ports, c2dev->id); device_destroy(c2port_class, c2dev->id); -- 2.50.1