Received: from eggs.gnu.org ([2001:4830:134:3::10]:50633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1unN-0001bC-ND for qemu-devel@nongnu.org; Wed, 02 Nov 2016 08:37:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1unK-0007wR-Jb for qemu-devel@nongnu.org; Wed, 02 Nov 2016 08:37:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c1unK-0007wI-EN for qemu-devel@nongnu.org; Wed, 02 Nov 2016 08:37:30 -0400 From: Markus Armbruster References: <1476859665-30133-1-git-send-email-caoj.fnst@cn.fujitsu.com> <1476859665-30133-11-git-send-email-caoj.fnst@cn.fujitsu.com> Date: Wed, 02 Nov 2016 13:37:26 +0100 In-Reply-To: <1476859665-30133-11-git-send-email-caoj.fnst@cn.fujitsu.com> (Cao jin's message of "Wed, 19 Oct 2016 14:47:45 +0800") Message-ID: <8737jaqcqh.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v4 10/10] msi_init: convert assert to return -errno List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cao jin Cc: qemu-devel@nongnu.org, Marcel Apfelbaum , Alex Williamson , "Michael S. Tsirkin" Cao jin writes: > According to the disscussion: > http://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg08215.html > > Let leaf function returns reasonable -errno, let caller decide how to > handle the return value. > > Suggested-by: Markus Armbruster > CC: Markus Armbruster > CC: Alex Williamson > CC: Michael S. Tsirkin > CC: Marcel Apfelbaum > Signed-off-by: Cao jin > --- > hw/pci/msi.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/hw/pci/msi.c b/hw/pci/msi.c > index a87b227..443682b 100644 > --- a/hw/pci/msi.c > +++ b/hw/pci/msi.c > @@ -201,9 +201,14 @@ int msi_init(struct PCIDevice *dev, uint8_t offset, > " 64bit %d mask %d\n", > offset, nr_vectors, msi64bit, msi_per_vector_mask); > > - assert(!(nr_vectors & (nr_vectors - 1))); /* power of 2 */ > - assert(nr_vectors > 0); > - assert(nr_vectors <= PCI_MSI_VECTORS_MAX); > + /* vector sanity test: should in range 1 - 32, should be power of 2 */ > + if ((nr_vectors == 0) || > + (nr_vectors > PCI_MSI_VECTORS_MAX) || > + (nr_vectors & (nr_vectors - 1))) { Suggest if (!is_power_of_2(nr_vectors) || nr_vectors > PCI_MSI_VECTORS_MAX) { > + error_setg(errp, "Invalid vector number: %d", nr_vectors); > + return -EINVAL; > + } > + > /* the nr of MSI vectors is up to 32 */ > vectors_order = ctz32(nr_vectors);