mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/repaper: fix -Wvoid-pointer-to-enum-cast warning
@ 2023-08-16 19:55 Justin Stitt
  2023-08-25 11:20 ` Noralf Trønnes
  0 siblings, 1 reply; 2+ messages in thread
From: Justin Stitt @ 2023-08-16 19:55 UTC (permalink / raw)
  To: Noralf Trønnes, David Airlie, Daniel Vetter,
	Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: dri-devel, linux-kernel, llvm, Justin Stitt

When building with clang 18 I see the following warning:
|       drivers/gpu/drm/tiny/repaper.c:952:11: warning: cast to smaller integer
|       type 'enum repaper_model' from 'const void *' [-Wvoid-pointer-to-enum-cast]
|         952 |                 model = (enum repaper_model)match;
|

This is due to the fact that `match` is a void* while `enum repaper_model`
has the size of an int.

Add uintptr_t cast to silence clang warning while also keeping enum cast
for readability and consistency with other `model` assignment just a
few lines below:
|       model = (enum repaper_model)spi_id->driver_data;

Link: https://github.com/ClangBuiltLinux/linux/issues/1910
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
 drivers/gpu/drm/tiny/repaper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c
index c2677d081a7b..165f2099e7d8 100644
--- a/drivers/gpu/drm/tiny/repaper.c
+++ b/drivers/gpu/drm/tiny/repaper.c
@@ -949,7 +949,7 @@ static int repaper_probe(struct spi_device *spi)
 
 	match = device_get_match_data(dev);
 	if (match) {
-		model = (enum repaper_model)match;
+		model = (enum repaper_model)(uintptr_t)match;
 	} else {
 		spi_id = spi_get_device_id(spi);
 		model = (enum repaper_model)spi_id->driver_data;

---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230816-void-drivers-gpu-drm-tiny-repaper-a08321cd99d7

Best regards,
--
Justin Stitt <justinstitt@google.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/repaper: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-16 19:55 [PATCH] drm/repaper: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-25 11:20 ` Noralf Trønnes
  0 siblings, 0 replies; 2+ messages in thread
From: Noralf Trønnes @ 2023-08-25 11:20 UTC (permalink / raw)
  To: Justin Stitt, David Airlie, Daniel Vetter, Nathan Chancellor,
	Nick Desaulniers, Tom Rix, noralf
  Cc: dri-devel, linux-kernel, llvm



On 8/16/23 21:55, Justin Stitt wrote:
> When building with clang 18 I see the following warning:
> |       drivers/gpu/drm/tiny/repaper.c:952:11: warning: cast to smaller integer
> |       type 'enum repaper_model' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> |         952 |                 model = (enum repaper_model)match;
> |
> 
> This is due to the fact that `match` is a void* while `enum repaper_model`
> has the size of an int.
> 
> Add uintptr_t cast to silence clang warning while also keeping enum cast
> for readability and consistency with other `model` assignment just a
> few lines below:
> |       model = (enum repaper_model)spi_id->driver_data;
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---

Thanks, applied to drm-misc-next.

Noralf.

>  drivers/gpu/drm/tiny/repaper.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c
> index c2677d081a7b..165f2099e7d8 100644
> --- a/drivers/gpu/drm/tiny/repaper.c
> +++ b/drivers/gpu/drm/tiny/repaper.c
> @@ -949,7 +949,7 @@ static int repaper_probe(struct spi_device *spi)
>  
>  	match = device_get_match_data(dev);
>  	if (match) {
> -		model = (enum repaper_model)match;
> +		model = (enum repaper_model)(uintptr_t)match;
>  	} else {
>  		spi_id = spi_get_device_id(spi);
>  		model = (enum repaper_model)spi_id->driver_data;
> 
> ---
> base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
> change-id: 20230816-void-drivers-gpu-drm-tiny-repaper-a08321cd99d7
> 
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-25 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-16 19:55 [PATCH] drm/repaper: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-25 11:20 ` Noralf Trønnes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®