float.c 706 B

1234567891011121314151617181920212223242526272829303132
  1. /* https://cirosantilli.com/linux-kernel-module-cheat#floating-point-in-kernel-modules */
  2. #include <linux/kernel.h>
  3. #include <linux/module.h>
  4. #include <asm/fpu/api.h> /* kernel_fpu_begin, kernel_fpu_end */
  5. /* float params are not supported, so we just go with int. */
  6. static int myfloat = 1;
  7. static int enable_fpu = 1;
  8. module_param(myfloat, int, S_IRUSR | S_IWUSR);
  9. module_param(enable_fpu, int, S_IRUSR | S_IWUSR);
  10. static int myinit(void)
  11. {
  12. if (enable_fpu) {
  13. kernel_fpu_begin();
  14. }
  15. if ((float)myfloat + 1.5f == 2.5f) {
  16. pr_info("magic value\n");
  17. }
  18. if (enable_fpu) {
  19. kernel_fpu_end();
  20. }
  21. return 0;
  22. }
  23. static void myexit(void) {}
  24. module_init(myinit)
  25. module_exit(myexit)
  26. MODULE_LICENSE("GPL");