All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Amos Kong <akong@redhat.com>
Cc: kvm@vger.kernel.org, jasowang@redhat.com, mtosatti@redhat.com,
	alex williamson <alex.williamson@redhat.com>,
	levinsasha928@gmail.com
Subject: Re: [PATCH v4] KVM: Resize kvm_io_range array dynamically
Date: Wed, 07 Mar 2012 16:12:38 +0200	[thread overview]
Message-ID: <4F576CD6.60006@redhat.com> (raw)
In-Reply-To: <abd787bc-4f1c-454d-9d8c-b18c3abf4ede@zmail13.collab.prod.int.phx2.redhat.com>

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


  reply	other threads:[~2012-03-07 14:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  5:24 [PATCH] KVM: Resize kvm_io_bus_range array dynamically Amos Kong
2012-02-29  5:50 ` [PATCH v2] KVM: Resize kvm_io_range " Amos Kong
2012-02-29 13:30 ` [PATCH v3] " Amos Kong
2012-02-29 14:19   ` Jan Kiszka
2012-02-29 15:22     ` Amos Kong
2012-02-29 15:29       ` Jan Kiszka
2012-02-29 16:34         ` Amos Kong
2012-03-01  5:19           ` Amos Kong
2012-03-01  7:01 ` [PATCH v4] " Amos Kong
2012-03-01 10:14   ` Sasha Levin
2012-03-01 15:33     ` Alex Williamson
2012-03-07 10:57   ` Avi Kivity
2012-03-07 12:51     ` Amos Kong
2012-03-07 14:12       ` Avi Kivity [this message]
2012-03-07 13:16   ` [PATCH v5 1/2] KVM: resize " Amos Kong
2012-03-07 13:16   ` [PATCH v5 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-07 13:20   ` [RESEND PATCH v5 0/2] fix ENOSPC issue of iobus dev Amos Kong
2012-03-07 13:20     ` [RESEND PATCH v5 1/2] KVM: resize kvm_io_range array dynamically Amos Kong
2012-03-07 13:20     ` [RESEND PATCH v5 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-08  2:03   ` [PATCH v6 0/2] fix ENOSPC issue of iobus dev Amos Kong
2012-03-08  2:03     ` [PATCH v6 1/2] KVM: resize kvm_io_range array dynamically Amos Kong
2012-03-08 23:20       ` Marcelo Tosatti
2012-03-09  4:05         ` Amos Kong
2012-03-08  2:04     ` [PATCH v6 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-09  4:17   ` [PATCH v7 0/2] fix ENOSPC issue of iobus dev Amos Kong
2012-03-09  4:17     ` [PATCH v7 1/2] KVM: resize kvm_io_range array dynamically Amos Kong
2012-03-09  4:17     ` [PATCH v7 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-09 21:07     ` [PATCH v7 0/2] fix ENOSPC issue of iobus dev Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F576CD6.60006@redhat.com \
    --to=avi@redhat.com \
    --cc=akong@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.