diff mbox series

[v1,kvmtool,1/7] arm/gicv2m: Set errno when gicv2_update_routing() fails

Message ID 20210913154413.14322-2-alexandru.elisei@arm.com (mailing list archive)
State New, archived
Headers show
Series vfio/pci: Fix MSIX table and PBA size allocation | expand

Commit Message

Alexandru Elisei Sept. 13, 2021, 3:44 p.m. UTC
In case of an error when updating the routing table entries,
irq__update_msix_route() uses perror to print an error message.
gicv2m_update_routing() doesn't set errno, and instead returns the value
that errno should have had, which can lead to failure messages like this:

KVM_SET_GSI_ROUTING: Success

Set errno in gicv2m_update_routing() to avoid such messages in the future.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/gicv2m.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Andre Przywara Oct. 6, 2021, 3:08 p.m. UTC | #1
On Mon, 13 Sep 2021 16:44:07 +0100
Alexandru Elisei <alexandru.elisei@arm.com> wrote:

> In case of an error when updating the routing table entries,
> irq__update_msix_route() uses perror to print an error message.
> gicv2m_update_routing() doesn't set errno, and instead returns the value
> that errno should have had, which can lead to failure messages like this:
> 
> KVM_SET_GSI_ROUTING: Success
> 
> Set errno in gicv2m_update_routing() to avoid such messages in the future.

Fair enough, the usage of errno in the error reporting path is not really
consistent in kvmtool, but as we also keep the return value, that's
alright:

> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
>  arm/gicv2m.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/arm/gicv2m.c b/arm/gicv2m.c
> index d7e6398..b47ada8 100644
> --- a/arm/gicv2m.c
> +++ b/arm/gicv2m.c
> @@ -42,16 +42,18 @@ static int gicv2m_update_routing(struct kvm *kvm,
>  {
>  	int spi;
>  
> -	if (entry->type != KVM_IRQ_ROUTING_MSI)
> -		return -EINVAL;
> +	if (entry->type != KVM_IRQ_ROUTING_MSI) {
> +		errno = EINVAL;
> +		return -errno;
> +	}
>  
>  	if (!entry->u.msi.address_hi && !entry->u.msi.address_lo)
>  		return 0;
>  
>  	spi = entry->u.msi.data & GICV2M_SPI_MASK;
>  	if (spi < v2m.first_spi || spi >= v2m.first_spi + v2m.num_spis) {
> -		pr_err("invalid SPI number %d", spi);
> -		return -EINVAL;
> +		errno = EINVAL;
> +		return -errno;
>  	}
>  
>  	v2m.spis[spi - v2m.first_spi] = entry->gsi;
diff mbox series

Patch

diff --git a/arm/gicv2m.c b/arm/gicv2m.c
index d7e6398..b47ada8 100644
--- a/arm/gicv2m.c
+++ b/arm/gicv2m.c
@@ -42,16 +42,18 @@  static int gicv2m_update_routing(struct kvm *kvm,
 {
 	int spi;
 
-	if (entry->type != KVM_IRQ_ROUTING_MSI)
-		return -EINVAL;
+	if (entry->type != KVM_IRQ_ROUTING_MSI) {
+		errno = EINVAL;
+		return -errno;
+	}
 
 	if (!entry->u.msi.address_hi && !entry->u.msi.address_lo)
 		return 0;
 
 	spi = entry->u.msi.data & GICV2M_SPI_MASK;
 	if (spi < v2m.first_spi || spi >= v2m.first_spi + v2m.num_spis) {
-		pr_err("invalid SPI number %d", spi);
-		return -EINVAL;
+		errno = EINVAL;
+		return -errno;
 	}
 
 	v2m.spis[spi - v2m.first_spi] = entry->gsi;