linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/msm/dpu: avoid uninitialized variable use
@ 2025-08-07  7:19 Arnd Bergmann
  2025-08-07  8:09 ` Dmitry Baryshkov
  0 siblings, 1 reply; 6+ messages in thread
From: Arnd Bergmann @ 2025-08-07  7:19 UTC (permalink / raw)
  To: Rob Clark, Dmitry Baryshkov, David Airlie, Simona Vetter,
	Nathan Chancellor, Abhinav Kumar
  Cc: Arnd Bergmann, Abhinav Kumar, Jessica Zhang, Sean Paul,
	Marijn Suijten, Nick Desaulniers, Bill Wendling, Justin Stitt,
	Antonino Maniscalco, Konrad Dybcio, Jun Nie, linux-arm-msm,
	dri-devel, freedreno, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

clang-21 points out a variable that is conditionally initialized
but then dereferenced:

drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:6: error: variable 'crtc_state' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
 1138 |         if (plane_state->crtc)
      |             ^~~~~~~~~~~~~~~~~
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1142:58: note: uninitialized use occurs here
 1142 |         ret = dpu_plane_atomic_check_nosspp(plane, plane_state, crtc_state);
      |                                                                 ^~~~~~~~~~
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:2: note: remove the 'if' if its condition is always true
 1138 |         if (plane_state->crtc)
      |         ^~~~~~~~~~~~~~~~~~~~~~
 1139 |                 crtc_state = drm_atomic_get_new_crtc_state(state,
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1132:35: note: initialize the variable 'crtc_state' to silence this warning
 1132 |         struct drm_crtc_state *crtc_state;
      |                                          ^
      |                                           = NULL

The bug is real, but the suggestion from clang to set it to NULL is
unfortunately just as harmful as dereferencing a NULL pointer is little
better than uninitialized data.

Change the function to return an error in this case.

Fixes: 774bcfb73176 ("drm/msm/dpu: add support for virtual planes")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
index 01171c535a27..4987f2f2fee0 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
@@ -1135,10 +1135,10 @@ static int dpu_plane_virtual_atomic_check(struct drm_plane *plane,
 	if (IS_ERR(plane_state))
 		return PTR_ERR(plane_state);
 
-	if (plane_state->crtc)
-		crtc_state = drm_atomic_get_new_crtc_state(state,
-							   plane_state->crtc);
+	if (!plane_state->crtc)
+		return -ENXIO;
 
+	crtc_state = drm_atomic_get_new_crtc_state(state, plane_state->crtc);
 	ret = dpu_plane_atomic_check_nosspp(plane, plane_state, crtc_state);
 	if (ret)
 		return ret;
-- 
2.39.5


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

* Re: [PATCH] drm/msm/dpu: avoid uninitialized variable use
  2025-08-07  7:19 [PATCH] drm/msm/dpu: avoid uninitialized variable use Arnd Bergmann
@ 2025-08-07  8:09 ` Dmitry Baryshkov
  2025-08-07 14:34   ` Nathan Chancellor
  2025-08-07 15:08   ` Arnd Bergmann
  0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Baryshkov @ 2025-08-07  8:09 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Rob Clark, Dmitry Baryshkov, David Airlie, Simona Vetter,
	Nathan Chancellor, Abhinav Kumar, Arnd Bergmann, Abhinav Kumar,
	Jessica Zhang, Sean Paul, Marijn Suijten, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Antonino Maniscalco, Konrad Dybcio,
	Jun Nie, linux-arm-msm, dri-devel, freedreno, linux-kernel, llvm

On Thu, Aug 07, 2025 at 09:19:48AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang-21 points out a variable that is conditionally initialized
> but then dereferenced:
> 
> drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:6: error: variable 'crtc_state' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
>  1138 |         if (plane_state->crtc)
>       |             ^~~~~~~~~~~~~~~~~
> drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1142:58: note: uninitialized use occurs here
>  1142 |         ret = dpu_plane_atomic_check_nosspp(plane, plane_state, crtc_state);
>       |                                                                 ^~~~~~~~~~
> drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1138:2: note: remove the 'if' if its condition is always true
>  1138 |         if (plane_state->crtc)
>       |         ^~~~~~~~~~~~~~~~~~~~~~
>  1139 |                 crtc_state = drm_atomic_get_new_crtc_state(state,
> drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c:1132:35: note: initialize the variable 'crtc_state' to silence this warning
>  1132 |         struct drm_crtc_state *crtc_state;
>       |                                          ^
>       |                                           = NULL
> 
> The bug is real, but the suggestion from clang to set it to NULL is
> unfortunately just as harmful as dereferencing a NULL pointer is little
> better than uninitialized data.


Having no plane->crtc is a valid setting and it is handled inside
drm_atomic_helper_check_plane_state() by setting plane_state->visible =
false and returning early. Setting crtc_state to NULL is a correct fix.
Could you please send it?

> 
> Change the function to return an error in this case.
> 
> Fixes: 774bcfb73176 ("drm/msm/dpu: add support for virtual planes")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 

-- 
With best wishes
Dmitry

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

* Re: [PATCH] drm/msm/dpu: avoid uninitialized variable use
  2025-08-07  8:09 ` Dmitry Baryshkov
@ 2025-08-07 14:34   ` Nathan Chancellor
  2025-08-09  8:20     ` Dmitry Baryshkov
  2025-08-07 15:08   ` Arnd Bergmann
  1 sibling, 1 reply; 6+ messages in thread
From: Nathan Chancellor @ 2025-08-07 14:34 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Arnd Bergmann, Rob Clark, Dmitry Baryshkov, David Airlie,
	Simona Vetter, Abhinav Kumar, Arnd Bergmann, Abhinav Kumar,
	Jessica Zhang, Sean Paul, Marijn Suijten, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Antonino Maniscalco, Konrad Dybcio,
	Jun Nie, linux-arm-msm, dri-devel, freedreno, linux-kernel, llvm

On Thu, Aug 07, 2025 at 11:09:38AM +0300, Dmitry Baryshkov wrote:
> Having no plane->crtc is a valid setting and it is handled inside
> drm_atomic_helper_check_plane_state() by setting plane_state->visible =
> false and returning early. Setting crtc_state to NULL is a correct fix.
> Could you please send it?

I sent this fix three weeks ago, could this be applied?

https://lore.kernel.org/20250715-drm-msm-fix-const-uninit-warning-v1-1-d6a366fd9a32@kernel.org/

Cheers,
Nathan

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

* Re: [PATCH] drm/msm/dpu: avoid uninitialized variable use
  2025-08-07  8:09 ` Dmitry Baryshkov
  2025-08-07 14:34   ` Nathan Chancellor
@ 2025-08-07 15:08   ` Arnd Bergmann
  1 sibling, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2025-08-07 15:08 UTC (permalink / raw)
  To: Dmitry Baryshkov, Arnd Bergmann
  Cc: Rob Clark, Dmitry Baryshkov, Dave Airlie, Simona Vetter,
	Nathan Chancellor, Abhinav Kumar, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, Nick Desaulniers, Bill Wendling,
	Justin Stitt, Antonino Maniscalco, Konrad Dybcio, Jun Nie,
	linux-arm-msm, dri-devel, freedreno, linux-kernel, llvm

On Thu, Aug 7, 2025, at 10:09, Dmitry Baryshkov wrote:
> On Thu, Aug 07, 2025 at 09:19:48AM +0200, Arnd Bergmann wrote:
>>
>> The bug is real, but the suggestion from clang to set it to NULL is
>> unfortunately just as harmful as dereferencing a NULL pointer is little
>> better than uninitialized data.
>
>
> Having no plane->crtc is a valid setting and it is handled inside
> drm_atomic_helper_check_plane_state() by setting plane_state->visible =
> false and returning early. Setting crtc_state to NULL is a correct fix.
> Could you please send it?

Ah, I see. I saw the crtc_state dereference in

  WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc);

but that is indeed guarded by the plane_state->crtc check.

Nathan's patch is sufficient then.

    Arnd

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

* Re: [PATCH] drm/msm/dpu: avoid uninitialized variable use
  2025-08-07 14:34   ` Nathan Chancellor
@ 2025-08-09  8:20     ` Dmitry Baryshkov
  2025-08-10  0:20       ` Nathan Chancellor
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Baryshkov @ 2025-08-09  8:20 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Arnd Bergmann, Rob Clark, Dmitry Baryshkov, David Airlie,
	Simona Vetter, Abhinav Kumar, Arnd Bergmann, Abhinav Kumar,
	Jessica Zhang, Sean Paul, Marijn Suijten, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Antonino Maniscalco, Konrad Dybcio,
	Jun Nie, linux-arm-msm, dri-devel, freedreno, linux-kernel, llvm

On Thu, Aug 07, 2025 at 07:34:44AM -0700, Nathan Chancellor wrote:
> On Thu, Aug 07, 2025 at 11:09:38AM +0300, Dmitry Baryshkov wrote:
> > Having no plane->crtc is a valid setting and it is handled inside
> > drm_atomic_helper_check_plane_state() by setting plane_state->visible =
> > false and returning early. Setting crtc_state to NULL is a correct fix.
> > Could you please send it?
> 
> I sent this fix three weeks ago, could this be applied?

It will be picked up for -rc2 (hopefully)

> 
> https://lore.kernel.org/20250715-drm-msm-fix-const-uninit-warning-v1-1-d6a366fd9a32@kernel.org/
> 
> Cheers,
> Nathan

-- 
With best wishes
Dmitry

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

* Re: [PATCH] drm/msm/dpu: avoid uninitialized variable use
  2025-08-09  8:20     ` Dmitry Baryshkov
@ 2025-08-10  0:20       ` Nathan Chancellor
  0 siblings, 0 replies; 6+ messages in thread
From: Nathan Chancellor @ 2025-08-10  0:20 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Arnd Bergmann, Rob Clark, Dmitry Baryshkov, David Airlie,
	Simona Vetter, Abhinav Kumar, Arnd Bergmann, Abhinav Kumar,
	Jessica Zhang, Sean Paul, Marijn Suijten, Nick Desaulniers,
	Bill Wendling, Justin Stitt, Antonino Maniscalco, Konrad Dybcio,
	Jun Nie, linux-arm-msm, dri-devel, freedreno, linux-kernel, llvm

On Sat, Aug 09, 2025 at 11:20:34AM +0300, Dmitry Baryshkov wrote:
> On Thu, Aug 07, 2025 at 07:34:44AM -0700, Nathan Chancellor wrote:
> > On Thu, Aug 07, 2025 at 11:09:38AM +0300, Dmitry Baryshkov wrote:
> > > Having no plane->crtc is a valid setting and it is handled inside
> > > drm_atomic_helper_check_plane_state() by setting plane_state->visible =
> > > false and returning early. Setting crtc_state to NULL is a correct fix.
> > > Could you please send it?
> > 
> > I sent this fix three weeks ago, could this be applied?
> 
> It will be picked up for -rc2 (hopefully)

Great, thank you! Even if it slips to -rc3, no worries, as long it is in
the pipeline to get there.

Cheers,
Nathan

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

end of thread, other threads:[~2025-08-10  0:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07  7:19 [PATCH] drm/msm/dpu: avoid uninitialized variable use Arnd Bergmann
2025-08-07  8:09 ` Dmitry Baryshkov
2025-08-07 14:34   ` Nathan Chancellor
2025-08-09  8:20     ` Dmitry Baryshkov
2025-08-10  0:20       ` Nathan Chancellor
2025-08-07 15:08   ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).