* [PATCH] x86: math-emu: Fix function cast warning
@ 2021-03-22 17:06 Arnd Bergmann
2021-03-22 20:35 ` Ingo Molnar
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2021-03-22 17:06 UTC (permalink / raw)
To: Bill Metzenthen, Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86
Cc: Arnd Bergmann, H. Peter Anvin, Gustavo A. R. Silva, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
Building with 'make W=1', gcc points out that casting between
incompatible function types can be dangerous:
arch/x86/math-emu/fpu_trig.c:1638:60: error: cast between incompatible function types from ‘int (*)(FPU_REG *, u_char)’ {aka ‘int (*)(struct fpu__reg *, unsigned char)’} to ‘void (*)(FPU_REG *, u_char)’ {aka ‘void (*)(struct fpu__reg *, unsigned char)’} [-Werror=cast-function-type]
1638 | fprem, fyl2xp1, fsqrt_, fsincos, frndint_, fscale, (FUNC_ST0) fsin, fcos
| ^
This one seems harmless, but it is easy enough to work around it by
adding an intermediate function that adjusts the return type.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
arch/x86/math-emu/fpu_trig.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/arch/x86/math-emu/fpu_trig.c b/arch/x86/math-emu/fpu_trig.c
index 4a9887851ad8..aebfdb244cb4 100644
--- a/arch/x86/math-emu/fpu_trig.c
+++ b/arch/x86/math-emu/fpu_trig.c
@@ -547,7 +547,7 @@ static void frndint_(FPU_REG *st0_ptr, u_char st0_tag)
single_arg_error(st0_ptr, st0_tag);
}
-static int fsin(FPU_REG *st0_ptr, u_char tag)
+static int do_fsin(FPU_REG *st0_ptr, u_char tag)
{
u_char arg_sign = getsign(st0_ptr);
@@ -608,6 +608,11 @@ static int fsin(FPU_REG *st0_ptr, u_char tag)
}
}
+static void fsin(FPU_REG *st0_ptr, u_char tag)
+{
+ fsin(st0_ptr, tag);
+}
+
static int f_cos(FPU_REG *st0_ptr, u_char tag)
{
u_char st0_sign;
@@ -724,7 +729,7 @@ static void fsincos(FPU_REG *st0_ptr, u_char st0_tag)
}
reg_copy(st0_ptr, &arg);
- if (!fsin(st0_ptr, st0_tag)) {
+ if (!do_fsin(st0_ptr, st0_tag)) {
push();
FPU_copy_to_reg0(&arg, st0_tag);
f_cos(&st(0), st0_tag);
@@ -1635,7 +1640,7 @@ void FPU_triga(void)
}
static FUNC_ST0 const trig_table_b[] = {
- fprem, fyl2xp1, fsqrt_, fsincos, frndint_, fscale, (FUNC_ST0) fsin, fcos
+ fprem, fyl2xp1, fsqrt_, fsincos, frndint_, fscale, fsin, fcos
};
void FPU_trigb(void)
--
2.29.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] x86: math-emu: Fix function cast warning
2021-03-22 17:06 [PATCH] x86: math-emu: Fix function cast warning Arnd Bergmann
@ 2021-03-22 20:35 ` Ingo Molnar
0 siblings, 0 replies; 2+ messages in thread
From: Ingo Molnar @ 2021-03-22 20:35 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Bill Metzenthen, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
x86, Arnd Bergmann, H. Peter Anvin, Gustavo A. R. Silva,
linux-kernel
* Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Building with 'make W=1', gcc points out that casting between
> incompatible function types can be dangerous:
>
> arch/x86/math-emu/fpu_trig.c:1638:60: error: cast between incompatible function types from ‘int (*)(FPU_REG *, u_char)’ {aka ‘int (*)(struct fpu__reg *, unsigned char)’} to ‘void (*)(FPU_REG *, u_char)’ {aka ‘void (*)(struct fpu__reg *, unsigned char)’} [-Werror=cast-function-type]
> 1638 | fprem, fyl2xp1, fsqrt_, fsincos, frndint_, fscale, (FUNC_ST0) fsin, fcos
> | ^
>
> This one seems harmless, but it is easy enough to work around it by
> adding an intermediate function that adjusts the return type.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> arch/x86/math-emu/fpu_trig.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/math-emu/fpu_trig.c b/arch/x86/math-emu/fpu_trig.c
> index 4a9887851ad8..aebfdb244cb4 100644
> --- a/arch/x86/math-emu/fpu_trig.c
> +++ b/arch/x86/math-emu/fpu_trig.c
> @@ -547,7 +547,7 @@ static void frndint_(FPU_REG *st0_ptr, u_char st0_tag)
> single_arg_error(st0_ptr, st0_tag);
> }
>
> -static int fsin(FPU_REG *st0_ptr, u_char tag)
> +static int do_fsin(FPU_REG *st0_ptr, u_char tag)
> {
> u_char arg_sign = getsign(st0_ptr);
>
> @@ -608,6 +608,11 @@ static int fsin(FPU_REG *st0_ptr, u_char tag)
> }
> }
>
> +static void fsin(FPU_REG *st0_ptr, u_char tag)
> +{
> + fsin(st0_ptr, tag);
> +}
> +
> static int f_cos(FPU_REG *st0_ptr, u_char tag)
> {
> u_char st0_sign;
The existing nomenclature in that code is:
static int f_cos(FPU_REG *st0_ptr, u_char tag)
static void fcos(FPU_REG *st0_ptr, u_char st0_tag)
So I'd suggest naming the variant with a return value f_sin().
Thanks,
Ingo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-22 20:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 17:06 [PATCH] x86: math-emu: Fix function cast warning Arnd Bergmann
2021-03-22 20:35 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).