Skip to contentSkip to conversation

drm/stm: Avoid using val uninitialized in ltdc_set_ycbcr_config()

PATCH Superseded Nathan Chancellor 5 participants 6 messages Feb 7, 2022 – Feb 22, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/stm: Avoid using val uninitialized in ltdc_set_ycbcr_config()

Clang warns:

drivers/gpu/drm/stm/ltdc.c:625:2: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

          default:
          ^~~~~~~
  drivers/gpu/drm/stm/ltdc.c:635:2: note: uninitialized use occurs here
          val |= LxPCR_YCEN;
          ^~~
  drivers/gpu/drm/stm/ltdc.c:600:9: note: initialize the variable 'val' to silence this warning
          u32 val;
                 ^
                  = 0

1 warning generated.

Use a return instead of break in the default case to fix the warning. Add an error message so that this return is not silent, which could hide issues in the future.

Fixes 484e72d3146b ("drm/stm: ltdc: add support of ycbcr pixel formats")
---
 drivers/gpu/drm/stm/ltdc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/stm/ltdc.c +2 -1
index 5eeb32c9c9ce..447ddde1786c 100644
@@ -624,7 +624,8 @@ static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm
 		break;
 	default:
 		/* RGB or not a YCbCr supported format */
-		break;
+		drm_err(plane->dev, "Unsupported pixel format: %u\n", drm_pix_fmt);
+		return;
 	}
 
 	/* Enable limited range */

base-commit: 542898c5aa5c6a3179dffb1d1606884a63f75fed

Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Nathan Chancellor

Clang warns:

drivers/gpu/drm/stm/ltdc.c:625:2: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

          default:
          ^~~~~~~
  drivers/gpu/drm/stm/ltdc.c:635:2: note: uninitialized use occurs here
          val |= LxPCR_YCEN;
          ^~~
  drivers/gpu/drm/stm/ltdc.c:600:9: note: initialize the variable 'val' to silence this warning
          u32 val;
                 ^
                  = 0

1 warning generated.

Use a return instead of break in the default case to fix the warning. Add an error message so that this return is not silent, which could hide issues in the future.

Fixes 484e72d3146b ("drm/stm: ltdc: add support of ycbcr pixel formats")
---
 drivers/gpu/drm/stm/ltdc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/stm/ltdc.c +0 -0
index 5eeb32c9c9ce..447ddde1786c 100644

drivers/gpu/drm/stm/ltdc.c static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm · line 627

Quoted 5 lines
drivers/gpu/drm/stm/ltdc.c +1 -1
@@ -624,7 +624,8 @@ static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm
                break;
        default:
                /* RGB or not a YCbCr supported format */
-               break;
+               drm_err(plane->dev, "Unsupported pixel format: %u\n", drm_pix_fmt);

This is fine, but in the future you should add an explicit #include <drm/drm_print.h>
to avoid implicit header dependencies (like the ones that Mingo is trying to detangle) for the declaration of drm_err. drm_vprintf needs it, too.

Quoted 9 lines
drivers/gpu/drm/stm/ltdc.c +1 -0
+               return;
        }
 
        /* Enable limited range */

base-commit: 542898c5aa5c6a3179dffb1d1606884a63f75fed --
2.35.1

Signature · 2 lines
Thanks,
~Nick Desaulniers
maintainer
#2 lore raw
Quoted 44 lines · Nick Desaulniers
Quoted 31 lines · Nathan Chancellor

Clang warns:

   drivers/gpu/drm/stm/ltdc.c:625:2: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
           default:
           ^~~~~~~
   drivers/gpu/drm/stm/ltdc.c:635:2: note: uninitialized use occurs here
           val |= LxPCR_YCEN;
           ^~~
   drivers/gpu/drm/stm/ltdc.c:600:9: note: initialize the variable 'val' to silence this warning
           u32 val;
                  ^
                   = 0
   1 warning generated.

Use a return instead of break in the default case to fix the warning. Add an error message so that this return is not silent, which could hide issues in the future.

Fixes 484e72d3146b ("drm/stm: ltdc: add support of ycbcr pixel formats")
---
  drivers/gpu/drm/stm/ltdc.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/stm/ltdc.c +0 -0
index 5eeb32c9c9ce..447ddde1786c 100644

drivers/gpu/drm/stm/ltdc.c static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm · line 627

Quoted 5 lines
drivers/gpu/drm/stm/ltdc.c +1 -1
@@ -624,7 +624,8 @@ static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm
                 break;
         default:
                 /* RGB or not a YCbCr supported format */
-               break;
+               drm_err(plane->dev, "Unsupported pixel format: %u\n", drm_pix_fmt);

This is fine, but in the future you should add an explicit #include <drm/drm_print.h>
to avoid implicit header dependencies (like the ones that Mingo is trying to detangle) for the declaration of drm_err. drm_vprintf needs it, too.

Quoted 2 lines

Hi Nick,
and thank you for having pointing this.

Hi Nathan,
May I ask you please to update your patch changing drm_err(plane->dev, ) with DRM_ERROR().

