diff mbox series

[2/2] cpu: Assert asidx_from_attrs return value in range

Message ID 20180630000242.29594-3-richard.henderson@linaro.org
State Superseded
Headers show
Series Fix qemu-system-aarch64 crash | expand

Commit Message

Richard Henderson June 30, 2018, 12:02 a.m. UTC
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 include/qom/cpu.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
2.17.1

Comments

Peter Maydell July 2, 2018, 2:16 p.m. UTC | #1
On 30 June 2018 at 01:02, Richard Henderson
<richard.henderson@linaro.org> wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>  include/qom/cpu.h | 6 ++++--

>  1 file changed, 4 insertions(+), 2 deletions(-)

>

> diff --git a/include/qom/cpu.h b/include/qom/cpu.h

> index cce2fd6acc..bd796579ee 100644

> --- a/include/qom/cpu.h

> +++ b/include/qom/cpu.h

> @@ -620,11 +620,13 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)

>  static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)

>  {

>      CPUClass *cc = CPU_GET_CLASS(cpu);

> +    int ret = 0;

>

>      if (cc->asidx_from_attrs) {

> -        return cc->asidx_from_attrs(cpu, attrs);

> +        ret = cc->asidx_from_attrs(cpu, attrs);

> +        assert(ret < cpu->num_ases && ret >= 0);

>      }

> -    return 0;

> +    return ret;

>  }

>  #endif

>


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>


thanks
-- PMM
diff mbox series

Patch

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index cce2fd6acc..bd796579ee 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -620,11 +620,13 @@  static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
+    int ret = 0;
 
     if (cc->asidx_from_attrs) {
-        return cc->asidx_from_attrs(cpu, attrs);
+        ret = cc->asidx_from_attrs(cpu, attrs);
+        assert(ret < cpu->num_ases && ret >= 0);
     }
-    return 0;
+    return ret;
 }
 #endif