Skip to contentSkip to conversation

drm/i915: Avoid drm_atomic_state_put(NULL) on error paths

PATCH In review Ander Conselvan de Oliveira 3 participants 7 messages Jan 18, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: Avoid drm_atomic_state_put(NULL) on error paths

The error paths in hsw_trans_edp_pipe_A_crc_wa() and intel_prepare_reset() would potentially call drm_atomic_state_put with a NULL state, which would lead to a NULL pointer dereference.

Found by coverity.

Fixes 0853695c3ba4 ("drm: Add reference counting to drm_atomic_state")
Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc <[email protected]> # v4.10-rc1+
---
 drivers/gpu/drm/i915/intel_display.c  | 3 ++-
 drivers/gpu/drm/i915/intel_pipe_crc.c | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +2 -1
index caa2e02..b5a09bd 100644
@@ -3577,7 +3577,8 @@ void intel_prepare_reset(struct drm_i915_private *dev_priv)
 	return;
 
 err:
-	drm_atomic_state_put(state);
+	if (state)
+		drm_atomic_state_put(state);
 }
 
 void intel_finish_reset(struct drm_i915_private *dev_priv)
drivers/gpu/drm/i915/intel_pipe_crc.c +3 -1
index 0f1da81..f1bbf49 100644
@@ -579,7 +579,9 @@ static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
 out:
 	WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
 	drm_modeset_unlock_all(dev);
-	drm_atomic_state_put(state);
+
+	if (state)
+		drm_atomic_state_put(state);
 }
 
 static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Signature · 6 lines
2.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw
Quoted 21 lines · Ander Conselvan de Oliveira

The error paths in hsw_trans_edp_pipe_A_crc_wa() and intel_prepare_reset() would potentially call drm_atomic_state_put with a NULL state, which would lead to a NULL pointer dereference.

Found by coverity.

Fixes 0853695c3ba4 ("drm: Add reference counting to drm_atomic_state")
Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc <[email protected]> # v4.10-rc1+
---
 drivers/gpu/drm/i915/intel_display.c  | 3 ++-
 drivers/gpu/drm/i915/intel_pipe_crc.c | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_display.c +0 -0
index caa2e02..b5a09bd 100644

drivers/gpu/drm/i915/intel_display.c void intel_prepare_reset(struct drm_i915_private *dev_priv) · line 3581

Quoted 6 lines
drivers/gpu/drm/i915/intel_display.c +2 -1
@@ -3577,7 +3577,8 @@ void intel_prepare_reset(struct drm_i915_private *dev_priv)
 	return;
 
 err:
-	drm_atomic_state_put(state);
+	if (state)
+		drm_atomic_state_put(state);

There's no point in the common err cleanup path here. Take a look at cleaning up the error handling in general in this function.

Quoted 8 lines
drivers/gpu/drm/i915/intel_display.c +0 -0
 }
 
 void intel_finish_reset(struct drm_i915_private *dev_priv)
drivers/gpu/drm/i915/intel_pipe_crc.c +0 -0
index 0f1da81..f1bbf49 100644

drivers/gpu/drm/i915/intel_pipe_crc.c static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv, · line 584

Quoted 7 lines
drivers/gpu/drm/i915/intel_pipe_crc.c +3 -1
@@ -579,7 +579,9 @@ static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
 out:
 	WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
 	drm_modeset_unlock_all(dev);
-	drm_atomic_state_put(state);
+
+	if (state)
+		drm_atomic_state_put(state);

Better to use the more typical onion error unwind paths. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 1/1 drm/i915: Avoid drm_atomic_state_put(NULL) on error paths

The error paths in hsw_trans_edp_pipe_A_crc_wa() and intel_prepare_reset() would potentially call drm_atomic_state_put with a NULL state, which would lead to a NULL pointer dereference.

Found by coverity.

v2: Improve the error paths. (Chris)

Fixes 0853695c3ba4 ("drm: Add reference counting to drm_atomic_state")
Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc <[email protected]> # v4.10-rc1+
---
 drivers/gpu/drm/i915/intel_display.c  | 10 +++-------
 drivers/gpu/drm/i915/intel_pipe_crc.c | 10 ++++++----
 2 files changed, 9 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/intel_display.c +3 -7
index 8aca92b..0d055e8 100644
@@ -3561,23 +3561,19 @@ void intel_prepare_reset(struct drm_i915_private *dev_priv)
 	state = drm_atomic_helper_duplicate_state(dev, ctx);
 	if (IS_ERR(state)) {
 		ret = PTR_ERR(state);
-		state = NULL;
 		DRM_ERROR("Duplicating state failed with %i\n", ret);
-		goto err;
+		return;
 	}
 
 	ret = drm_atomic_helper_disable_all(dev, ctx);
 	if (ret) {
 		DRM_ERROR("Suspending crtc's failed with %i\n", ret);
-		goto err;
+		drm_atomic_state_put(state);
+		return;
 	}
 
 	dev_priv->modeset_restore_state = state;
 	state->acquire_ctx = ctx;
-	return;
-
-err:
-	drm_atomic_state_put(state);
 }
 
 void intel_finish_reset(struct drm_i915_private *dev_priv)
drivers/gpu/drm/i915/intel_pipe_crc.c +6 -4
index 0f1da81..c0b1f99 100644
@@ -560,14 +560,14 @@ static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
 	state = drm_atomic_state_alloc(dev);
 	if (!state) {
 		ret = -ENOMEM;
-		goto out;
+		goto unlock;
 	}
 
 	state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
 	pipe_config = intel_atomic_get_crtc_state(state, crtc);
 	if (IS_ERR(pipe_config)) {
 		ret = PTR_ERR(pipe_config);
-		goto out;
+		goto put_state;
 	}
 
 	pipe_config->pch_pfit.force_thru = enable;
@@ -576,10 +576,12 @@ static void hsw_trans_edp_pipe_A_crc_wa(struct drm_i915_private *dev_priv,
 		pipe_config->base.connectors_changed = true;
 
 	ret = drm_atomic_commit(state);
-out:
+
+put_state:
+	drm_atomic_state_put(state);
+unlock:
 	WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
 	drm_modeset_unlock_all(dev);
-	drm_atomic_state_put(state);
 }
 
 static int ivb_pipe_crc_ctl_reg(struct drm_i915_private *dev_priv,
Signature · 6 lines
2.5.5

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#3 lore raw
Quoted 6 lines · Ander Conselvan de Oliveira

The error paths in hsw_trans_edp_pipe_A_crc_wa() and intel_prepare_reset() would potentially call drm_atomic_state_put with a NULL state, which would lead to a NULL pointer dereference.

Found by coverity.

Quoted 7 lines

v2: Improve the error paths. (Chris)

Fixes 0853695c3ba4 ("drm: Add reference counting to drm_atomic_state")
Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc <[email protected]> # v4.10-rc1+

-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw
Quoted 7 lines · Chris Wilson
Quoted 6 lines · Ander Conselvan de Oliveira

The error paths in hsw_trans_edp_pipe_A_crc_wa() and intel_prepare_reset() would potentially call drm_atomic_state_put with a NULL state, which would lead to a NULL pointer dereference.

Found by coverity.

Quoted 8 lines
Quoted 7 lines

v2: Improve the error paths. (Chris)

Fixes 0853695c3ba4 ("drm: Add reference counting to drm_atomic_state")
Cc Chris Wilson <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc <[email protected]> # v4.10-rc1+

Thanks for the patch for yet another of my mistakes. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#5 lore raw

✓ Fi.CI.BAT: success for drm/i915: Avoid drm_atomic_state_put(NULL) on error paths

In reply to Ander Conselvan de Oliveira
== Series Details ==

== Series Details ==

Series: drm/i915: Avoid drm_atomic_state_put(NULL) on error paths
URL : https://patchwork.freedesktop.org/series/18176/
State : success

== Summary ==

Series 18176v1 drm/i915: Avoid drm_atomic_state_put(NULL) on error paths
https://patchwork.freedesktop.org/api/1.0/series/18176/revisions/1/mbox/

Test kms_pipe_crc_basic:

        Subgroup suspend-read-crc-pipe-a:
                dmesg-warn -> PASS       (fi-skl-6700hq)
fi-bdw-5557u     total:246  pass:232  dwarn:0   dfail:0   fail:0   skip:14 
fi-bsw-n3050     total:246  pass:207  dwarn:0   dfail:0   fail:0   skip:39 
fi-bxt-j4205     total:246  pass:224  dwarn:0   dfail:0   fail:0   skip:22 
fi-bxt-t5700     total:82   pass:69   dwarn:0   dfail:0   fail:0   skip:12 
fi-byt-j1900     total:246  pass:219  dwarn:0   dfail:0   fail:0   skip:27 
fi-byt-n2820     total:246  pass:215  dwarn:0   dfail:0   fail:0   skip:31 
fi-hsw-4770      total:246  pass:227  dwarn:0   dfail:0   fail:0   skip:19 
fi-hsw-4770r     total:246  pass:227  dwarn:0   dfail:0   fail:0   skip:19 
fi-ivb-3520m     total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-ivb-3770      total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-kbl-7500u     total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-skl-6260u     total:246  pass:233  dwarn:0   dfail:0   fail:0   skip:13 
fi-skl-6700hq    total:246  pass:226  dwarn:0   dfail:0   fail:0   skip:20 
fi-skl-6700k     total:246  pass:222  dwarn:3   dfail:0   fail:0   skip:21 
fi-skl-6770hq    total:246  pass:233  dwarn:0   dfail:0   fail:0   skip:13 
fi-snb-2520m     total:246  pass:215  dwarn:0   dfail:0   fail:0   skip:31 
fi-snb-2600      total:246  pass:214  dwarn:0   dfail:0   fail:0   skip:32 

60b577f7d497706085d720a9c0f106b5e84408c7 drm-tip: 2017y-01m-18d-11h-41m-42s UTC integration manifest ca65347 drm/i915: Avoid drm_atomic_state_put(NULL) on error paths

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3536/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#6 lore raw

✓ Fi.CI.BAT: success for drm/i915: Avoid drm_atomic_state_put(NULL) on error paths (rev2)

In reply to Ander Conselvan de Oliveira
== Series Details ==

== Series Details ==

Series: drm/i915: Avoid drm_atomic_state_put(NULL) on error paths (rev2)
URL : https://patchwork.freedesktop.org/series/18176/
State : success

== Summary ==

Series 18176v2 drm/i915: Avoid drm_atomic_state_put(NULL) on error paths
https://patchwork.freedesktop.org/api/1.0/series/18176/revisions/2/mbox/

Test kms_pipe_crc_basic:

        Subgroup suspend-read-crc-pipe-a:
                dmesg-warn -> PASS       (fi-skl-6700hq)
fi-bdw-5557u     total:246  pass:232  dwarn:0   dfail:0   fail:0   skip:14 
fi-bsw-n3050     total:246  pass:207  dwarn:0   dfail:0   fail:0   skip:39 
fi-bxt-j4205     total:246  pass:224  dwarn:0   dfail:0   fail:0   skip:22 
fi-bxt-t5700     total:82   pass:69   dwarn:0   dfail:0   fail:0   skip:12 
fi-byt-j1900     total:246  pass:219  dwarn:0   dfail:0   fail:0   skip:27 
fi-byt-n2820     total:246  pass:215  dwarn:0   dfail:0   fail:0   skip:31 
fi-hsw-4770      total:246  pass:227  dwarn:0   dfail:0   fail:0   skip:19 
fi-hsw-4770r     total:246  pass:227  dwarn:0   dfail:0   fail:0   skip:19 
fi-ivb-3520m     total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-ivb-3770      total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-kbl-7500u     total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-skl-6260u     total:246  pass:233  dwarn:0   dfail:0   fail:0   skip:13 
fi-skl-6700hq    total:246  pass:226  dwarn:0   dfail:0   fail:0   skip:20 
fi-skl-6700k     total:246  pass:222  dwarn:3   dfail:0   fail:0   skip:21 
fi-skl-6770hq    total:246  pass:233  dwarn:0   dfail:0   fail:0   skip:13 
fi-snb-2520m     total:246  pass:215  dwarn:0   dfail:0   fail:0   skip:31 
fi-snb-2600      total:246  pass:214  dwarn:0   dfail:0   fail:0   skip:32 

60b577f7d497706085d720a9c0f106b5e84408c7 drm-tip: 2017y-01m-18d-11h-41m-42s UTC integration manifest 007d7bb drm/i915: Avoid drm_atomic_state_put(NULL) on error paths

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3538/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx