From dd8eadc6e7aae148eb57534687657cf4be276af6 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 12 Nov 2020 11:56:08 +1100 Subject: [PATCH] [core] seperate ioctl setup from module init --- src/Makefile | 1 + src/ioctl.c | 61 ++++++++-------------------------------------- src/ioctl.h | 25 +++++++++++++++++++ src/module.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 51 deletions(-) create mode 100644 src/ioctl.h create mode 100644 src/module.c diff --git a/src/Makefile b/src/Makefile index f7e1853..77db1cf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,5 @@ vendor-reset-y += \ + src/module.o \ src/vendor-reset-dev.o \ src/ioctl.o \ src/ftrace.o \ diff --git a/src/ioctl.c b/src/ioctl.c index e24c699..cf54ecb 100644 --- a/src/ioctl.c +++ b/src/ioctl.c @@ -17,24 +17,12 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include -#include -#include - #include "vendor-reset-dev.h" #include "vendor-reset-ioctl.h" -#include "ftrace.h" -#include "hooks.h" - -#define VENDOR_RESET_DEVNAME "vendor_reset" - -#define vr_info(fmt, args...) pr_info("vendor-reset: " fmt, ##args) +#include -static bool install_hook = true; -module_param(install_hook, bool, 0); +#define VENDOR_RESET_IOCTL_DEVNAME "vendor_reset" static long vendor_reset_ioctl_reset(struct file * filp, unsigned long arg) { @@ -83,7 +71,7 @@ static long vendor_reset_ioctl(struct file * filp, unsigned int ioctl, return ret; } -static const struct file_operations vendor_reset_fops = +static const struct file_operations vendor_reset_ioctl_fops = { .owner = THIS_MODULE, .unlocked_ioctl = vendor_reset_ioctl, @@ -92,48 +80,19 @@ static const struct file_operations vendor_reset_fops = #endif }; -static struct miscdevice vendor_reset_misc = +static struct miscdevice vendor_reset_ioctl_misc = { .minor = MISC_DYNAMIC_MINOR, - .name = VENDOR_RESET_DEVNAME, - .fops = &vendor_reset_fops + .name = VENDOR_RESET_IOCTL_DEVNAME, + .fops = &vendor_reset_ioctl_fops }; -static int __init vendor_reset_init(void) +int vendor_reset_ioctl_init(void) { - int ret; - - ret = misc_register(&vendor_reset_misc); - if (ret) - return ret; - - if (install_hook) - { - ret = fh_install_hooks(fh_hooks); - if (ret) - goto err; - - vr_info("Hooks installed successfully\n"); - } - - return 0; - -err: - misc_deregister(&vendor_reset_misc); - return ret; + return misc_register(&vendor_reset_ioctl_misc); } -static void __exit vendor_reset_exit(void) +void vendor_reset_ioctl_exit(void) { - if (install_hook) - fh_remove_hooks(fh_hooks); - - misc_deregister(&vendor_reset_misc); + misc_deregister(&vendor_reset_ioctl_misc); } - -module_init(vendor_reset_init); -module_exit(vendor_reset_exit); - -MODULE_LICENSE("GPL v2"); -MODULE_AUTHOR("Geoffrey McRae "); -MODULE_AUTHOR("Adam Madsen "); diff --git a/src/ioctl.h b/src/ioctl.h new file mode 100644 index 0000000..3074b5f --- /dev/null +++ b/src/ioctl.h @@ -0,0 +1,25 @@ +/* +Vendor Reset - Vendor Specific Reset +Copyright (C) 2020 Geoffrey McRae + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _H_VENDOR_RESET_IOCTL +#define _H_VENDOR_RESET_IOCTL + +int vendor_reset_ioctl_init(void); +void vendor_reset_ioctl_exit(void); + +#endif diff --git a/src/module.c b/src/module.c new file mode 100644 index 0000000..112b984 --- /dev/null +++ b/src/module.c @@ -0,0 +1,68 @@ +/* +Vendor Reset - Vendor Specific Reset +Copyright (C) 2020 Geoffrey McRae +Copyright (C) 2020 Adam Madsen + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include + +#include "ioctl.h" +#include "ftrace.h" +#include "hooks.h" + +#define vr_info(fmt, args...) pr_info("vendor-reset: " fmt, ##args) + +static bool install_hook = true; + +static int __init vendor_reset_init(void) +{ + int ret; + + ret = vendor_reset_ioctl_init(); + if (ret) + return ret; + + if (install_hook) + { + ret = fh_install_hooks(fh_hooks); + if (ret) + goto err; + + vr_info("hooks installed\n"); + } + + return 0; + +err: + vendor_reset_ioctl_exit(); + return ret; +} + +static void __exit vendor_reset_exit(void) +{ + if (install_hook) + fh_remove_hooks(fh_hooks); + + vendor_reset_ioctl_exit(); +} + +module_init(vendor_reset_init); +module_exit(vendor_reset_exit); +module_param(install_hook, bool, 0); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Geoffrey McRae "); +MODULE_AUTHOR("Adam Madsen ");