From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH v4] KVM: Resize kvm_io_range array dynamically Date: Wed, 07 Mar 2012 16:12:38 +0200 Message-ID: <4F576CD6.60006@redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, jasowang@redhat.com, mtosatti@redhat.com, alex williamson , levinsasha928@gmail.com To: Amos Kong Return-path: Received: from mx1.redhat.com ([209.132.183.28]:53837 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756148Ab2CGOMm (ORCPT ); Wed, 7 Mar 2012 09:12:42 -0500 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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