diff mbox

fix qemu_get_cpu(), should return NULL if CPU not found

Message ID 1362679963-23201-1-git-send-email-imammedo@redhat.com
State New
Headers show

Commit Message

Igor Mammedov March 7, 2013, 6:12 p.m. UTC
commit 55e5c2850 breaks CPU not found return value, and returns
CPU corresponding to the last non NULL env.
Fix it by returning CPU only if env is not NULL, otherwise CPU is
not found and function should return NULL.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Färber March 12, 2013, 9:42 a.m. UTC | #1
Am 07.03.2013 19:12, schrieb Igor Mammedov:
> commit 55e5c2850 breaks CPU not found return value, and returns
> CPU corresponding to the last non NULL env.
> Fix it by returning CPU only if env is not NULL, otherwise CPU is
> not found and function should return NULL.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>

D'oh, that was exactly the problem in ppc code I tried to fix by using
this function! ;-)

Thanks, applied to qom-cpu (with modified commit message):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Pull coming up.

Andreas

> ---
>  exec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/exec.c b/exec.c
> index 46a2830..0a96ddb 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -260,7 +260,7 @@ CPUState *qemu_get_cpu(int index)
>          env = env->next_cpu;
>      }
>  
> -    return cpu;
> +    return env ? cpu : NULL;
>  }
>  
>  void cpu_exec_init(CPUArchState *env)
>
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 46a2830..0a96ddb 100644
--- a/exec.c
+++ b/exec.c
@@ -260,7 +260,7 @@  CPUState *qemu_get_cpu(int index)
         env = env->next_cpu;
     }
 
-    return cpu;
+    return env ? cpu : NULL;
 }
 
 void cpu_exec_init(CPUArchState *env)