Skip to content

Commit

Permalink
Add reference count of current module
Browse files Browse the repository at this point in the history
This prevent module from unexpected unload
  • Loading branch information
atmouse- committed Mar 15, 2023
1 parent 17320b1 commit 7fb44f8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions virtual_touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ static int __init virt_ts_init(void)

static int device_open(struct inode *inode, struct file *file) {
if (Device_Open) return -EBUSY;
try_module_get(THIS_MODULE);
++Device_Open;
return 0;
}

static int device_release(struct inode *inode, struct file *file) {
--Device_Open;
module_put(THIS_MODULE);
return 0;
}

Expand Down

0 comments on commit 7fb44f8

Please sign in to comment.