diff --git a/src/Makefile b/src/Makefile index 77db1cf..420e98e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,6 +3,6 @@ vendor-reset-y += \ src/vendor-reset-dev.o \ src/ioctl.o \ src/ftrace.o \ - src/hooks.o + src/hook.o ccflags-y += -I$(src)/src diff --git a/src/hooks.c b/src/hook.c similarity index 62% rename from src/hooks.c rename to src/hook.c index c36793c..6cb9ae3 100644 --- a/src/hooks.c +++ b/src/hook.c @@ -17,12 +17,19 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include "vendor-reset-dev.h" +#include "hook.h" #include "ftrace.h" -#include "hooks.h" +#include "vendor-reset-dev.h" +#include + +#define vr_info(fmt, args...) pr_info("vendor-reset-hook: " fmt, ##args) +#define vr_warn(fmt, args...) pr_warn("vendor-reset-hook: " fmt, ##args) + +static bool install_hook = true; +module_param(install_hook, bool, 0); + +static bool hook_installed = false; static int (*orig_pci_dev_specific_reset)(struct pci_dev *dev, int probe); static int hooked_pci_dev_specific_reset(struct pci_dev *dev, int probe) @@ -42,6 +49,34 @@ static int hooked_pci_dev_specific_reset(struct pci_dev *dev, int probe) } struct ftrace_hook fh_hooks[] = { - HOOK("pci_dev_specific_reset", &orig_pci_dev_specific_reset, hooked_pci_dev_specific_reset), - {0}, + HOOK("pci_dev_specific_reset", &orig_pci_dev_specific_reset, hooked_pci_dev_specific_reset), + {0}, }; + +long vendor_reset_hook_init(void) +{ + int ret = 0; + + if (install_hook) + { + ret = fh_install_hooks(fh_hooks); + if (ret) + vr_warn("install failed"); + else + { + vr_info("installed"); + hook_installed = true; + } + } + + return ret; +} + +void vendor_reset_hook_exit(void) +{ + if (hook_installed) + { + fh_remove_hooks(fh_hooks); + hook_installed = false; + } +} diff --git a/src/hooks.h b/src/hook.h similarity index 85% rename from src/hooks.h rename to src/hook.h index 5ddafb3..3a055ec 100644 --- a/src/hooks.h +++ b/src/hook.h @@ -17,11 +17,10 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __VENDOR_RESET_HOOKS_H__ -#define __VENDOR_RESET_HOOKS_H__ +#ifndef __VENDOR_RESET_HOOK_H__ +#define __VENDOR_RESET_HOOK_H__ -#include +long vendor_reset_hook_init(void); +void vendor_reset_hook_exit(void); -extern struct ftrace_hook fh_hooks[]; - -#endif \ No newline at end of file +#endif diff --git a/src/module.c b/src/module.c index 112b984..cfda59e 100644 --- a/src/module.c +++ b/src/module.c @@ -20,13 +20,8 @@ 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; @@ -35,14 +30,9 @@ static int __init vendor_reset_init(void) if (ret) return ret; - if (install_hook) - { - ret = fh_install_hooks(fh_hooks); - if (ret) - goto err; - - vr_info("hooks installed\n"); - } + ret = vendor_reset_hook_init(); + if (ret) + goto err; return 0; @@ -53,15 +43,12 @@ err: static void __exit vendor_reset_exit(void) { - if (install_hook) - fh_remove_hooks(fh_hooks); - + vendor_reset_hook_exit(); 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 ");