Big thank you,

Philippe :-)

Quoted 11 lines
Quoted 9 lines
drivers/gpu/drm/stm/ltdc.c +1 -0
+               return;
         }
 
         /* Enable limited range */

base-commit: 542898c5aa5c6a3179dffb1d1606884a63f75fed --
2.35.1

#3 lore raw
Quoted 50 lines · Philippe CORNU
Quoted 44 lines · Nick Desaulniers
Quoted 31 lines · Nathan Chancellor

Clang warns:

   drivers/gpu/drm/stm/ltdc.c:625:2: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
           default:
           ^~~~~~~
   drivers/gpu/drm/stm/ltdc.c:635:2: note: uninitialized use occurs here
           val |= LxPCR_YCEN;
           ^~~
   drivers/gpu/drm/stm/ltdc.c:600:9: note: initialize the variable 'val' to silence this warning
           u32 val;
                  ^
                   = 0
   1 warning generated.

Use a return instead of break in the default case to fix the warning. Add an error message so that this return is not silent, which could hide issues in the future.

Fixes 484e72d3146b ("drm/stm: ltdc: add support of ycbcr pixel formats")
---
  drivers/gpu/drm/stm/ltdc.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/stm/ltdc.c +0 -0
index 5eeb32c9c9ce..447ddde1786c 100644

drivers/gpu/drm/stm/ltdc.c static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm · line 627

Quoted 5 lines
drivers/gpu/drm/stm/ltdc.c +1 -1
@@ -624,7 +624,8 @@ static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm
                 break;
         default:
                 /* RGB or not a YCbCr supported format */
-               break;
+               drm_err(plane->dev, "Unsupported pixel format: %u\n", drm_pix_fmt);

This is fine, but in the future you should add an explicit #include <drm/drm_print.h>
to avoid implicit header dependencies (like the ones that Mingo is trying to detangle) for the declaration of drm_err. drm_vprintf needs it, too.

Quoted 2 lines
Quoted 6 lines

Hi Nick,
and thank you for having pointing this.

Hi Nathan,
May I ask you please to update your patch changing drm_err(plane->dev, ) with DRM_ERROR().

Sure thing, v2 has been sent:

https://lore.kernel.org/r/[email protected]/

I used drm_err() as I saw DRM_ERROR() was deprecated but I get internal driver consistency is important.

Cheers,
Nathan

Quoted 17 lines

Big thank you,

Philippe :-)

Quoted 11 lines
Quoted 9 lines
drivers/gpu/drm/stm/ltdc.c +1 -0
+               return;
         }
 
         /* Enable limited range */

base-commit: 542898c5aa5c6a3179dffb1d1606884a63f75fed --
2.35.1

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Nathan Chancellor

Hello Nathan,

Quoted 18 lines · Nathan Chancellor

Clang warns:

drivers/gpu/drm/stm/ltdc.c:625:2: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]

          default:
          ^~~~~~~
  drivers/gpu/drm/stm/ltdc.c:635:2: note: uninitialized use occurs here
          val |= LxPCR_YCEN;
          ^~~
  drivers/gpu/drm/stm/ltdc.c:600:9: note: initialize the variable 'val' to silence this warning
          u32 val;
                 ^
                  = 0

1 warning generated.

Use a return instead of break in the default case to fix the warning. Add an error message so that this return is not silent, which could hide issues in the future.

Quoted 6 lines
Fixes 484e72d3146b ("drm/stm: ltdc: add support of ycbcr pixel formats")
---
 drivers/gpu/drm/stm/ltdc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Thanks,

Raphaël

maintainer Acked-by on v1 1/1
#5 lore raw
In reply to Nathan Chancellor

Hi Nathan,
Thenks for the patch.

Best regards

Quoted 41 lines · Nathan Chancellor

Clang warns:

   drivers/gpu/drm/stm/ltdc.c:625:2: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
           default:
           ^~~~~~~
   drivers/gpu/drm/stm/ltdc.c:635:2: note: uninitialized use occurs here
           val |= LxPCR_YCEN;
           ^~~
   drivers/gpu/drm/stm/ltdc.c:600:9: note: initialize the variable 'val' to silence this warning
           u32 val;
                  ^
                   = 0
   1 warning generated.

Use a return instead of break in the default case to fix the warning. Add an error message so that this return is not silent, which could hide issues in the future.

Fixes 484e72d3146b ("drm/stm: ltdc: add support of ycbcr pixel formats")
---
  drivers/gpu/drm/stm/ltdc.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/stm/ltdc.c +2 -1
index 5eeb32c9c9ce..447ddde1786c 100644
@@ -624,7 +624,8 @@ static inline void ltdc_set_ycbcr_config(struct drm_plane *plane, u32 drm_pix_fm
  		break;
  	default:
  		/* RGB or not a YCbCr supported format */
-		break;
+		drm_err(plane->dev, "Unsupported pixel format: %u\n", drm_pix_fmt);
+		return;
  	}
 
  	/* Enable limited range */

base-commit: 542898c5aa5c6a3179dffb1d1606884a63f75fed