Re: [PATCH] serial: mxs-uart: fix Wvoid-pointer-to-enum-cast warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/08/2023 17:44, Greg Kroah-Hartman wrote:
> On Thu, Aug 10, 2023 at 10:50:42AM +0200, Krzysztof Kozlowski wrote:
>> `devtype` is enum, thus cast of pointer on 64-bit compile test with W=1
>> causes:
>>
>>   mxs-auart.c:1598:15: error: cast to smaller integer type 'enum mxs_auart_type' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast]
>>
>> Cc: Andi Shyti <andi.shyti@xxxxxxxxxx>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxx>
>> ---
>>  drivers/tty/serial/mxs-auart.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
>> index 8eeecf8ad359..a9b32722b049 100644
>> --- a/drivers/tty/serial/mxs-auart.c
>> +++ b/drivers/tty/serial/mxs-auart.c
>> @@ -1595,7 +1595,7 @@ static int mxs_auart_probe(struct platform_device *pdev)
>>  		return -EINVAL;
>>  	}
>>  
>> -	s->devtype = (enum mxs_auart_type)of_device_get_match_data(&pdev->dev);
>> +	s->devtype = (uintptr_t)of_device_get_match_data(&pdev->dev);
> 
> This feels like a compiler issue as devtype is a enum mxs_auart_type
> variable, so the cast shoudl be correct.

While the cast is obviously safe here, the warning in general is
reasonable - people were make too many mistakes by assuming pointers are
integers...

Just for the record (not saying that others doing is proof of correctness):

https://lore.kernel.org/lkml/20230809-cbl-1903-v1-1-df9d66a3ba3e@xxxxxxxxxx/T/

But maybe Nathan can share his thoughts whether we should just disable
this warning for kernel?

> 
> And if not, unitptr_t isn't a valid kernel type, so that's not a good

It is in include/linux/types.h, so do you mean that it is not
recommended for in-kernel usage? I can go with kernel_ulong_t - which is
a kernel type - if the cast is agreed.

> solution either.  Worst case, it's how big a pointer is, which is not
> going to be what an enum is if you have a sane compiler :(


Best regards,
Krzysztof




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux