[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 10/10] msi_init: convert assert to return -errno
From: |
Cao jin |
Subject: |
[Qemu-devel] [PATCH v7 10/10] msi_init: convert assert to return -errno |
Date: |
Mon, 14 Nov 2016 15:25:40 +0800 |
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 <address@hidden>
CC: Markus Armbruster <address@hidden>
CC: Michael S. Tsirkin <address@hidden>
CC: Marcel Apfelbaum <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Reviewed-by: Marcel Apfelbaum <address@hidden>
Signed-off-by: Cao jin <address@hidden>
---
hw/pci/msi.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/hw/pci/msi.c b/hw/pci/msi.c
index a87b227..af3efbe 100644
--- a/hw/pci/msi.c
+++ b/hw/pci/msi.c
@@ -201,9 +201,12 @@ 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 (!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);
--
2.1.0
- [Qemu-devel] [PATCH v7 00/10] Convert msix_init() to error, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 01/10] msix: Follow CODING_STYLE, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 02/10] hcd-xhci: check & correct param before using it, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 06/10] megasas: remove unnecessary megasas_use_msix(), Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 04/10] megasas: change behaviour of msix switch, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 10/10] msi_init: convert assert to return -errno,
Cao jin <=
- [Qemu-devel] [PATCH v7 07/10] megasas: undo the overwrites of msi user configuration, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 09/10] vmxnet3: remove unnecessary internal msix flag, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 05/10] hcd-xhci: change behaviour of msix switch, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 03/10] pci: Convert msix_init() to Error and fix callers to check it, Cao jin, 2016/11/14
- [Qemu-devel] [PATCH v7 08/10] vmxnet3: fix reference leak issue, Cao jin, 2016/11/14
- Re: [Qemu-devel] [PATCH v7 00/10] Convert msix_init() to error, Michael S. Tsirkin, 2016/11/14