diff mbox

[03/11] KVM: ARM/arm64: avoid returning negative error code as bool

Message ID 1409062410-25891-4-git-send-email-will.deacon@arm.com
State Superseded
Headers show

Commit Message

Will Deacon Aug. 26, 2014, 2:13 p.m. UTC
is_valid_cache returns true if the specified cache is valid.
Unfortunately, if the parameter passed it out of range, we return
-ENOENT, which ends up as true leading to potential hilarity.

This patch returns false on the failure path instead.

Cc: Christoffer Dall <christoffer.dall@linaro.org>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm/kvm/coproc.c     | 2 +-
 arch/arm64/kvm/sys_regs.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Marc Zyngier Aug. 26, 2014, 2:22 p.m. UTC | #1
On 26/08/14 15:13, Will Deacon wrote:
> is_valid_cache returns true if the specified cache is valid.
> Unfortunately, if the parameter passed it out of range, we return
> -ENOENT, which ends up as true leading to potential hilarity.
> 
> This patch returns false on the failure path instead.
> 
> Cc: Christoffer Dall <christoffer.dall@linaro.org>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Signed-off-by: Will Deacon <will.deacon@arm.com>

With a brown paper bag on:

Acked-by: Marc Zyngier <marc.zyngier@arm.com>

	M.

> ---
>  arch/arm/kvm/coproc.c     | 2 +-
>  arch/arm64/kvm/sys_regs.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
> index 37a0fe1bb9bb..7928dbdf2102 100644
> --- a/arch/arm/kvm/coproc.c
> +++ b/arch/arm/kvm/coproc.c
> @@ -791,7 +791,7 @@ static bool is_valid_cache(u32 val)
>  	u32 level, ctype;
>  
>  	if (val >= CSSELR_MAX)
> -		return -ENOENT;
> +		return false;
>  
>  	/* Bottom bit is Instruction or Data bit.  Next 3 bits are level. */
>          level = (val >> 1);
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 5805e7c4a4dd..4cc3b719208e 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -1218,7 +1218,7 @@ static bool is_valid_cache(u32 val)
>  	u32 level, ctype;
>  
>  	if (val >= CSSELR_MAX)
> -		return -ENOENT;
> +		return false;
>  
>  	/* Bottom bit is Instruction or Data bit.  Next 3 bits are level. */
>  	level = (val >> 1);
>
Christoffer Dall Aug. 26, 2014, 2:49 p.m. UTC | #2
On Tue, Aug 26, 2014 at 03:13:22PM +0100, Will Deacon wrote:
> is_valid_cache returns true if the specified cache is valid.
> Unfortunately, if the parameter passed it out of range, we return
> -ENOENT, which ends up as true leading to potential hilarity.
> 
> This patch returns false on the failure path instead.
> 
> Cc: Christoffer Dall <christoffer.dall@linaro.org>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Signed-off-by: Will Deacon <will.deacon@arm.com>

nice one!

Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
diff mbox

Patch

diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c
index 37a0fe1bb9bb..7928dbdf2102 100644
--- a/arch/arm/kvm/coproc.c
+++ b/arch/arm/kvm/coproc.c
@@ -791,7 +791,7 @@  static bool is_valid_cache(u32 val)
 	u32 level, ctype;
 
 	if (val >= CSSELR_MAX)
-		return -ENOENT;
+		return false;
 
 	/* Bottom bit is Instruction or Data bit.  Next 3 bits are level. */
         level = (val >> 1);
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 5805e7c4a4dd..4cc3b719208e 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1218,7 +1218,7 @@  static bool is_valid_cache(u32 val)
 	u32 level, ctype;
 
 	if (val >= CSSELR_MAX)
-		return -ENOENT;
+		return false;
 
 	/* Bottom bit is Instruction or Data bit.  Next 3 bits are level. */
 	level = (val >> 1);