diff mbox

kvm: device-assignment: Fix kvm_get_irq_route_gsi() return check

Message ID 20090512221144.5883.46470.stgit@dl380g6-3.ned.telco.ned.telco (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Williamson May 12, 2009, 10:14 p.m. UTC
Cast to a signed int to test for < 0.

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
---

 This supersedes "[PATCH] kvm: device-assignment: Catch GSI overflow"

 hw/device-assignment.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)


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

Comments

Yang, Sheng May 13, 2009, 3:36 a.m. UTC | #1
On Wednesday 13 May 2009 06:14:01 Alex Williamson wrote:
> Cast to a signed int to test for < 0.
>
> Signed-off-by: Alex Williamson <alex.williamson@hp.com>
> ---
>
>  This supersedes "[PATCH] kvm: device-assignment: Catch GSI overflow"
>
>  hw/device-assignment.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> index a6cc9b9..5bdae24 100644
> --- a/hw/device-assignment.c
> +++ b/hw/device-assignment.c
> @@ -798,7 +798,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev,
> unsigned int ctrl_pos) pci_dev->cap.start + PCI_MSI_DATA_32);
>          assigned_dev->entry->type = KVM_IRQ_ROUTING_MSI;
>          assigned_dev->entry->gsi = kvm_get_irq_route_gsi(kvm_context);
> -        if (assigned_dev->entry->gsi < 0) {
> +        if ((int)(assigned_dev->entry->gsi) < 0) {
>              perror("assigned_dev_update_msi: kvm_get_irq_route_gsi");
>              return;
>          }

Use a return value(r) seems better.

And I realized there is memory leak here. Entry seems haven't been freed for 
error... So does MSI-X...
Alex Williamson May 13, 2009, 3:55 a.m. UTC | #2
On Wed, 2009-05-13 at 11:36 +0800, Yang, Sheng wrote:
> On Wednesday 13 May 2009 06:14:01 Alex Williamson wrote:
> > --- a/hw/device-assignment.c
> > +++ b/hw/device-assignment.c
> > @@ -798,7 +798,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev,
> > unsigned int ctrl_pos) pci_dev->cap.start + PCI_MSI_DATA_32);
> >          assigned_dev->entry->type = KVM_IRQ_ROUTING_MSI;
> >          assigned_dev->entry->gsi = kvm_get_irq_route_gsi(kvm_context);
> > -        if (assigned_dev->entry->gsi < 0) {
> > +        if ((int)(assigned_dev->entry->gsi) < 0) {
> >              perror("assigned_dev_update_msi: kvm_get_irq_route_gsi");
> >              return;
> >          }
> 
> Use a return value(r) seems better.

Hi Sheng,

Do you mean:

r = kvm_get_irq_route_gsi(kvm_context);
if (r < 0) {
...
}
assigned_dev->entry->gsi = r;

> And I realized there is memory leak here. Entry seems haven't been freed for 
> error... So does MSI-X...

I hadn't noticed that one, but now that you mention it, yep.  Thanks,

Alex


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yang, Sheng May 13, 2009, 4:09 a.m. UTC | #3
On Wednesday 13 May 2009 11:55:50 Alex Williamson wrote:
> On Wed, 2009-05-13 at 11:36 +0800, Yang, Sheng wrote:
> > On Wednesday 13 May 2009 06:14:01 Alex Williamson wrote:
> > > --- a/hw/device-assignment.c
> > > +++ b/hw/device-assignment.c
> > > @@ -798,7 +798,7 @@ static void assigned_dev_update_msi(PCIDevice
> > > *pci_dev, unsigned int ctrl_pos) pci_dev->cap.start + PCI_MSI_DATA_32);
> > >          assigned_dev->entry->type = KVM_IRQ_ROUTING_MSI;
> > >          assigned_dev->entry->gsi = kvm_get_irq_route_gsi(kvm_context);
> > > -        if (assigned_dev->entry->gsi < 0) {
> > > +        if ((int)(assigned_dev->entry->gsi) < 0) {
> > >              perror("assigned_dev_update_msi: kvm_get_irq_route_gsi");
> > >              return;
> > >          }
> >
> > Use a return value(r) seems better.
>
> Hi Sheng,
>
> Do you mean:
>
> r = kvm_get_irq_route_gsi(kvm_context);
> if (r < 0) {
> ...
> }
> assigned_dev->entry->gsi = r;

Yes.

> > And I realized there is memory leak here. Entry seems haven't been freed
> > for error... So does MSI-X...
>
> I hadn't noticed that one, but now that you mention it, yep.  Thanks,

Thanks. :)
diff mbox

Patch

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index a6cc9b9..5bdae24 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -798,7 +798,7 @@  static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos)
                 pci_dev->cap.start + PCI_MSI_DATA_32);
         assigned_dev->entry->type = KVM_IRQ_ROUTING_MSI;
         assigned_dev->entry->gsi = kvm_get_irq_route_gsi(kvm_context);
-        if (assigned_dev->entry->gsi < 0) {
+        if ((int)(assigned_dev->entry->gsi) < 0) {
             perror("assigned_dev_update_msi: kvm_get_irq_route_gsi");
             return;
         }