diff mbox series

[2/2] drm/i915: move uapi.event outside spinlock in intel_crtc_vblank_work

Message ID 20240528112901.476068-3-luciano.coelho@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: prevent some static analyzer warnings | expand

Commit Message

Luca Coelho May 28, 2024, 11:29 a.m. UTC
In intel_crtc_vblank_work(), we access uapi.event before grabbing the
event_lock spinlock, but modify it inside the spinlock block.  This
causes some static analyzers to get confused and issue a warning.

The uapi.event value is not protected by the event_lock, so we can
safely move it out of the protected block to prevent false positives.

Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
 drivers/gpu/drm/i915/display/intel_crtc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Rodrigo Vivi May 28, 2024, 4:58 p.m. UTC | #1
On Tue, May 28, 2024 at 02:29:01PM +0300, Luca Coelho wrote:
> In intel_crtc_vblank_work(), we access uapi.event before grabbing the
> event_lock spinlock, but modify it inside the spinlock block.  This
> causes some static analyzers to get confused and issue a warning.
> 
> The uapi.event value is not protected by the event_lock, so we can
> safely move it out of the protected block to prevent false positives.


My first reaction was to think about moving the lock before the if,
but then I went down to see the event_lock definition and usage in drm
and see some other precedences on this and agree this is safe and
better.

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> 
> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_crtc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_crtc.c b/drivers/gpu/drm/i915/display/intel_crtc.c
> index ca6dc1dc56c8..bf6e74e99f5c 100644
> --- a/drivers/gpu/drm/i915/display/intel_crtc.c
> +++ b/drivers/gpu/drm/i915/display/intel_crtc.c
> @@ -411,8 +411,8 @@ static void intel_crtc_vblank_work(struct kthread_work *base)
>  	if (crtc_state->uapi.event) {
>  		spin_lock_irq(&crtc->base.dev->event_lock);
>  		drm_crtc_send_vblank_event(&crtc->base, crtc_state->uapi.event);
> -		crtc_state->uapi.event = NULL;
>  		spin_unlock_irq(&crtc->base.dev->event_lock);
> +		crtc_state->uapi.event = NULL;
>  	}
>  
>  	trace_intel_crtc_vblank_work_end(crtc);
> -- 
> 2.39.2
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_crtc.c b/drivers/gpu/drm/i915/display/intel_crtc.c
index ca6dc1dc56c8..bf6e74e99f5c 100644
--- a/drivers/gpu/drm/i915/display/intel_crtc.c
+++ b/drivers/gpu/drm/i915/display/intel_crtc.c
@@ -411,8 +411,8 @@  static void intel_crtc_vblank_work(struct kthread_work *base)
 	if (crtc_state->uapi.event) {
 		spin_lock_irq(&crtc->base.dev->event_lock);
 		drm_crtc_send_vblank_event(&crtc->base, crtc_state->uapi.event);
-		crtc_state->uapi.event = NULL;
 		spin_unlock_irq(&crtc->base.dev->event_lock);
+		crtc_state->uapi.event = NULL;
 	}
 
 	trace_intel_crtc_vblank_work_end(crtc);