From: Greg Kroah-Hartman Date: Tue, 26 Jan 2016 00:52:17 +0000 (-0800) Subject: greybus: audio_manager: use an 'ida' for the module id X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3c5de59473f88aeb12420f142d42801d4d389759;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git greybus: audio_manager: use an 'ida' for the module id Every time we hotplug an audio module, we get a new audio module id. We should recycle them instead of just constantly incrementing the number so we don't see things like: [178016.832580] Created audio module #6124 in the kernel logs. Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/audio_manager.c b/drivers/staging/greybus/audio_manager.c index 117676314daf..05af441be162 100644 --- a/drivers/staging/greybus/audio_manager.c +++ b/drivers/staging/greybus/audio_manager.c @@ -19,8 +19,7 @@ static struct kset *manager_kset; static LIST_HEAD(modules_list); static DEFINE_RWLOCK(modules_lock); - -static int current_module_id; +static DEFINE_IDA(module_id); /* helpers */ static struct gb_audio_manager_module *gb_audio_manager_get_locked(int id) @@ -43,12 +42,16 @@ int gb_audio_manager_add(struct gb_audio_manager_module_descriptor *desc) { struct gb_audio_manager_module *module; unsigned long flags; + int id; int err; + id = ida_simple_get(&module_id, 0, 0, GFP_KERNEL); err = gb_audio_manager_module_create(&module, manager_kset, - current_module_id++, desc); - if (err) + id, desc); + if (err) { + ida_simple_remove(&module_id, id); return err; + } /* Add it to the list */ write_lock_irqsave(&modules_lock, flags); @@ -72,6 +75,7 @@ int gb_audio_manager_remove(int id) return -EINVAL; } + ida_simple_remove(&module_id, module->id); list_del(&module->list); kobject_put(&module->kobj); write_unlock_irqrestore(&modules_lock, flags); @@ -175,6 +179,7 @@ static void __exit manager_exit(void) { gb_audio_manager_remove_all(); kset_unregister(manager_kset); + ida_destroy(&module_id); } module_init(manager_init);