mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] vfio/pci: remove a bogus cast in vfio_msi_set_block()
@ 2018-05-28  7:47 Dan Carpenter
  2018-05-28 19:27 ` Auger Eric
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2018-05-28  7:47 UTC (permalink / raw)
  To: Alex Williamson; +Cc: kvm, linux-kernel, kernel-janitors

This cast is confusing...  The "start" variable is an unsigned int.  We
absolutely do not want to cast it to a negative int so why is the cast
there?  It turns out, when you look at the context, it's a no-op and we
can just remove it.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index 1c46045b0e7f..2724fed62129 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -368,7 +368,7 @@ static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start,
 	}
 
 	if (ret) {
-		for (--j; j >= (int)start; j--)
+		for (--j; j >= start; j--)
 			vfio_msi_set_vector_signal(vdev, j, -1, msix);
 	}
 

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

* Re: [PATCH] vfio/pci: remove a bogus cast in vfio_msi_set_block()
  2018-05-28  7:47 [PATCH] vfio/pci: remove a bogus cast in vfio_msi_set_block() Dan Carpenter
@ 2018-05-28 19:27 ` Auger Eric
  2018-05-29  8:45   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Auger Eric @ 2018-05-28 19:27 UTC (permalink / raw)
  To: Dan Carpenter, Alex Williamson; +Cc: kvm, linux-kernel, kernel-janitors

Hi Dan,

On 05/28/2018 09:47 AM, Dan Carpenter wrote:
> This cast is confusing...  The "start" variable is an unsigned int.  We
> absolutely do not want to cast it to a negative int so why is the cast
> there?  It turns out, when you look at the context, it's a no-op and we
> can just remove it.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
> index 1c46045b0e7f..2724fed62129 100644
> --- a/drivers/vfio/pci/vfio_pci_intrs.c
> +++ b/drivers/vfio/pci/vfio_pci_intrs.c
> @@ -368,7 +368,7 @@ static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start,
>  	}
>  
>  	if (ret) {
> -		for (--j; j >= (int)start; j--)
> +		for (--j; j >= start; j--)
I think this was done one purpose as j can be -1 while start is an
unsigned.

See b95d9305e8cb8d432ca02da1b759fef59bc50ace
"../.., -1 being compared as unsigned doesn't produce the intended stop
condition."

If I remember correctly this led to a bug.

Thanks

Eric
>  			vfio_msi_set_vector_signal(vdev, j, -1, msix);
>  	}
>  
> 

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

* Re: [PATCH] vfio/pci: remove a bogus cast in vfio_msi_set_block()
  2018-05-28 19:27 ` Auger Eric
@ 2018-05-29  8:45   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2018-05-29  8:45 UTC (permalink / raw)
  To: Auger Eric; +Cc: Alex Williamson, kvm, linux-kernel, kernel-janitors

On Mon, May 28, 2018 at 09:27:18PM +0200, Auger Eric wrote:
> Hi Dan,
> 
> On 05/28/2018 09:47 AM, Dan Carpenter wrote:
> > This cast is confusing...  The "start" variable is an unsigned int.  We
> > absolutely do not want to cast it to a negative int so why is the cast
> > there?  It turns out, when you look at the context, it's a no-op and we
> > can just remove it.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
> > index 1c46045b0e7f..2724fed62129 100644
> > --- a/drivers/vfio/pci/vfio_pci_intrs.c
> > +++ b/drivers/vfio/pci/vfio_pci_intrs.c
> > @@ -368,7 +368,7 @@ static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start,
> >  	}
> >  
> >  	if (ret) {
> > -		for (--j; j >= (int)start; j--)
> > +		for (--j; j >= start; j--)
> I think this was done one purpose as j can be -1 while start is an
> unsigned.
> 

Oh, wow...  Yeah.  Sorry.  I didn't think that through.  I will create
a static checker warning so this particular bug doesn't happen to me
again.

regards,
dan carpenter

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

end of thread, other threads:[~2018-05-29  8:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-28  7:47 [PATCH] vfio/pci: remove a bogus cast in vfio_msi_set_block() Dan Carpenter
2018-05-28 19:27 ` Auger Eric
2018-05-29  8:45   ` Dan Carpenter

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

all inboxes | Powered by JetHome®