Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/math-emu: Fix function cast warnings

clang-16 warns about casting function pointers with incompatible
prototypes. The x86 math-emu code does this in a number of places
to call some trivial functions that need no arguments:

arch/x86/math-emu/fpu_etc.c:124:14: error: cast from 'void (*)(void)' to 'FUNC_ST0' \
(aka 'void (*)(struct fpu__reg *, unsigned char)') converts to incompatible function \
type [-Werror,-Wcast-function-type-strict]
124 | fchs, fabs, (FUNC_ST0) FPU_illegal, (FUNC_ST0) FPU_illegal,
| ^~~~~~~~~~~~~~~~~~~~~~

arch/x86/math-emu/fpu_trig.c:1634:19: error: cast from 'void (*)(void)' to 'FUNC_ST0' \
(aka 'void (*)(struct fpu__reg *, unsigned char)') converts to incompatible function \
type [-Werror,-Wcast-function-type-strict]
1634 | fxtract, fprem1, (FUNC_ST0) fdecstp, (FUNC_ST0) fincstp
| ^~~~~~~~~~~~~~~~~~

arch/x86/math-emu/reg_constant.c:112:53: error: cast from 'void (*)(void)' to 'FUNC_RC' \
(aka 'void (*)(int)') converts to incompatible function \
type [-Werror,-Wcast-function-type-strict]
112 | fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, (FUNC_RC) FPU_illegal

Change the fdecstp() and fincstp() functions to actually have the correct
prototypes based on the caller, and add wrappers around FPU_illegal() for
adapting those.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/lkml/20240213095631.454543-1-arnd@kernel.org

authored by

Arnd Bergmann and committed by
Borislav Petkov (AMD)
e0ca9353 cb517619

+16 -6
+7 -2
arch/x86/math-emu/fpu_etc.c
··· 120 120 setcc(c); 121 121 } 122 122 123 + static void FPU_ST0_illegal(FPU_REG *st0_ptr, u_char st0_tag) 124 + { 125 + FPU_illegal(); 126 + } 127 + 123 128 static FUNC_ST0 const fp_etc_table[] = { 124 - fchs, fabs, (FUNC_ST0) FPU_illegal, (FUNC_ST0) FPU_illegal, 125 - ftst_, fxam, (FUNC_ST0) FPU_illegal, (FUNC_ST0) FPU_illegal 129 + fchs, fabs, FPU_ST0_illegal, FPU_ST0_illegal, 130 + ftst_, fxam, FPU_ST0_illegal, FPU_ST0_illegal, 126 131 }; 127 132 128 133 void FPU_etc(void)
+3 -3
arch/x86/math-emu/fpu_trig.c
··· 433 433 #endif /* PARANOID */ 434 434 } 435 435 436 - static void fdecstp(void) 436 + static void fdecstp(FPU_REG *st0_ptr, u_char st0_tag) 437 437 { 438 438 clear_C1(); 439 439 top--; 440 440 } 441 441 442 - static void fincstp(void) 442 + static void fincstp(FPU_REG *st0_ptr, u_char st0_tag) 443 443 { 444 444 clear_C1(); 445 445 top++; ··· 1631 1631 1632 1632 static FUNC_ST0 const trig_table_a[] = { 1633 1633 f2xm1, fyl2x, fptan, fpatan, 1634 - fxtract, fprem1, (FUNC_ST0) fdecstp, (FUNC_ST0) fincstp 1634 + fxtract, fprem1, fdecstp, fincstp, 1635 1635 }; 1636 1636 1637 1637 void FPU_triga(void)
+6 -1
arch/x86/math-emu/reg_constant.c
··· 108 108 109 109 typedef void (*FUNC_RC) (int); 110 110 111 + static void FPU_RC_illegal(int unused) 112 + { 113 + FPU_illegal(); 114 + } 115 + 111 116 static FUNC_RC constants_table[] = { 112 - fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, (FUNC_RC) FPU_illegal 117 + fld1, fldl2t, fldl2e, fldpi, fldlg2, fldln2, fldz, FPU_RC_illegal 113 118 }; 114 119 115 120 void fconst(void)