[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc.
From: |
Peter Maydell |
Subject: |
Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc. |
Date: |
Fri, 28 Jul 2023 10:35:16 +0100 |
On Fri, 28 Jul 2023 at 06:13, dinglimin <dinglimin@cmss.chinamobile.com> wrote:
>
> Replaced a call to malloc() and its respective call to free() with g_malloc()
> and g_free().
>
> Signed-off-by: dinglimin <dinglimin@cmss.chinamobile.com>
>
> v4 -> V5:Use g_try_malloc() instead of malloc()
> V3 -> V4:Delete null checks after g malloc().
> V2 -> V3:softmmu_unlock_user changes free to g free.
> V1 -> V2:if cpu_memory_rw_debug failed, still need to set p=NULL
>
> Signed-off-by: dinglimin <dinglimin@cmss.chinamobile.com>
> ---
> semihosting/uaccess.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c
> index 8018828069..35fdcd69db 100644
> --- a/semihosting/uaccess.c
> +++ b/semihosting/uaccess.c
> @@ -14,13 +14,20 @@
> void *softmmu_lock_user(CPUArchState *env, target_ulong addr,
> target_ulong len, bool copy)
> {
> - void *p = malloc(len);
> - if (p && copy) {
> + void *p = g_try_malloc(len);
> +
> + if (!p) {
> + p = NULL;
This doesn't make sense -- if (!p) means p is already NULL,
so you don't need to set it to NULL.
> + return p;
> + }
This patch should just replace malloc() with
g_try_malloc() and free() with g_free(). You don't need to
change any of the rest of the logic in the function.
> +
> + if (copy) {
> if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) {
> - free(p);
> + g_free(p);
> p = NULL;
> }
> }
> +
> return p;
> }
>
> @@ -87,5 +94,5 @@ void softmmu_unlock_user(CPUArchState *env, void *p,
> if (len) {
> cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1);
> }
> - free(p);
> + g_free(p);
> }
> --
> 2.30.0.windows.2
thanks
-- PMM
- [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., (continued)
- [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., dinglimin, 2023/07/25
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Michael Tokarev, 2023/07/25
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Peter Maydell, 2023/07/25
- 回复: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., dinglimin, 2023/07/26
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Peter Maydell, 2023/07/26
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Richard Henderson, 2023/07/26
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Peter Maydell, 2023/07/27
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Daniel P . Berrangé, 2023/07/27
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Richard Henderson, 2023/07/27
- [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., dinglimin, 2023/07/28
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc.,
Peter Maydell <=
- [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., dinglimin, 2023/07/28
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Peter Maydell, 2023/07/28
- Re: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., Peter Maydell, 2023/07/28
- [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., dinglimin, 2023/07/26
[PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc., dinglimin, 2023/07/25