mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	Since commit 43a7206b09 ("driver core: class: make class_register() take
a const *"), the driver core allows for struct class to be in read-only
memory, so move the fw_attr_class structure to be declared at build time
placing it into read-only memory, instead of having to be dynamically
allocated at boot time.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: "Ricardo B. Marliere" <ricardo@marliere.net>
Link: https://lore.kernel.org/r/20240305-class_cleanup-platform-v1-1-9085c97b9355@marliere.net
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
		
	
			
		
			
				
	
	
		
			52 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
// 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 const struct class firmware_attributes_class = {
 | 
						|
	.name = "firmware-attributes",
 | 
						|
};
 | 
						|
 | 
						|
int fw_attributes_class_get(const 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");
 |