Skip to contentSkip to conversation

drm/i915: Skip pixel multiplier x-check if we fail to send the command

PATCH In review Damien Lespiau 2 participants 6 messages Jul 11, 2013 – Jul 12, 2013

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

PATCH 1/1 drm/i915: Skip pixel multiplier x-check if we fail to send the command

If intel_sdvo_get_value() fails here, val is unitialized and the cross check won't check anything.

---
 drivers/gpu/drm/i915/intel_sdvo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_sdvo.c +4 -1
index b8e1623..4481f6a 100644
@@ -1357,7 +1357,10 @@ static void intel_sdvo_get_config(struct intel_encoder *encoder,
 	}
 
 	/* Cross check the port pixel multiplier with the sdvo encoder state. */
-	intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
+	if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
+				  &val, 1))
+		return;
+
 	switch (val) {
 	case SDVO_CLOCK_RATE_MULT_1X:
 		encoder_pixel_multiplier = 1;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 13 lines · Damien Lespiau

If intel_sdvo_get_value() fails here, val is unitialized and the cross check won't check anything.

---
 drivers/gpu/drm/i915/intel_sdvo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_sdvo.c +0 -0
index b8e1623..4481f6a 100644

drivers/gpu/drm/i915/intel_sdvo.c static void intel_sdvo_get_config(struct intel_encoder *encoder, · line 1362

Quoted 7 lines
drivers/gpu/drm/i915/intel_sdvo.c +3 -1
@@ -1357,7 +1357,10 @@ static void intel_sdvo_get_config(struct intel_encoder *encoder,
 	}
 
 	/* Cross check the port pixel multiplier with the sdvo encoder state. */
-	intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
+	if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
+				  &val, 1))
+		return;

But now it fails silently instead of being paranoid ... Can we just shut up the tool instead?
-Daniel

Quoted 11 lines
drivers/gpu/drm/i915/intel_sdvo.c +1 -0
+
 	switch (val) {
 	case SDVO_CLOCK_RATE_MULT_1X:
 		encoder_pixel_multiplier = 1;
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#2 lore raw
Quoted 16 lines · Daniel Vetter
Quoted 15 lines · Damien Lespiau

If intel_sdvo_get_value() fails here, val is unitialized and the cross check won't check anything.

---
 drivers/gpu/drm/i915/intel_sdvo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_sdvo.c +0 -0
index b8e1623..4481f6a 100644
@@ -1357,7 +1357,10 @@ static void intel_sdvo_get_config(struct intel_encoder *encoder,
 	}
 
Quoted 8 lines

drivers/gpu/drm/i915/intel_sdvo.c static void intel_sdvo_get_config(struct intel_encoder *encoder, · line 1362

Quoted 5 lines
drivers/gpu/drm/i915/intel_sdvo.c +3 -1
 	/* Cross check the port pixel multiplier with the sdvo encoder state. */
-	intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
+	if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
+				  &val, 1))
+		return;

But now it fails silently instead of being paranoid ... Can we just shut up the tool instead?

We absolutely can! (and it's done).

Signature · 1 line
Damien
#3 lore raw
Quoted 26 lines · Damien Lespiau
Quoted 16 lines · Daniel Vetter
Quoted 15 lines · Damien Lespiau

If intel_sdvo_get_value() fails here, val is unitialized and the cross check won't check anything.

---
 drivers/gpu/drm/i915/intel_sdvo.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_sdvo.c +0 -0
index b8e1623..4481f6a 100644
@@ -1357,7 +1357,10 @@ static void intel_sdvo_get_config(struct intel_encoder *encoder,
 	}
 
Quoted 8 lines

drivers/gpu/drm/i915/intel_sdvo.c static void intel_sdvo_get_config(struct intel_encoder *encoder, · line 1362

Quoted 5 lines
drivers/gpu/drm/i915/intel_sdvo.c +3 -1
 	/* Cross check the port pixel multiplier with the sdvo encoder state. */
-	intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
+	if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
+				  &val, 1))
+		return;

But now it fails silently instead of being paranoid ... Can we just shut up the tool instead?

Quoted 1 line

