Re: [PATCH v4] KVM: Resize kvm_io_range array dynamically

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/07/2012 02:51 PM, Amos Kong wrote:
> > > +
> > > +	new_bus = kmemdup(bus, sizeof(*bus) + ((bus->dev_count - 1) *
> > > +			  sizeof(struct kvm_io_range)), GFP_KERNEL);
> > > +	if (!new_bus)
> > > +		return -ENOMEM;
> > > +
> > > +	new_bus->dev_count--;
> > > +	/* copy last entry of bus->range to deleted entry spot if
> > > +	   deleted entry isn't the last entry of bus->range */
> > > +	if (i != bus->dev_count - 1) {
> > 
> > The check is unneeded - if they compare equal, the copy is a no-op.
>
>
> In kvm_io_bus_unregister_dev(), we need to delete one entry from original bus array.
> so the allocated new bus array only has $N - 1 entries, ($N is the entry number of original bus array)
>
> If i equals to bus->dev_count - 1, then the entry which is need to be deleted is the last entry of original bus array.
> and the entry isn't copied to new bus array, so we don't need to do anything, sort isn't necessary.

It's actually wrong to avoid the copy like I suggested, since this isn't
an in-place delete, and we don't have space for the last entry.

btw you don't need to sort at all.  Instead do

  memcpy(new_bus->range, bus->range, i * sizeof)
  memcpy(new_bus->range + i, bus->range + i + 1, new_bus->dev_count - i
* sizeof)

-- 
error compiling committee.c: too many arguments to function

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


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux