diff mbox

[v5,10/10] msi_init: convert assert to return -errno

Message ID 1478145997-28865-11-git-send-email-caoj.fnst@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Cao jin Nov. 3, 2016, 4:06 a.m. UTC
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 <armbru@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
CC: Michael S. Tsirkin <mst@redhat.com>
CC: Marcel Apfelbaum <marcel@redhat.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
---
 hw/pci/msi.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Cao jin Nov. 3, 2016, 6:16 a.m. UTC | #1
Please ignore this one, I forget to commit the amendment...
Already send the right one.

Cao jin

On 11/03/2016 12:06 PM, Cao jin wrote:
> 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 <armbru@redhat.com>
> CC: Markus Armbruster <armbru@redhat.com>
> CC: Michael S. Tsirkin <mst@redhat.com>
> CC: Marcel Apfelbaum <marcel@redhat.com>
>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
> ---
>   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))) {
> +        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);
>
>
diff mbox

Patch

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))) {
+        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);