qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Mahmoud Mandour <ma.mandourr@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant
Date: Mon, 15 Mar 2021 07:10:04 +0100	[thread overview]
Message-ID: <dfa393ed-88ba-9c4b-e991-aeb9e73050a4@redhat.com> (raw)
In-Reply-To: <20210314032324.45142-6-ma.mandourr@gmail.com>

On 14/03/2021 04.23, Mahmoud Mandour wrote:
> Replaced a malloc() call and its respective free() call with
> GLib's g_try_malloc() and g_free().
> 
> Also, did slight styling changes that were producing
> style errors when using the checkpatch.pl script against
> the file.

If it's unrelated, then maybe better do it in a separate patch.

> Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
> ---
>   util/compatfd.c | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/util/compatfd.c b/util/compatfd.c
> index ee47dd8089..834ddd0573 100644
> --- a/util/compatfd.c
> +++ b/util/compatfd.c
> @@ -20,8 +20,7 @@
>   #include <sys/syscall.h>
>   #endif
>   
> -struct sigfd_compat_info
> -{
> +struct sigfd_compat_info {
>       sigset_t mask;
>       int fd;
>   };
> @@ -53,8 +52,9 @@ static void *sigwait_compat(void *opaque)
>   
>                   len = write(info->fd, (char *)&buffer + offset,
>                               sizeof(buffer) - offset);
> -                if (len == -1 && errno == EINTR)
> +                if (len == -1 && errno == EINTR) {
>                       continue;
> +                }
>   
>                   if (len <= 0) {
>                       return NULL;
> @@ -72,14 +72,14 @@ static int qemu_signalfd_compat(const sigset_t *mask)
>       QemuThread thread;
>       int fds[2];
>   
> -    info = malloc(sizeof(*info));
> +    info = g_try_malloc(sizeof(*info));
>       if (info == NULL) {
>           errno = ENOMEM;
>           return -1;
>       }

Since this is only a very small allocation, I think it would be better to 
use g_malloc() here and then simply remove the "if (info == NULL) ..." part.

  Thomas



  reply	other threads:[~2021-03-15  6:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-14  3:23 [PATCH 0/8] Replacing malloc and the like with GLib's variants Mahmoud Mandour
2021-03-14  3:23 ` [PATCH 1/8] bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants Mahmoud Mandour
2021-03-15 16:07   ` Alex Bennée
2021-03-15 16:22     ` Mahmoud Mandour
2021-03-15 17:56       ` Alex Bennée
2021-03-14  3:23 ` [PATCH 2/8] hw/audio/fmopl.c: Fixing some style errors Mahmoud Mandour
2021-03-14  3:23 ` [PATCH 3/8] hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants Mahmoud Mandour
2021-03-15 16:12   ` Alex Bennée
2021-03-15 17:35     ` Mahmoud Mandour
2021-03-14  3:23 ` [PATCH 4/8] target/xtensa: Replaced malloc/free " Mahmoud Mandour
2021-03-14 15:38   ` Max Filippov
2021-03-14  3:23 ` [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant Mahmoud Mandour
2021-03-15  6:10   ` Thomas Huth [this message]
2021-03-15  6:43     ` Mahmoud Mandour
2021-03-15  7:29       ` Thomas Huth
2021-03-15 16:15         ` Alex Bennée
2021-03-14  3:23 ` [PATCH 6/8] tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0 Mahmoud Mandour
2021-03-15  9:53   ` Stefan Hajnoczi
2021-05-25 19:01   ` Dr. David Alan Gilbert
2021-03-14  3:23 ` [PATCH 7/8] tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc Mahmoud Mandour
2021-03-15  9:54   ` Stefan Hajnoczi
2021-03-14  3:23 ` [PATCH 8/8] tools/virtiofsd: Replacing malloc-like calls with GLib's variants Mahmoud Mandour
2021-03-15 10:01   ` Stefan Hajnoczi
2021-03-15 10:46     ` Mahmoud Mandour
2021-03-16 17:23       ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dfa393ed-88ba-9c4b-e991-aeb9e73050a4@redhat.com \
    --to=thuth@redhat.com \
    --cc=ma.mandourr@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).