diff mbox

[3/3] drm/bridge/sii8620: fix loops in EDID fetch logic

Message ID 20180115173357.31067-4-a.hajda@samsung.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Andrzej Hajda Jan. 15, 2018, 5:33 p.m. UTC
Function should constantly check if cable is connected and finish
in finite time.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/bridge/sil-sii8620.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

Comments

Marek Szyprowski June 8, 2018, 7:19 a.m. UTC | #1
Hi Andrzej,

On 2018-01-15 18:33, Andrzej Hajda wrote:
> Function should constantly check if cable is connected and finish
> in finite time.
>
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

> ---
>   drivers/gpu/drm/bridge/sil-sii8620.c | 31 ++++++++++++++++++++-----------
>   1 file changed, 20 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/sil-sii8620.c b/drivers/gpu/drm/bridge/sil-sii8620.c
> index 7c46847fef18..f65e14836c0e 100644
> --- a/drivers/gpu/drm/bridge/sil-sii8620.c
> +++ b/drivers/gpu/drm/bridge/sil-sii8620.c
> @@ -801,6 +801,7 @@ static void sii8620_burst_rx_all(struct sii8620 *ctx)
>   static void sii8620_fetch_edid(struct sii8620 *ctx)
>   {
>   	u8 lm_ddc, ddc_cmd, int3, cbus;
> +	unsigned long timeout;
>   	int fetched, i;
>   	int edid_len = EDID_LENGTH;
>   	u8 *edid;
> @@ -850,23 +851,31 @@ static void sii8620_fetch_edid(struct sii8620 *ctx)
>   			REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_ENH_DDC_READ_NO_ACK
>   		);
>   
> -		do {
> -			int3 = sii8620_readb(ctx, REG_INTR3);
> +		int3 = 0;
> +		timeout = jiffies + msecs_to_jiffies(200);
> +		for (;;) {
>   			cbus = sii8620_readb(ctx, REG_CBUS_STATUS);
> -
> -			if (int3 & BIT_DDC_CMD_DONE)
> -				break;
> -
> -			if (!(cbus & BIT_CBUS_STATUS_CBUS_CONNECTED)) {
> +			if (~cbus & BIT_CBUS_STATUS_CBUS_CONNECTED) {
> +				kfree(edid);
> +				edid = NULL;
> +				goto end;
> +			}
> +			if (int3 & BIT_DDC_CMD_DONE) {
> +				if (sii8620_readb(ctx, REG_DDC_DOUT_CNT)
> +				    >= FETCH_SIZE)
> +					break;
> +			} else {
> +				int3 = sii8620_readb(ctx, REG_INTR3);
> +			}
> +			if (time_is_before_jiffies(timeout)) {
> +				ctx->error = -ETIMEDOUT;
> +				dev_err(ctx->dev, "timeout during EDID read\n");
>   				kfree(edid);
>   				edid = NULL;
>   				goto end;
>   			}
> -		} while (1);
> -
> -		sii8620_readb(ctx, REG_DDC_STATUS);
> -		while (sii8620_readb(ctx, REG_DDC_DOUT_CNT) < FETCH_SIZE)
>   			usleep_range(10, 20);
> +		}
>   
>   		sii8620_read_buf(ctx, REG_DDC_DATA, edid + fetched, FETCH_SIZE);
>   		if (fetched + FETCH_SIZE == EDID_LENGTH) {

Best regards
Maciej Purski June 13, 2018, 1:12 p.m. UTC | #2
Hi Andrzej,

On 01/15/2018 06:33 PM, Andrzej Hajda wrote:
> Function should constantly check if cable is connected and finish
> in finite time.
> 
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>

Looks fine to me.

Reviewed-by: Maciej Purski <m.purski@samsung.com>

> ---
>   drivers/gpu/drm/bridge/sil-sii8620.c | 31 ++++++++++++++++++++-----------
>   1 file changed, 20 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/bridge/sil-sii8620.c b/drivers/gpu/drm/bridge/sil-sii8620.c
> index 7c46847fef18..f65e14836c0e 100644
> --- a/drivers/gpu/drm/bridge/sil-sii8620.c
> +++ b/drivers/gpu/drm/bridge/sil-sii8620.c
> @@ -801,6 +801,7 @@ static void sii8620_burst_rx_all(struct sii8620 *ctx)
>   static void sii8620_fetch_edid(struct sii8620 *ctx)
>   {
>   	u8 lm_ddc, ddc_cmd, int3, cbus;
> +	unsigned long timeout;
>   	int fetched, i;
>   	int edid_len = EDID_LENGTH;
>   	u8 *edid;
> @@ -850,23 +851,31 @@ static void sii8620_fetch_edid(struct sii8620 *ctx)
>   			REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_ENH_DDC_READ_NO_ACK
>   		);
>   
> -		do {
> -			int3 = sii8620_readb(ctx, REG_INTR3);
> +		int3 = 0;
> +		timeout = jiffies + msecs_to_jiffies(200);
> +		for (;;) {
>   			cbus = sii8620_readb(ctx, REG_CBUS_STATUS);
> -
> -			if (int3 & BIT_DDC_CMD_DONE)
> -				break;
> -
> -			if (!(cbus & BIT_CBUS_STATUS_CBUS_CONNECTED)) {
> +			if (~cbus & BIT_CBUS_STATUS_CBUS_CONNECTED) {
> +				kfree(edid);
> +				edid = NULL;
> +				goto end;
> +			}
> +			if (int3 & BIT_DDC_CMD_DONE) {
> +				if (sii8620_readb(ctx, REG_DDC_DOUT_CNT)
> +				    >= FETCH_SIZE)
> +					break;
> +			} else {
> +				int3 = sii8620_readb(ctx, REG_INTR3);
> +			}
> +			if (time_is_before_jiffies(timeout)) {
> +				ctx->error = -ETIMEDOUT;
> +				dev_err(ctx->dev, "timeout during EDID read\n");
>   				kfree(edid);
>   				edid = NULL;
>   				goto end;
>   			}
> -		} while (1);
> -
> -		sii8620_readb(ctx, REG_DDC_STATUS);
> -		while (sii8620_readb(ctx, REG_DDC_DOUT_CNT) < FETCH_SIZE)
>   			usleep_range(10, 20);
> +		}
>   
>   		sii8620_read_buf(ctx, REG_DDC_DATA, edid + fetched, FETCH_SIZE);
>   		if (fetched + FETCH_SIZE == EDID_LENGTH) {
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpu/drm/bridge/sil-sii8620.c b/drivers/gpu/drm/bridge/sil-sii8620.c
index 7c46847fef18..f65e14836c0e 100644
--- a/drivers/gpu/drm/bridge/sil-sii8620.c
+++ b/drivers/gpu/drm/bridge/sil-sii8620.c
@@ -801,6 +801,7 @@  static void sii8620_burst_rx_all(struct sii8620 *ctx)
 static void sii8620_fetch_edid(struct sii8620 *ctx)
 {
 	u8 lm_ddc, ddc_cmd, int3, cbus;
+	unsigned long timeout;
 	int fetched, i;
 	int edid_len = EDID_LENGTH;
 	u8 *edid;
@@ -850,23 +851,31 @@  static void sii8620_fetch_edid(struct sii8620 *ctx)
 			REG_DDC_CMD, ddc_cmd | VAL_DDC_CMD_ENH_DDC_READ_NO_ACK
 		);
 
-		do {
-			int3 = sii8620_readb(ctx, REG_INTR3);
+		int3 = 0;
+		timeout = jiffies + msecs_to_jiffies(200);
+		for (;;) {
 			cbus = sii8620_readb(ctx, REG_CBUS_STATUS);
-
-			if (int3 & BIT_DDC_CMD_DONE)
-				break;
-
-			if (!(cbus & BIT_CBUS_STATUS_CBUS_CONNECTED)) {
+			if (~cbus & BIT_CBUS_STATUS_CBUS_CONNECTED) {
+				kfree(edid);
+				edid = NULL;
+				goto end;
+			}
+			if (int3 & BIT_DDC_CMD_DONE) {
+				if (sii8620_readb(ctx, REG_DDC_DOUT_CNT)
+				    >= FETCH_SIZE)
+					break;
+			} else {
+				int3 = sii8620_readb(ctx, REG_INTR3);
+			}
+			if (time_is_before_jiffies(timeout)) {
+				ctx->error = -ETIMEDOUT;
+				dev_err(ctx->dev, "timeout during EDID read\n");
 				kfree(edid);
 				edid = NULL;
 				goto end;
 			}
-		} while (1);
-
-		sii8620_readb(ctx, REG_DDC_STATUS);
-		while (sii8620_readb(ctx, REG_DDC_DOUT_CNT) < FETCH_SIZE)
 			usleep_range(10, 20);
+		}
 
 		sii8620_read_buf(ctx, REG_DDC_DATA, edid + fetched, FETCH_SIZE);
 		if (fetched + FETCH_SIZE == EDID_LENGTH) {