File: firmware_attributes_class.c

package info (click to toggle)
linux 6.1.159-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,495,620 kB
  • sloc: ansic: 23,458,997; asm: 266,680; sh: 110,635; makefile: 49,889; python: 36,941; perl: 36,837; cpp: 6,055; yacc: 4,908; lex: 2,725; awk: 1,440; ruby: 25; sed: 5
file content (52 lines) | stat: -rw-r--r-- 1,209 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: GPL-2.0-or-later

/* Firmware attributes class helper module */

#include <linux/mutex.h>
#include <linux/device/class.h>
#include <linux/module.h>
#include "firmware_attributes_class.h"

static DEFINE_MUTEX(fw_attr_lock);
static int fw_attr_inuse;

static struct class firmware_attributes_class = {
	.name = "firmware-attributes",
};

int fw_attributes_class_get(struct class **fw_attr_class)
{
	int err;

	mutex_lock(&fw_attr_lock);
	if (!fw_attr_inuse) { /*first time class is being used*/
		err = class_register(&firmware_attributes_class);
		if (err) {
			mutex_unlock(&fw_attr_lock);
			return err;
		}
	}
	fw_attr_inuse++;
	*fw_attr_class = &firmware_attributes_class;
	mutex_unlock(&fw_attr_lock);
	return 0;
}
EXPORT_SYMBOL_GPL(fw_attributes_class_get);

int fw_attributes_class_put(void)
{
	mutex_lock(&fw_attr_lock);
	if (!fw_attr_inuse) {
		mutex_unlock(&fw_attr_lock);
		return -EINVAL;
	}
	fw_attr_inuse--;
	if (!fw_attr_inuse) /* No more consumers */
		class_unregister(&firmware_attributes_class);
	mutex_unlock(&fw_attr_lock);
	return 0;
}
EXPORT_SYMBOL_GPL(fw_attributes_class_put);

MODULE_AUTHOR("Mark Pearson <markpearson@lenovo.com>");
MODULE_LICENSE("GPL");