ipmi: si: Cast to smaller integer type without warning
PATCH 1/1 ipmi: si: Cast to smaller integer type without warning
Debian clang version 19.1.7 is not happy when compiled with make W=1 (note, CONFIG_WERROR=y is the default):
ipmi_si_platform.c:268:15: error: cast to smaller integer type 'enum si_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
268 | io.si_type = (enum si_type)device_get_match_data(&pdev->dev);
Fix this by intermediate cast to the uintptr_t, that makes compiler happy.
--- drivers/char/ipmi/ipmi_si_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/ipmi/ipmi_si_platform.c +1 -1
@@ -265,7 +265,7 @@ static int of_ipmi_probe(struct platform_device *pdev) }memset (&io,0 ,sizeof (io)); - io.si_type = (enum si_type )device_get_match_data (&pdev->dev); + io.si_type = (enum si_type )(uintptr_t )device_get_match_data (&pdev->dev); io.addr_source =SI_DEVICETREE ; io.irq_setup = ipmi_std_irq_setup;
Signature · 1 line
2.47.2
Corey Minyard
maintainerQuoted 7 lines · Andy Shevchenko
Debian clang version 19.1.7 is not happy when compiled with
make W=1(note,CONFIG_WERROR=yis the default):ipmi_si_platform.c:268:15: error: cast to smaller integer type 'enum
si_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
268 | io.si_type = (enum si_type)device_get_match_data(&pdev->dev);Fix this by intermediate cast to the
uintptr_t, that makes compiler happy.
Unless things have changed recently, Linus prefers "unsigned long" per
https://patchwork.kernel.org/project/linux-hardening/patch/[email protected]/#24899749
And it would match what is in the match table.
Is that change ok?
-corey
Quoted 23 lines
Fixes 5be50eb5ae99 ("ipmi: si: Use device_get_match_data()")Signed-off-by Andy Shevchenko <[email protected]>--- drivers/char/ipmi/ipmi_si_platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/char/ipmi/ipmi_si_platform.c +1
-1@@ -265,7 +265,7 @@ static int of_ipmi_probe(struct platform_device *pdev) }memset (&io,0 ,sizeof (io)); - io.si_type = (enum si_type )device_get_match_data (&pdev->dev); + io.si_type = (enum si_type )(uintptr_t )device_get_match_data (&pdev->dev); io.addr_source =SI_DEVICETREE ; io.irq_setup = ipmi_std_irq_setup;Signature · 1 line
2.47.2
Quoted 11 lines · Corey Minyard
Quoted 7 lines · Andy Shevchenko
Debian clang version 19.1.7 is not happy when compiled with
make W=1(note,CONFIG_WERROR=yis the default):ipmi_si_platform.c:268:15: error: cast to smaller integer type 'enum
si_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
268 | io.si_type = (enum si_type)device_get_match_data(&pdev->dev);Fix this by intermediate cast to the
uintptr_t, that makes compiler happy.Unless things have changed recently, Linus prefers "unsigned long" per
https://patchwork.kernel.org/project/linux-hardening/patch/[email protected]/#24899749
I'm not sure I got your point. That discussion seems irrelevant to me. They are talking about pointer-as-an-integer cases. Here we already know that we are passing integer-as-a-pointer and this is the opposite conversion.
Quoted 1 line
And it would match what is in the match table.
Match tables are tend to move to pointers, enum is usually goes to int.
Quoted 1 line
Is that change ok?
If you don't like my change, please do yours and consider this as a bug report that needs to be addressed. I prefer more my solution as we do that in many places for the exact scenario.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 20 lines · Andy Shevchenko
Quoted 11 lines · Corey Minyard
Quoted 7 lines · Andy Shevchenko
Debian clang version 19.1.7 is not happy when compiled with
make W=1(note,CONFIG_WERROR=yis the default):ipmi_si_platform.c:268:15: error: cast to smaller integer type 'enum
si_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
268 | io.si_type = (enum si_type)device_get_match_data(&pdev->dev);Fix this by intermediate cast to the
uintptr_t, that makes compiler happy.Unless things have changed recently, Linus prefers "unsigned long" per
https://patchwork.kernel.org/project/linux-hardening/patch/[email protected]/#24899749I'm not sure I got your point. That discussion seems irrelevant to me. They are talking about pointer-as-an-integer cases. Here we already know that we are passing integer-as-a-pointer and this is the opposite conversion.
Quoted 1 line
And it would match what is in the match table.
Quoted 7 lines
Match tables are tend to move to pointers, enum is usually goes to int.
Quoted 1 line
Is that change ok?
If you don't like my change, please do yours and consider this as a bug report that needs to be addressed. I prefer more my solution as we do that in many places for the exact scenario.
Note, the proper solution to the cases like this is to move to info-like structure and actually operate with the pointers instead of enums, longs, etc.
That's what's slowly moving on in IIO subsystem, for instance.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Corey Minyard
maintainerQuoted 25 lines · Andy Shevchenko
Quoted 24 lines · Andy Shevchenko
Quoted 11 lines · Corey Minyard
Quoted 7 lines · Andy Shevchenko
Debian clang version 19.1.7 is not happy when compiled with
make W=1(note,CONFIG_WERROR=yis the default):ipmi_si_platform.c:268:15: error: cast to smaller integer type 'enum
si_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
268 | io.si_type = (enum si_type)device_get_match_data(&pdev->dev);Fix this by intermediate cast to the
uintptr_t, that makes compiler happy.Unless things have changed recently, Linus prefers "unsigned long" per
https://patchwork.kernel.org/project/linux-hardening/patch/[email protected]/#24899749I'm not sure I got your point. That discussion seems irrelevant to me. They are talking about pointer-as-an-integer cases. Here we already know that we are passing integer-as-a-pointer and this is the opposite conversion.
Quoted 1 line
And it would match what is in the match table.
Match tables are tend to move to pointers, enum is usually goes to int.
Quoted 1 line
Is that change ok?
Quoted 8 lines
Quoted 3 lines
If you don't like my change, please do yours and consider this as a bug report that needs to be addressed. I prefer more my solution as we do that in many places for the exact scenario.
Note, the proper solution to the cases like this is to move to info-like structure and actually operate with the pointers instead of enums, longs, etc.
That's what's slowly moving on in IIO subsystem, for instance.
Yes, you are right, I'll probably make that change. I'm not sure about the uintptr thing, but I think the right change is to do an info structure. I never liked that code as it was, anyway.
Thanks,
-corey
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
Quoted 30 lines · Corey Minyard
Quoted 29 lines · Andy Shevchenko
Quoted 27 lines · Andy Shevchenko
Quoted 11 lines · Corey Minyard
Quoted 7 lines · Andy Shevchenko
Debian clang version 19.1.7 is not happy when compiled with
make W=1(note,CONFIG_WERROR=yis the default):ipmi_si_platform.c:268:15: error: cast to smaller integer type 'enum
si_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
268 | io.si_type = (enum si_type)device_get_match_data(&pdev->dev);Fix this by intermediate cast to the
uintptr_t, that makes compiler happy.Unless things have changed recently, Linus prefers "unsigned long" per
https://patchwork.kernel.org/project/linux-hardening/patch/[email protected]/#24899749I'm not sure I got your point. That discussion seems irrelevant to me. They are talking about pointer-as-an-integer cases. Here we already know that we are passing integer-as-a-pointer and this is the opposite conversion.
Quoted 1 line
And it would match what is in the match table.
Match tables are tend to move to pointers, enum is usually goes to int.
Quoted 1 line
Is that change ok?
If you don't like my change, please do yours and consider this as a bug report that needs to be addressed. I prefer more my solution as we do that in many places for the exact scenario.
Quoted 8 lines
Quoted 4 lines
Note, the proper solution to the cases like this is to move to info-like structure and actually operate with the pointers instead of enums, longs, etc.
That's what's slowly moving on in IIO subsystem, for instance.
Yes, you are right, I'll probably make that change. I'm not sure about the uintptr thing, but I think the right change is to do an info structure. I never liked that code as it was, anyway.
Please do, I will happily test anything you provide as currently this code breaks make W=1 builds.
Signature · 2 lines
With Best Regards, Andy Shevchenko