Skip to contentSkip to conversation

drm/i915: fix a read size argument

PATCH In review Dan Carpenter 5 participants 6 messages Oct 13, 2016

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

PATCH 1/1 drm/i915: fix a read size argument

We want to read 3 bytes here, but because the parenthesis are in the wrong place we instead read:

	sizeof(intel_dp->edp_dpcd) == sizeof(intel_dp->edp_dpcd)

which is one byte.

Fixes fe5a66f91c88 ("drm/i915: Read PSR caps/intermediate freqs/etc. only once on eDP")
drivers/gpu/drm/i915/intel_dp.c +2 -2
index 14a3cf0..ee8aa95 100644
@@ -3551,8 +3551,8 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
 	/* Read the eDP Display control capabilities registers */
 	if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
 	    drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
-			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd) ==
-			     sizeof(intel_dp->edp_dpcd)))
+			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
+			     sizeof(intel_dp->edp_dpcd))
 		DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
 			      intel_dp->edp_dpcd);
 

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Dan Carpenter

We want to read 3 bytes here, but because the parenthesis are in the wrong place we instead read:

	sizeof(intel_dp->edp_dpcd) == sizeof(intel_dp->edp_dpcd)

which is one byte.

Fixes fe5a66f91c88 ("drm/i915: Read PSR caps/intermediate freqs/etc. only once on eDP")

Oops, does smatch catch this? I don't recall seeing the complaint in recent runs?

-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
Quoted 4 lines · Chris Wilson
Quoted 3 lines · Dan Carpenter

We want to read 3 bytes here, but because the parenthesis are in the wrong place we instead read:

Quoted 8 lines
Quoted 6 lines
	sizeof(intel_dp->edp_dpcd) == sizeof(intel_dp->edp_dpcd)

which is one byte.

Fixes fe5a66f91c88 ("drm/i915: Read PSR caps/intermediate freqs/etc. only once on eDP")

Oops, does smatch catch this?

Yeah. It does.

regards,
dan carpenter

Reviewed-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter
Quoted 9 lines · Dan Carpenter

We want to read 3 bytes here, but because the parenthesis are in the wrong place we instead read:

	sizeof(intel_dp->edp_dpcd) == sizeof(intel_dp->edp_dpcd)

which is one byte.

Fixes fe5a66f91c88 ("drm/i915: Read PSR caps/intermediate freqs/etc. only once on eDP")

Good catch! What tool did you use to find it, or did you find it by inspection?

(btw, there's a missing --- here, between the commit msg and the diff)

Quoted 6 lines
drivers/gpu/drm/i915/intel_dp.c +0 -0
index 14a3cf0..ee8aa95 100644

drivers/gpu/drm/i915/intel_dp.c intel_edp_init_dpcd(struct intel_dp *intel_dp) · line 3557

Quoted 9 lines
drivers/gpu/drm/i915/intel_dp.c +2 -2
@@ -3551,8 +3551,8 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
 	/* Read the eDP Display control capabilities registers */
 	if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
 	    drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
-			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd) ==
-			     sizeof(intel_dp->edp_dpcd)))
+			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
+			     sizeof(intel_dp->edp_dpcd))
 		DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
 			      intel_dp->edp_dpcd);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
In reply to Dan Carpenter

Am 13.10.2016 10:55, schrieb Dan Carpenter:

Quoted 15 lines

We want to read 3 bytes here, but because the parenthesis are in the wrong place we instead read:

	sizeof(intel_dp->edp_dpcd) == sizeof(intel_dp->edp_dpcd)

which is one byte.

Fixes fe5a66f91c88 ("drm/i915: Read PSR caps/intermediate freqs/etc. only once on eDP")
drivers/gpu/drm/i915/intel_dp.c +0 -0
index 14a3cf0..ee8aa95 100644

drivers/gpu/drm/i915/intel_dp.c intel_edp_init_dpcd(struct intel_dp *intel_dp) · line 3555

Quoted 7 lines
drivers/gpu/drm/i915/intel_dp.c +2 -2
@@ -3551,8 +3551,8 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
 	/* Read the eDP Display control capabilities registers */
 	if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
 	    drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
-			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd) ==
-			     sizeof(intel_dp->edp_dpcd)))
+			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
+			     sizeof(intel_dp->edp_dpcd))

perhaps we can morph that into something more readable ? I would suggest:

if (intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE)

  {
    size_t size=sizeof(intel_dp->edp_dpcd); /* == EDP_DISPLAY_CTL_CAP_SIZE */
    int ret;	

    ret=drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,intel_dp->edp_dpcd,size);	

    if (ret != size )
        ......

}

this way it improves readability and reduces line length.

Quoted 8 lines
drivers/gpu/drm/i915/intel_dp.c +0 -1
 		DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
 			      intel_dp->edp_dpcd);
 
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#5 lore raw
Quoted 10 lines · walter harms

Am 13.10.2016 10:55, schrieb Dan Carpenter:

Quoted 9 lines

We want to read 3 bytes here, but because the parenthesis are in the wrong place we instead read:

	sizeof(intel_dp->edp_dpcd) == sizeof(intel_dp->edp_dpcd)

which is one byte.

Fixes fe5a66f91c88 ("drm/i915: Read PSR caps/intermediate freqs/etc. only once on eDP")

Dan, good catch, thank you. Luckily we only really use the first byte currently...

Quoted 28 lines

drivers/gpu/drm/i915/intel_dp.c intel_edp_init_dpcd(struct intel_dp *intel_dp) · line 3555

Quoted 12 lines
drivers/gpu/drm/i915/intel_dp.c +2 -2
index 14a3cf0..ee8aa95 100644
@@ -3551,8 +3551,8 @@ intel_edp_init_dpcd(struct intel_dp *intel_dp)
 	/* Read the eDP Display control capabilities registers */
 	if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
 	    drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
-			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd) ==
-			     sizeof(intel_dp->edp_dpcd)))
+			     intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
+			     sizeof(intel_dp->edp_dpcd))

perhaps we can morph that into something more readable ? I would suggest:

if (intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE)

  {
    size_t size=sizeof(intel_dp->edp_dpcd); /* == EDP_DISPLAY_CTL_CAP_SIZE */
    int ret;	

    ret=drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,intel_dp->edp_dpcd,size);	

    if (ret != size )
        ......
Quoted 3 lines

}

this way it improves readability and reduces line length.

Not convinced, let's just take the simple brace fix now.

BR,
Jani.

Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel