1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /* Firmware attributes class helper module */
5 #include <linux/mutex.h>
6 #include <linux/device/class.h>
7 #include <linux/module.h>
8 #include "firmware_attributes_class.h"
10 static DEFINE_MUTEX(fw_attr_lock);
11 static int fw_attr_inuse;
13 static struct class firmware_attributes_class = {
14 .name = "firmware-attributes",
17 int fw_attributes_class_get(struct class **fw_attr_class)
21 mutex_lock(&fw_attr_lock);
22 if (!fw_attr_inuse) { /*first time class is being used*/
23 err = class_register(&firmware_attributes_class);
25 mutex_unlock(&fw_attr_lock);
30 *fw_attr_class = &firmware_attributes_class;
31 mutex_unlock(&fw_attr_lock);
34 EXPORT_SYMBOL_GPL(fw_attributes_class_get);
36 int fw_attributes_class_put(void)
38 mutex_lock(&fw_attr_lock);
40 mutex_unlock(&fw_attr_lock);
44 if (!fw_attr_inuse) /* No more consumers */
45 class_unregister(&firmware_attributes_class);
46 mutex_unlock(&fw_attr_lock);
49 EXPORT_SYMBOL_GPL(fw_attributes_class_put);
52 MODULE_LICENSE("GPL");