2023-08-10 11:17:01

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 01/15] hwmon: (adt7475) fix Wvoid-pointer-to-enum-cast warning

'chip' is an enum, thus cast of pointer on 64-bit compile test with W=1
causes:

adt7475.c:1655:10: error: cast to smaller integer type 'enum chips' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/hwmon/adt7475.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 5363254644da..03acadc3a6cb 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -1652,7 +1652,7 @@ static int adt7475_probe(struct i2c_client *client)
i2c_set_clientdata(client, data);

if (client->dev.of_node)
- chip = (enum chips)of_device_get_match_data(&client->dev);
+ chip = (uintptr_t)of_device_get_match_data(&client->dev);
else
chip = id->driver_data;

--
2.34.1



2023-08-10 11:23:30

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 04/15] hwmon: (ina2xx) fix Wvoid-pointer-to-enum-cast warning

'chip' is an enum, thus cast of pointer on 64-bit compile test with W=1
causes:

ina2xx.c:627:10: error: cast to smaller integer type 'enum ina2xx_ids' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/hwmon/ina2xx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index a47973e2d606..d8415d1f21fc 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -624,7 +624,7 @@ static int ina2xx_probe(struct i2c_client *client)
enum ina2xx_ids chip;

if (client->dev.of_node)
- chip = (enum ina2xx_ids)of_device_get_match_data(&client->dev);
+ chip = (uintptr_t)of_device_get_match_data(&client->dev);
else
chip = i2c_match_id(ina2xx_id, client)->driver_data;

--
2.34.1


2023-08-10 12:17:11

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [PATCH 11/15] hwmon: (tmp513) fix Wvoid-pointer-to-enum-cast warning

'id' is an enum, thus cast of pointer on 64-bit compile test with W=1
causes:

tmp513.c:724:14: error: cast to smaller integer type 'enum tmp51x_ids' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/hwmon/tmp513.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/tmp513.c b/drivers/hwmon/tmp513.c
index bff10f4b56e1..7db5d0fc24a4 100644
--- a/drivers/hwmon/tmp513.c
+++ b/drivers/hwmon/tmp513.c
@@ -721,7 +721,7 @@ static int tmp51x_probe(struct i2c_client *client)
return -ENOMEM;

if (client->dev.of_node)
- data->id = (enum tmp51x_ids)device_get_match_data(&client->dev);
+ data->id = (uintptr_t)device_get_match_data(&client->dev);
else
data->id = i2c_match_id(tmp51x_id, client)->driver_data;

--
2.34.1


2023-08-10 17:33:46

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH 01/15] hwmon: (adt7475) fix Wvoid-pointer-to-enum-cast warning

On Thu, Aug 10, 2023 at 11:31:43AM +0200, Krzysztof Kozlowski wrote:
> 'chip' is an enum, thus cast of pointer on 64-bit compile test with W=1
> causes:
>
> adt7475.c:1655:10: error: cast to smaller integer type 'enum chips' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>

Series applied.

Thanks,
Guenter

2023-08-14 08:53:00

by David Laight

[permalink] [raw]
Subject: RE: [PATCH 04/15] hwmon: (ina2xx) fix Wvoid-pointer-to-enum-cast warning

From: Krzysztof Kozlowski
> Sent: 10 August 2023 10:32
>
> 'chip' is an enum, thus cast of pointer on 64-bit compile test with W=1
> causes:
>
> ina2xx.c:627:10: error: cast to smaller integer type 'enum ina2xx_ids' from 'const void *' [-
> Werror,-Wvoid-pointer-to-enum-cast]
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---
> drivers/hwmon/ina2xx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
> index a47973e2d606..d8415d1f21fc 100644
> --- a/drivers/hwmon/ina2xx.c
> +++ b/drivers/hwmon/ina2xx.c
> @@ -624,7 +624,7 @@ static int ina2xx_probe(struct i2c_client *client)
> enum ina2xx_ids chip;
>
> if (client->dev.of_node)
> -chip = (enum ina2xx_ids)of_device_get_match_data(&client->dev);
> +chip = (uintptr_t)of_device_get_match_data(&client->dev);

The kernel type would be 'long' not uintptr_t.
But this all looks like something horrid is being done.

(And you've clearly lost all the tabs)

David

> else
> chip = i2c_match_id(ina2xx_id, client)->driver_data;
>
> --
> 2.34.1
>

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


2023-08-14 10:24:20

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 04/15] hwmon: (ina2xx) fix Wvoid-pointer-to-enum-cast warning

On 14/08/2023 10:33, David Laight wrote:
> From: Krzysztof Kozlowski
>> Sent: 10 August 2023 10:32
>>
>> 'chip' is an enum, thus cast of pointer on 64-bit compile test with W=1
>> causes:
>>
>> ina2xx.c:627:10: error: cast to smaller integer type 'enum ina2xx_ids' from 'const void *' [-
>> Werror,-Wvoid-pointer-to-enum-cast]
>>
>> Signed-off-by: Krzysztof Kozlowski <[email protected]>
>> ---
>> drivers/hwmon/ina2xx.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
>> index a47973e2d606..d8415d1f21fc 100644
>> --- a/drivers/hwmon/ina2xx.c
>> +++ b/drivers/hwmon/ina2xx.c
>> @@ -624,7 +624,7 @@ static int ina2xx_probe(struct i2c_client *client)
>> enum ina2xx_ids chip;
>>
>> if (client->dev.of_node)
>> -chip = (enum ina2xx_ids)of_device_get_match_data(&client->dev);
>> +chip = (uintptr_t)of_device_get_match_data(&client->dev);
>
> The kernel type would be 'long' not uintptr_t.

Yeah, Greg also pointed out. It was applied, so no sure if it is worth
to change to kernel_ulong_t.

> But this all looks like something horrid is being done.

Why exactly? This is pretty often pattern, code is correct and easy to
understand.

>
> (And you've clearly lost all the tabs)

It's your email client who lost them:
https://lore.kernel.org/all/[email protected]/

Best regards,
Krzysztof