All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] sparc: Use g_memdup() instead of g_new0() + memcpy()
@ 2016-06-16 17:33 Thomas Huth
  2016-06-17 11:38 ` Artyom Tarasenko
  2016-07-26 12:32 ` Michael Tokarev
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Huth @ 2016-06-16 17:33 UTC (permalink / raw)
  To: qemu-devel, Mark Cave-Ayland; +Cc: Blue Swirl, Artyom Tarasenko, qemu-trivial

There is no need to make sure that the memory is zeroed after the
allocation if we also immediatly fill the whole buffer afterwards
with memcpy(). Thus g_new0 should be g_new instead. But since we
are also doing a memcpy() here, we can also simply replace both
with g_memdup() instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 target-sparc/cpu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c
index 5b74cfc..7b43192 100644
--- a/target-sparc/cpu.c
+++ b/target-sparc/cpu.c
@@ -115,8 +115,7 @@ static int cpu_sparc_register(SPARCCPU *cpu, const char *cpu_model)
         return -1;
     }
 
-    env->def = g_new0(sparc_def_t, 1);
-    memcpy(env->def, def, sizeof(*def));
+    env->def = g_memdup(def, sizeof(*def));
 
     featurestr = strtok(NULL, ",");
     cc->parse_features(CPU(cpu), featurestr, &err);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] sparc: Use g_memdup() instead of g_new0() + memcpy()
  2016-06-16 17:33 [Qemu-devel] [PATCH] sparc: Use g_memdup() instead of g_new0() + memcpy() Thomas Huth
@ 2016-06-17 11:38 ` Artyom Tarasenko
  2016-07-26 12:32 ` Michael Tokarev
  1 sibling, 0 replies; 3+ messages in thread
From: Artyom Tarasenko @ 2016-06-17 11:38 UTC (permalink / raw)
  To: Thomas Huth; +Cc: qemu-devel, Mark Cave-Ayland, Blue Swirl, qemu-trivial

Acked-By: Artyom Tarasenko <atar4qemu@gmail.com>

On Thu, Jun 16, 2016 at 7:33 PM, Thomas Huth <thuth@redhat.com> wrote:
> There is no need to make sure that the memory is zeroed after the
> allocation if we also immediatly fill the whole buffer afterwards
> with memcpy(). Thus g_new0 should be g_new instead. But since we
> are also doing a memcpy() here, we can also simply replace both
> with g_memdup() instead.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  target-sparc/cpu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c
> index 5b74cfc..7b43192 100644
> --- a/target-sparc/cpu.c
> +++ b/target-sparc/cpu.c
> @@ -115,8 +115,7 @@ static int cpu_sparc_register(SPARCCPU *cpu, const char *cpu_model)
>          return -1;
>      }
>
> -    env->def = g_new0(sparc_def_t, 1);
> -    memcpy(env->def, def, sizeof(*def));
> +    env->def = g_memdup(def, sizeof(*def));
>
>      featurestr = strtok(NULL, ",");
>      cc->parse_features(CPU(cpu), featurestr, &err);
> --
> 1.8.3.1
>



-- 
Regards,
Artyom Tarasenko

SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] sparc: Use g_memdup() instead of g_new0() + memcpy()
  2016-06-16 17:33 [Qemu-devel] [PATCH] sparc: Use g_memdup() instead of g_new0() + memcpy() Thomas Huth
  2016-06-17 11:38 ` Artyom Tarasenko
@ 2016-07-26 12:32 ` Michael Tokarev
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Tokarev @ 2016-07-26 12:32 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Mark Cave-Ayland
  Cc: Blue Swirl, qemu-trivial, Artyom Tarasenko

16.06.2016 20:33, Thomas Huth wrote:
> There is no need to make sure that the memory is zeroed after the
> allocation if we also immediatly fill the whole buffer afterwards
> with memcpy(). Thus g_new0 should be g_new instead. But since we
> are also doing a memcpy() here, we can also simply replace both
> with g_memdup() instead.

Applied to -trivial, thanks!

/mjt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-26 12:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-16 17:33 [Qemu-devel] [PATCH] sparc: Use g_memdup() instead of g_new0() + memcpy() Thomas Huth
2016-06-17 11:38 ` Artyom Tarasenko
2016-07-26 12:32 ` Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.