Skip to contentSkip to conversation

drm/bridge: ti-sn65dsi86: fix a ternary type promotion bug

PATCH In review Dan Carpenter 2 participants 3 messages May 18, 2021

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

PATCH 1/1 drm/bridge: ti-sn65dsi86: fix a ternary type promotion bug

The ti_sn_aux_transfer() function returns ssize_t (signed long). It's supposed to return negative error codes or the number of bytes transferred. The "ret" variable is int and the "len" variable is unsigned int.

The problem is that with a ternary like this, the negative int is first type promoted to unsigned int to match "len" at this point it is a high positive value. Then when it is type promoted to ssize_t (s64) it remains a high positive value instead of sign extending and becoming a negative again.

Fix this by removing the ternary.

Fixes b137406d9679 ("drm/bridge: ti-sn65dsi86: If refclk, DP AUX can happen w/out pre-enable")
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +3 -1
index bb0a0e1c6341..45a2969afb2b 100644
@@ -1042,7 +1042,9 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux,
 	pm_runtime_mark_last_busy(pdata->dev);
 	pm_runtime_put_autosuspend(pdata->dev);
 
-	return ret ? ret : len;
+	if (ret)
+		return ret;
+	return len;
 }
 
 static int ti_sn_bridge_parse_dsi_host(struct ti_sn65dsi86 *pdata)
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw

Hey Dan,

Thanks for submitting this.

Quoted 25 lines · Dan Carpenter

The ti_sn_aux_transfer() function returns ssize_t (signed long). It's supposed to return negative error codes or the number of bytes transferred. The "ret" variable is int and the "len" variable is unsigned int.

The problem is that with a ternary like this, the negative int is first type promoted to unsigned int to match "len" at this point it is a high positive value. Then when it is type promoted to ssize_t (s64) it remains a high positive value instead of sign extending and becoming a negative again.

Fix this by removing the ternary.

Fixes b137406d9679 ("drm/bridge: ti-sn65dsi86: If refclk, DP AUX can happen w/out pre-enable")
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +0 -0
index bb0a0e1c6341..45a2969afb2b 100644

drivers/gpu/drm/bridge/ti-sn65dsi86.c static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux, · line 1049

Quoted 9 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +3 -1
@@ -1042,7 +1042,9 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux,
        pm_runtime_mark_last_busy(pdata->dev);
        pm_runtime_put_autosuspend(pdata->dev);
 
-       return ret ? ret : len;
+       if (ret)
+               return ret;
+       return len;
 }
 

Applying to drm-misc-fixes.

#2 lore raw

Since it fixes drm-misc-next, applied it there instead.

Quoted 44 lines · Robert Foss

Hey Dan,

Thanks for submitting this.

Quoted 25 lines · Dan Carpenter

The ti_sn_aux_transfer() function returns ssize_t (signed long). It's supposed to return negative error codes or the number of bytes transferred. The "ret" variable is int and the "len" variable is unsigned int.

The problem is that with a ternary like this, the negative int is first type promoted to unsigned int to match "len" at this point it is a high positive value. Then when it is type promoted to ssize_t (s64) it remains a high positive value instead of sign extending and becoming a negative again.

Fix this by removing the ternary.

Fixes b137406d9679 ("drm/bridge: ti-sn65dsi86: If refclk, DP AUX can happen w/out pre-enable")
---
 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/ti-sn65dsi86.c +0 -0
index bb0a0e1c6341..45a2969afb2b 100644

drivers/gpu/drm/bridge/ti-sn65dsi86.c static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux, · line 1049

Quoted 9 lines
drivers/gpu/drm/bridge/ti-sn65dsi86.c +3 -1
@@ -1042,7 +1042,9 @@ static ssize_t ti_sn_aux_transfer(struct drm_dp_aux *aux,
        pm_runtime_mark_last_busy(pdata->dev);
        pm_runtime_put_autosuspend(pdata->dev);
 
-       return ret ? ret : len;
+       if (ret)
+               return ret;
+       return len;
 }
 

Applying to drm-misc-fixes.