We absolutely can! (and it's done).

On second thought we could shovel the switch into an if block so that val is only read when written. Since pixel_multiplier is already set to 0 (in case the sdvo device returns garbage) we'll correctly WARN even when get_value fails (and per chance the stack garbage in val is the right value for the pixel multiplier).
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#4 lore raw

PATCH 1/2 drm/i915: Don't attempt to read an unitialized stack value

If intel_sdvo_get_value() fails here, val is unitialized and the cross check will compare the pipe config multiplier with a bogus value.

Instead, only set encoder_pixel_multiplier when the sdvo command has been successful. The cross check will compare the pipe config value with 0 otherwise.

v2: Do the cross check with the initial value of encoder_pixel_multiplier (0) if the sdvo command fails (and thus keep the warning) (Daniel Vetter)

---
 drivers/gpu/drm/i915/intel_sdvo.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/intel_sdvo.c +13 -11
index b8e1623..eb2a603 100644
@@ -1357,17 +1357,19 @@ static void intel_sdvo_get_config(struct intel_encoder *encoder,
 	}
 
 	/* Cross check the port pixel multiplier with the sdvo encoder state. */
-	intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
-	switch (val) {
-	case SDVO_CLOCK_RATE_MULT_1X:
-		encoder_pixel_multiplier = 1;
-		break;
-	case SDVO_CLOCK_RATE_MULT_2X:
-		encoder_pixel_multiplier = 2;
-		break;
-	case SDVO_CLOCK_RATE_MULT_4X:
-		encoder_pixel_multiplier = 4;
-		break;
+	if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
+				 &val, 1)) {
+		switch (val) {
+		case SDVO_CLOCK_RATE_MULT_1X:
+			encoder_pixel_multiplier = 1;
+			break;
+		case SDVO_CLOCK_RATE_MULT_2X:
+			encoder_pixel_multiplier = 2;
+			break;
+		case SDVO_CLOCK_RATE_MULT_4X:
+			encoder_pixel_multiplier = 4;
+			break;
+		}
 	}
 
 	if(HAS_PCH_SPLIT(dev))
Signature · 1 line
1.8.3.1
#5 lore raw

Re: [PATCH 1/2] drm/i915: Don't attempt to read an unitialized stack value

Quoted 11 lines · Damien Lespiau

If intel_sdvo_get_value() fails here, val is unitialized and the cross check will compare the pipe config multiplier with a bogus value.

Instead, only set encoder_pixel_multiplier when the sdvo command has been successful. The cross check will compare the pipe config value with 0 otherwise.

v2: Do the cross check with the initial value of encoder_pixel_multiplier (0) if the sdvo command fails (and thus keep the warning) (Daniel Vetter)

Queued for -next, thanks for the patch.
-Daniel

Quoted 46 lines
---
 drivers/gpu/drm/i915/intel_sdvo.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/intel_sdvo.c +13 -11
index b8e1623..eb2a603 100644
@@ -1357,17 +1357,19 @@ static void intel_sdvo_get_config(struct intel_encoder *encoder,
 	}
 
 	/* Cross check the port pixel multiplier with the sdvo encoder state. */
-	intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT, &val, 1);
-	switch (val) {
-	case SDVO_CLOCK_RATE_MULT_1X:
-		encoder_pixel_multiplier = 1;
-		break;
-	case SDVO_CLOCK_RATE_MULT_2X:
-		encoder_pixel_multiplier = 2;
-		break;
-	case SDVO_CLOCK_RATE_MULT_4X:
-		encoder_pixel_multiplier = 4;
-		break;
+	if (intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_CLOCK_RATE_MULT,
+				 &val, 1)) {
+		switch (val) {
+		case SDVO_CLOCK_RATE_MULT_1X:
+			encoder_pixel_multiplier = 1;
+			break;
+		case SDVO_CLOCK_RATE_MULT_2X:
+			encoder_pixel_multiplier = 2;
+			break;
+		case SDVO_CLOCK_RATE_MULT_4X:
+			encoder_pixel_multiplier = 4;
+			break;
+		}
 	}
 
 	if(HAS_PCH_SPLIT(dev))
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch