mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-22 13:30:42 +08:00
9289bfe59c
Sparse[1] is a semantic parser, capable of finding out the potential problems of Linux kernel code. This patch fixed the warnings. [1] https://www.kernel.org/doc/html/latest/dev-tools/sparse.html
56 lines
1013 B
C
56 lines
1013 B
C
/*
|
|
* example_rwlock.c
|
|
*/
|
|
#include <linux/interrupt.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
|
|
static DEFINE_RWLOCK(myrwlock);
|
|
|
|
static void example_read_lock(void)
|
|
{
|
|
unsigned long flags;
|
|
|
|
read_lock_irqsave(&myrwlock, flags);
|
|
pr_info("Read Locked\n");
|
|
|
|
/* Read from something */
|
|
|
|
read_unlock_irqrestore(&myrwlock, flags);
|
|
pr_info("Read Unlocked\n");
|
|
}
|
|
|
|
static void example_write_lock(void)
|
|
{
|
|
unsigned long flags;
|
|
|
|
write_lock_irqsave(&myrwlock, flags);
|
|
pr_info("Write Locked\n");
|
|
|
|
/* Write to something */
|
|
|
|
write_unlock_irqrestore(&myrwlock, flags);
|
|
pr_info("Write Unlocked\n");
|
|
}
|
|
|
|
static int example_rwlock_init(void)
|
|
{
|
|
pr_info("example_rwlock started\n");
|
|
|
|
example_read_lock();
|
|
example_write_lock();
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void example_rwlock_exit(void)
|
|
{
|
|
pr_info("example_rwlock exit\n");
|
|
}
|
|
|
|
module_init(example_rwlock_init);
|
|
module_exit(example_rwlock_exit);
|
|
|
|
MODULE_DESCRIPTION("Read/Write locks example");
|
|
MODULE_LICENSE("GPL");
|