public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm: count reaches -1, tested 0
@ 2009-02-08 14:25 Roel Kluin
  2009-02-09  2:28 ` Dave Airlie
  2009-02-09 22:22 ` Thomas Hellström
  0 siblings, 2 replies; 4+ messages in thread
From: Roel Kluin @ 2009-02-08 14:25 UTC (permalink / raw)
  To: airlied; +Cc: dri-devel, lkml

With a postfix decrement count will reach -1 rather than 0,
subsequent tests fail.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/gpu/drm/via/via_dma.c b/drivers/gpu/drm/via/via_dma.c
index 7a339db..600315c 100644
--- a/drivers/gpu/drm/via/via_dma.c
+++ b/drivers/gpu/drm/via/via_dma.c
@@ -481,9 +481,9 @@ static int via_wait_idle(drm_via_private_t * dev_priv)
 {
 	int count = 10000000;
 
-	while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && count--);
+	while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && --count);
 
-	while (count-- && (VIA_READ(VIA_REG_STATUS) &
+	while (--count && (VIA_READ(VIA_REG_STATUS) &
 			   (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
 			    VIA_3D_ENG_BUSY))) ;
 	return count;
@@ -705,7 +705,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
 	switch (d_siz->func) {
 	case VIA_CMDBUF_SPACE:
 		while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz->size)
-		       && count--) {
+		       && --count) {
 			if (!d_siz->wait) {
 				break;
 			}
@@ -717,7 +717,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
 		break;
 	case VIA_CMDBUF_LAG:
 		while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz->size)
-		       && count--) {
+		       && --count) {
 			if (!d_siz->wait) {
 				break;
 			}


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm: count reaches -1, tested 0
  2009-02-08 14:25 [PATCH] drm: count reaches -1, tested 0 Roel Kluin
@ 2009-02-09  2:28 ` Dave Airlie
  2009-02-09 22:22 ` Thomas Hellström
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Airlie @ 2009-02-09  2:28 UTC (permalink / raw)
  To: Roel Kluin; +Cc: airlied, dri-devel, lkml, Thomas Hellström

On Mon, Feb 9, 2009 at 12:25 AM, Roel Kluin <roel.kluin@gmail.com> wrote:
> With a postfix decrement count will reach -1 rather than 0,
> subsequent tests fail.

Thomas can you sign off on this?

Dave.
>
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/drivers/gpu/drm/via/via_dma.c b/drivers/gpu/drm/via/via_dma.c
> index 7a339db..600315c 100644
> --- a/drivers/gpu/drm/via/via_dma.c
> +++ b/drivers/gpu/drm/via/via_dma.c
> @@ -481,9 +481,9 @@ static int via_wait_idle(drm_via_private_t * dev_priv)
>  {
>        int count = 10000000;
>
> -       while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && count--);
> +       while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && --count);
>
> -       while (count-- && (VIA_READ(VIA_REG_STATUS) &
> +       while (--count && (VIA_READ(VIA_REG_STATUS) &
>                           (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
>                            VIA_3D_ENG_BUSY))) ;
>        return count;
> @@ -705,7 +705,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
>        switch (d_siz->func) {
>        case VIA_CMDBUF_SPACE:
>                while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz->size)
> -                      && count--) {
> +                      && --count) {
>                        if (!d_siz->wait) {
>                                break;
>                        }
> @@ -717,7 +717,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
>                break;
>        case VIA_CMDBUF_LAG:
>                while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz->size)
> -                      && count--) {
> +                      && --count) {
>                        if (!d_siz->wait) {
>                                break;
>                        }
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm: count reaches -1, tested 0
  2009-02-08 14:25 [PATCH] drm: count reaches -1, tested 0 Roel Kluin
  2009-02-09  2:28 ` Dave Airlie
@ 2009-02-09 22:22 ` Thomas Hellström
  2009-02-10 20:48   ` [PATCH v2] " Roel Kluin
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Hellström @ 2009-02-09 22:22 UTC (permalink / raw)
  To: Roel Kluin; +Cc: airlied, dri-devel, lkml

Hi!

Roel Kluin wrote:
> With a postfix decrement count will reach -1 rather than 0,
> subsequent tests fail.
>   
This code is about to be abandoned, but if we're going to fix it, 
instead of pushing the problem to then next while loop, what about

while (count && condition)
    count--;

Can you redo the patch based on that?


Thanks,
Thomas

> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/drivers/gpu/drm/via/via_dma.c b/drivers/gpu/drm/via/via_dma.c
> index 7a339db..600315c 100644
> --- a/drivers/gpu/drm/via/via_dma.c
> +++ b/drivers/gpu/drm/via/via_dma.c
> @@ -481,9 +481,9 @@ static int via_wait_idle(drm_via_private_t * dev_priv)
>  {
>  	int count = 10000000;
>  
> -	while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && count--);
> +	while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && --count);
>  
> -	while (count-- && (VIA_READ(VIA_REG_STATUS) &
> +	while (--count && (VIA_READ(VIA_REG_STATUS) &
>  			   (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
>  			    VIA_3D_ENG_BUSY))) ;
>  	return count;
> @@ -705,7 +705,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
>  	switch (d_siz->func) {
>  	case VIA_CMDBUF_SPACE:
>  		while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz->size)
> -		       && count--) {
> +		       && --count) {
>  			if (!d_siz->wait) {
>  				break;
>  			}
> @@ -717,7 +717,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
>  		break;
>  	case VIA_CMDBUF_LAG:
>  		while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz->size)
> -		       && count--) {
> +		       && --count) {
>  			if (!d_siz->wait) {
>  				break;
>  			}
>
>
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> --
> _______________________________________________
> Dri-devel mailing list
> Dri-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dri-devel
>   




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] drm: count reaches -1, tested 0
  2009-02-09 22:22 ` Thomas Hellström
@ 2009-02-10 20:48   ` Roel Kluin
  0 siblings, 0 replies; 4+ messages in thread
From: Roel Kluin @ 2009-02-10 20:48 UTC (permalink / raw)
  To: Thomas Hellström; +Cc: airlied, dri-devel, lkml

Thomas Hellström wrote:

> This code is about to be abandoned, but if we're going to fix it,
> instead of pushing the problem to then next while loop, what about
> 
> while (count && condition)
>    count--;
> 
> Can you redo the patch based on that?

Very well reviewed, thanks. Like this?
------------------->8-----------------------8<------------------------

With a postfix decrement in the test count will reach -1 rather than 0,
subsequent tests fail.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/gpu/drm/via/via_dma.c b/drivers/gpu/drm/via/via_dma.c
index 7a339db..029c22a 100644
--- a/drivers/gpu/drm/via/via_dma.c
+++ b/drivers/gpu/drm/via/via_dma.c
@@ -481,11 +481,12 @@ static int via_wait_idle(drm_via_private_t * dev_priv)
 {
 	int count = 10000000;
 
-	while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && count--);
+	while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && --count)
+		;
 
-	while (count-- && (VIA_READ(VIA_REG_STATUS) &
-			   (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
-			    VIA_3D_ENG_BUSY))) ;
+	while (count && (VIA_READ(VIA_REG_STATUS) & (VIA_CMD_RGTR_BUSY |
+					VIA_2D_ENG_BUSY | VIA_3D_ENG_BUSY)))
+		count--;
 	return count;
 }
 
@@ -705,7 +706,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
 	switch (d_siz->func) {
 	case VIA_CMDBUF_SPACE:
 		while (((tmp_size = via_cmdbuf_space(dev_priv)) < d_siz->size)
-		       && count--) {
+		       && --count) {
 			if (!d_siz->wait) {
 				break;
 			}
@@ -717,7 +718,7 @@ static int via_cmdbuf_size(struct drm_device *dev, void *data, struct drm_file *
 		break;
 	case VIA_CMDBUF_LAG:
 		while (((tmp_size = via_cmdbuf_lag(dev_priv)) > d_siz->size)
-		       && count--) {
+		       && --count) {
 			if (!d_siz->wait) {
 				break;
 			}

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-02-10 20:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-08 14:25 [PATCH] drm: count reaches -1, tested 0 Roel Kluin
2009-02-09  2:28 ` Dave Airlie
2009-02-09 22:22 ` Thomas Hellström
2009-02-10 20:48   ` [PATCH v2] " Roel Kluin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox