diff mbox

thermal/drivers/hisi: Remove bogus const from function return type

Message ID 1511089467-20525-1-git-send-email-geert@linux-m68k.org (mailing list archive)
State Accepted
Delegated to: Eduardo Valentin
Headers show

Commit Message

Geert Uytterhoeven Nov. 19, 2017, 11:04 a.m. UTC
With gcc-4.1.2:

    drivers/thermal/hisi_thermal.c: In function ‘hisi_thermal_probe’:
    drivers/thermal/hisi_thermal.c:530: warning: type qualifiers ignored on function return type

Remove the "const" keyword to fix this.

Fixes: a160a465297362c5 ("thermal/drivers/hisi: Prepare to add support for other hisi platforms")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/thermal/hisi_thermal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eduardo Valentin Jan. 1, 2018, 6:21 p.m. UTC | #1
Hello Geert,

On Sun, Nov 19, 2017 at 12:04:27PM +0100, Geert Uytterhoeven wrote:
> With gcc-4.1.2:
> 
>     drivers/thermal/hisi_thermal.c: In function ‘hisi_thermal_probe’:
>     drivers/thermal/hisi_thermal.c:530: warning: type qualifiers ignored on function return type
> 
> Remove the "const" keyword to fix this.

Interesting.

I intentionally asked Daniel to include the modifier because sparse
pointed this to me:

This patch adds this issue to hisi driver (sparse)

drivers/thermal/hisi_thermal.c:398:24: warning: incorrect type in assignment (different modifiers)
drivers/thermal/hisi_thermal.c:398:24:    expected int ( *platform_probe )( ... )
drivers/thermal/hisi_thermal.c:398:24:    got void const *

which makes sense to me to be const, given that it is receiving the return 
of a function which returns a const void *. 
nclude/linux/of_device.h:extern const void *of_device_get_match_data(const struct device *dev);

Cheers,
Geert Uytterhoeven Jan. 2, 2018, 7:36 a.m. UTC | #2
Hi Eduardo,

On Mon, Jan 1, 2018 at 7:21 PM, Eduardo Valentin <edubezval@gmail.com> wrote:
> On Sun, Nov 19, 2017 at 12:04:27PM +0100, Geert Uytterhoeven wrote:
>> With gcc-4.1.2:
>>
>>     drivers/thermal/hisi_thermal.c: In function ‘hisi_thermal_probe’:
>>     drivers/thermal/hisi_thermal.c:530: warning: type qualifiers ignored on function return type
>>
>> Remove the "const" keyword to fix this.
>
> Interesting.
>
> I intentionally asked Daniel to include the modifier because sparse
> pointed this to me:
>
> This patch adds this issue to hisi driver (sparse)
>
> drivers/thermal/hisi_thermal.c:398:24: warning: incorrect type in assignment (different modifiers)
> drivers/thermal/hisi_thermal.c:398:24:    expected int ( *platform_probe )( ... )
> drivers/thermal/hisi_thermal.c:398:24:    got void const *

Sparse doesn't like assigning void pointers to function pointers without a cast.

> which makes sense to me to be const, given that it is receiving the return
> of a function which returns a const void *.
> nclude/linux/of_device.h:extern const void *of_device_get_match_data(const struct device *dev);

That const applies to what is returned by of_device_get_match_data() (a const
void *), not to what is returned by the returned function (an int).

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Arnd Bergmann Jan. 2, 2018, 11:44 a.m. UTC | #3
On Sun, Nov 19, 2017 at 12:04 PM, Geert Uytterhoeven
<geert@linux-m68k.org> wrote:
> With gcc-4.1.2:
>
>     drivers/thermal/hisi_thermal.c: In function ‘hisi_thermal_probe’:
>     drivers/thermal/hisi_thermal.c:530: warning: type qualifiers ignored on function return type
>
> Remove the "const" keyword to fix this.
>
> Fixes: a160a465297362c5 ("thermal/drivers/hisi: Prepare to add support for other hisi platforms")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

For future reference, this kind of warning shows up with gcc-4.2 as
well, but not with
gcc-4.3 or higher. I think in this case, both gcc and sparse fail to
provide helpful
feedback, but the code is probably better done using either a typedef
for the function
type, or with a structure containing the function pointer.

         Arnd
Eduardo Valentin Jan. 2, 2018, 5:50 p.m. UTC | #4
On Tue, Jan 02, 2018 at 12:44:29PM +0100, Arnd Bergmann wrote:
> On Sun, Nov 19, 2017 at 12:04 PM, Geert Uytterhoeven
> <geert@linux-m68k.org> wrote:
> > With gcc-4.1.2:
> >
> >     drivers/thermal/hisi_thermal.c: In function ‘hisi_thermal_probe’:
> >     drivers/thermal/hisi_thermal.c:530: warning: type qualifiers ignored on function return type
> >
> > Remove the "const" keyword to fix this.
> >
> > Fixes: a160a465297362c5 ("thermal/drivers/hisi: Prepare to add support for other hisi platforms")
> > Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> 
> For future reference, this kind of warning shows up with gcc-4.2 as
> well, but not with
> gcc-4.3 or higher. I think in this case, both gcc and sparse fail to

Yeah, this is correct. I do not see the same warn while using gcc-4.8.

> provide helpful
> feedback, but the code is probably better done using either a typedef
> for the function
> type, or with a structure containing the function pointer.

I agree.

> 
>          Arnd
diff mbox

Patch

diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 2d855a96cdd9886c..761d0559c268b606 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -527,7 +527,7 @@  static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor,
 static int hisi_thermal_probe(struct platform_device *pdev)
 {
 	struct hisi_thermal_data *data;
-	int const (*platform_probe)(struct hisi_thermal_data *);
+	int (*platform_probe)(struct hisi_thermal_data *);
 	struct device *dev = &pdev->dev;
 	int ret;