* [PATCH 0/2] util/compatfd.c: Fixed styling and replaced malloc @ 2021-03-15 10:58 Mahmoud Mandour 2021-03-15 10:58 ` [PATCH 1/2] util/compatfd.c: Fixed style issues Mahmoud Mandour 2021-03-15 10:58 ` [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc Mahmoud Mandour 0 siblings, 2 replies; 9+ messages in thread From: Mahmoud Mandour @ 2021-03-15 10:58 UTC (permalink / raw) To: qemu-devel; +Cc: Mahmoud Mandour In this small series, I fix two styling issues that were causing errors when the checkpatch.pl scritp was run against the file util/compatfd.c. Also, I replace a call to malloc() and its respective call to free() with GLib's allocation and deallocation. Used g_malloc() because the allocation is already small and its better if the system aborts on failure of such small allocations. Mahmoud Mandour (2): util/compatfd.c: Fixed style issues util/compatfd.c: Replaced a malloc call with g_malloc. util/compatfd.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) -- 2.25.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2] util/compatfd.c: Fixed style issues 2021-03-15 10:58 [PATCH 0/2] util/compatfd.c: Fixed styling and replaced malloc Mahmoud Mandour @ 2021-03-15 10:58 ` Mahmoud Mandour 2021-03-15 14:51 ` Thomas Huth 2021-03-15 10:58 ` [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc Mahmoud Mandour 1 sibling, 1 reply; 9+ messages in thread From: Mahmoud Mandour @ 2021-03-15 10:58 UTC (permalink / raw) To: qemu-devel; +Cc: Mahmoud Mandour Fixed two styling issues that caused checkpatch.pl errors. Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> --- util/compatfd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/compatfd.c b/util/compatfd.c index ee47dd8089..174f394533 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; -- 2.25.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] util/compatfd.c: Fixed style issues 2021-03-15 10:58 ` [PATCH 1/2] util/compatfd.c: Fixed style issues Mahmoud Mandour @ 2021-03-15 14:51 ` Thomas Huth 0 siblings, 0 replies; 9+ messages in thread From: Thomas Huth @ 2021-03-15 14:51 UTC (permalink / raw) To: Mahmoud Mandour, qemu-devel; +Cc: QEMU Trivial On 15/03/2021 11.58, Mahmoud Mandour wrote: > Fixed two styling issues that caused checkpatch.pl errors. > > Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> > --- > util/compatfd.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/util/compatfd.c b/util/compatfd.c > index ee47dd8089..174f394533 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; > Reviewed-by: Thomas Huth <thuth@redhat.com> ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc. 2021-03-15 10:58 [PATCH 0/2] util/compatfd.c: Fixed styling and replaced malloc Mahmoud Mandour 2021-03-15 10:58 ` [PATCH 1/2] util/compatfd.c: Fixed style issues Mahmoud Mandour @ 2021-03-15 10:58 ` Mahmoud Mandour 2021-03-15 11:13 ` Philippe Mathieu-Daudé 1 sibling, 1 reply; 9+ messages in thread From: Mahmoud Mandour @ 2021-03-15 10:58 UTC (permalink / raw) To: qemu-devel; +Cc: Mahmoud Mandour Replaced a call to malloc() and its respective call to free() with g_malloc() and g_free(). g_malloc() is preferred more than g_try_* functions, which return NULL on error, when the size of the requested allocation is small. This is because allocating few bytes should not be a problem in a healthy system. Otherwise, the system is already in a critical state. Subsequently, removed NULL-checking after g_malloc(). Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> --- util/compatfd.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/util/compatfd.c b/util/compatfd.c index 174f394533..a8ec525c6c 100644 --- a/util/compatfd.c +++ b/util/compatfd.c @@ -72,14 +72,10 @@ static int qemu_signalfd_compat(const sigset_t *mask) QemuThread thread; int fds[2]; - info = malloc(sizeof(*info)); - if (info == NULL) { - errno = ENOMEM; - return -1; - } + info = g_malloc(sizeof(*info)); if (pipe(fds) == -1) { - free(info); + g_free(info); return -1; } -- 2.25.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc. 2021-03-15 10:58 ` [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc Mahmoud Mandour @ 2021-03-15 11:13 ` Philippe Mathieu-Daudé 2021-03-15 11:30 ` Mahmoud Mandour 0 siblings, 1 reply; 9+ messages in thread From: Philippe Mathieu-Daudé @ 2021-03-15 11:13 UTC (permalink / raw) To: Mahmoud Mandour, qemu-devel Hi Mahmoud, On 3/15/21 11:58 AM, Mahmoud Mandour wrote: > Replaced a call to malloc() and its respective call to free() > with g_malloc() and g_free(). > > g_malloc() is preferred more than g_try_* functions, which > return NULL on error, when the size of the requested > allocation is small. This is because allocating few > bytes should not be a problem in a healthy system. > Otherwise, the system is already in a critical state. > > Subsequently, removed NULL-checking after g_malloc(). > > Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> > --- > util/compatfd.c | 8 ++------ > 1 file changed, 2 insertions(+), 6 deletions(-) > > diff --git a/util/compatfd.c b/util/compatfd.c > index 174f394533..a8ec525c6c 100644 > --- a/util/compatfd.c > +++ b/util/compatfd.c > @@ -72,14 +72,10 @@ static int qemu_signalfd_compat(const sigset_t *mask) > QemuThread thread; > int fds[2]; > > - info = malloc(sizeof(*info)); > - if (info == NULL) { > - errno = ENOMEM; > - return -1; > - } > + info = g_malloc(sizeof(*info)); Watch out... https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html If any call to allocate memory using functions g_new(), g_new0(), g_renew(), g_malloc(), g_malloc0(), g_malloc0_n(), g_realloc(), and g_realloc_n() fails, the application is terminated. So with your change instead of handling ENOMEM the QEMU process is simply killed. Don't you want to use g_try_new(struct sigfd_compat_info, 1) here instead? > > if (pipe(fds) == -1) { > - free(info); > + g_free(info); > return -1; > } > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc. 2021-03-15 11:13 ` Philippe Mathieu-Daudé @ 2021-03-15 11:30 ` Mahmoud Mandour 2021-03-15 14:25 ` Markus Armbruster 0 siblings, 1 reply; 9+ messages in thread From: Mahmoud Mandour @ 2021-03-15 11:30 UTC (permalink / raw) To: Philippe Mathieu-Daudé; +Cc: qemu-devel [-- Attachment #1: Type: text/plain, Size: 2531 bytes --] On Mon, Mar 15, 2021 at 1:13 PM Philippe Mathieu-Daudé <philmd@redhat.com> wrote: > Hi Mahmoud, > > On 3/15/21 11:58 AM, Mahmoud Mandour wrote: > > Replaced a call to malloc() and its respective call to free() > > with g_malloc() and g_free(). > > > > g_malloc() is preferred more than g_try_* functions, which > > return NULL on error, when the size of the requested > > allocation is small. This is because allocating few > > bytes should not be a problem in a healthy system. > > Otherwise, the system is already in a critical state. > > > > Subsequently, removed NULL-checking after g_malloc(). > > > > Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> > > --- > > util/compatfd.c | 8 ++------ > > 1 file changed, 2 insertions(+), 6 deletions(-) > > > > diff --git a/util/compatfd.c b/util/compatfd.c > > index 174f394533..a8ec525c6c 100644 > > --- a/util/compatfd.c > > +++ b/util/compatfd.c > > @@ -72,14 +72,10 @@ static int qemu_signalfd_compat(const sigset_t *mask) > > QemuThread thread; > > int fds[2]; > > > > - info = malloc(sizeof(*info)); > > - if (info == NULL) { > > - errno = ENOMEM; > > - return -1; > > - } > > + info = g_malloc(sizeof(*info)); > > Watch out... > > https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html > > If any call to allocate memory using functions g_new(), g_new0(), > g_renew(), g_malloc(), g_malloc0(), g_malloc0_n(), g_realloc(), > and g_realloc_n() fails, the application is terminated. > > So with your change instead of handling ENOMEM the QEMU process is > simply killed. > > Don't you want to use g_try_new(struct sigfd_compat_info, 1) here > instead? > > > > > if (pipe(fds) == -1) { > > - free(info); > > + g_free(info); > > return -1; > > } > > > > > > Hello Mr. Philippe, That's originally what I did and I sent a patch that uses a g_try_* variant, and was instructed by Mr. Thomas Huth that it was better to use g_malloc instead because this is a small allocation and the process is better killed if such an allocation fails because the system is already in a very critical state if it does not handle a small allocation well. You can find Mr. Thomas reply to my previous patch here: Re: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant (gnu.org) <https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg05067.html> You can instruct me on what to do further. Thanks Mahmoud [-- Attachment #2: Type: text/html, Size: 3496 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc. 2021-03-15 11:30 ` Mahmoud Mandour @ 2021-03-15 14:25 ` Markus Armbruster 2021-03-15 14:53 ` Thomas Huth 0 siblings, 1 reply; 9+ messages in thread From: Markus Armbruster @ 2021-03-15 14:25 UTC (permalink / raw) To: Mahmoud Mandour; +Cc: Thomas Huth, Philippe Mathieu-Daudé, qemu-devel Mahmoud, it's generally a good idea to cc: people who commented on a previous iteration of the same patch. In this case, Thomas. I'm doing that for you now. Mahmoud Mandour <ma.mandourr@gmail.com> writes: > On Mon, Mar 15, 2021 at 1:13 PM Philippe Mathieu-Daudé <philmd@redhat.com> > wrote: > >> Hi Mahmoud, >> >> On 3/15/21 11:58 AM, Mahmoud Mandour wrote: >> > Replaced a call to malloc() and its respective call to free() >> > with g_malloc() and g_free(). >> > >> > g_malloc() is preferred more than g_try_* functions, which >> > return NULL on error, when the size of the requested >> > allocation is small. This is because allocating few >> > bytes should not be a problem in a healthy system. >> > Otherwise, the system is already in a critical state. >> > >> > Subsequently, removed NULL-checking after g_malloc(). >> > >> > Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> >> > --- >> > util/compatfd.c | 8 ++------ >> > 1 file changed, 2 insertions(+), 6 deletions(-) >> > >> > diff --git a/util/compatfd.c b/util/compatfd.c >> > index 174f394533..a8ec525c6c 100644 >> > --- a/util/compatfd.c >> > +++ b/util/compatfd.c >> > @@ -72,14 +72,10 @@ static int qemu_signalfd_compat(const sigset_t *mask) >> > QemuThread thread; >> > int fds[2]; >> > >> > - info = malloc(sizeof(*info)); >> > - if (info == NULL) { >> > - errno = ENOMEM; >> > - return -1; >> > - } >> > + info = g_malloc(sizeof(*info)); >> >> Watch out... >> >> https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html >> >> If any call to allocate memory using functions g_new(), g_new0(), >> g_renew(), g_malloc(), g_malloc0(), g_malloc0_n(), g_realloc(), >> and g_realloc_n() fails, the application is terminated. >> >> So with your change instead of handling ENOMEM the QEMU process is >> simply killed. >> >> Don't you want to use g_try_new(struct sigfd_compat_info, 1) here >> instead? >> >> > >> > if (pipe(fds) == -1) { >> > - free(info); >> > + g_free(info); >> > return -1; >> > } >> > >> > >> >> > Hello Mr. Philippe, > > That's originally what I did and I sent a patch that uses a g_try_* > variant, and was > instructed by Mr. Thomas Huth that it was better to use g_malloc instead > because this is a small allocation and the process is better killed if such > an allocation fails because the system is already in a very critical state > if it does not handle a small allocation well. You even explained this in the commit message. Appreciated. > You can find Mr. Thomas reply to my previous patch here: > Re: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant > (gnu.org) > <https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg05067.html> > > You can instruct me on what to do further. I figure this patch is fine. Thomas? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc. 2021-03-15 14:25 ` Markus Armbruster @ 2021-03-15 14:53 ` Thomas Huth 2021-03-15 15:13 ` Philippe Mathieu-Daudé 0 siblings, 1 reply; 9+ messages in thread From: Thomas Huth @ 2021-03-15 14:53 UTC (permalink / raw) To: Markus Armbruster, Mahmoud Mandour Cc: QEMU Trivial, Philippe Mathieu-Daudé, qemu-devel On 15/03/2021 15.25, Markus Armbruster wrote: > Mahmoud, it's generally a good idea to cc: people who commented on a > previous iteration of the same patch. In this case, Thomas. I'm doing > that for you now. > > Mahmoud Mandour <ma.mandourr@gmail.com> writes: > >> On Mon, Mar 15, 2021 at 1:13 PM Philippe Mathieu-Daudé <philmd@redhat.com> >> wrote: >> >>> Hi Mahmoud, >>> >>> On 3/15/21 11:58 AM, Mahmoud Mandour wrote: >>>> Replaced a call to malloc() and its respective call to free() >>>> with g_malloc() and g_free(). >>>> >>>> g_malloc() is preferred more than g_try_* functions, which >>>> return NULL on error, when the size of the requested >>>> allocation is small. This is because allocating few >>>> bytes should not be a problem in a healthy system. >>>> Otherwise, the system is already in a critical state. >>>> >>>> Subsequently, removed NULL-checking after g_malloc(). >>>> >>>> Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> >>>> --- >>>> util/compatfd.c | 8 ++------ >>>> 1 file changed, 2 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/util/compatfd.c b/util/compatfd.c >>>> index 174f394533..a8ec525c6c 100644 >>>> --- a/util/compatfd.c >>>> +++ b/util/compatfd.c >>>> @@ -72,14 +72,10 @@ static int qemu_signalfd_compat(const sigset_t *mask) >>>> QemuThread thread; >>>> int fds[2]; >>>> >>>> - info = malloc(sizeof(*info)); >>>> - if (info == NULL) { >>>> - errno = ENOMEM; >>>> - return -1; >>>> - } >>>> + info = g_malloc(sizeof(*info)); >>> >>> Watch out... >>> >>> https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html >>> >>> If any call to allocate memory using functions g_new(), g_new0(), >>> g_renew(), g_malloc(), g_malloc0(), g_malloc0_n(), g_realloc(), >>> and g_realloc_n() fails, the application is terminated. >>> >>> So with your change instead of handling ENOMEM the QEMU process is >>> simply killed. >>> >>> Don't you want to use g_try_new(struct sigfd_compat_info, 1) here >>> instead? >>> >>>> >>>> if (pipe(fds) == -1) { >>>> - free(info); >>>> + g_free(info); >>>> return -1; >>>> } >>>> >>>> >>> >>> >> Hello Mr. Philippe, >> >> That's originally what I did and I sent a patch that uses a g_try_* >> variant, and was >> instructed by Mr. Thomas Huth that it was better to use g_malloc instead No need to say "Mr." here ... we're not that formal on this mailing list here :-) >> because this is a small allocation and the process is better killed if such >> an allocation fails because the system is already in a very critical state >> if it does not handle a small allocation well. > > You even explained this in the commit message. Appreciated. > >> You can find Mr. Thomas reply to my previous patch here: >> Re: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant >> (gnu.org) >> <https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg05067.html> >> >> You can instruct me on what to do further. > > I figure this patch is fine. Thomas? Yes, looks good now, thanks for the update, Mahmoud! Reviewed-by: Thomas Huth <thuth@redhat.com> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc. 2021-03-15 14:53 ` Thomas Huth @ 2021-03-15 15:13 ` Philippe Mathieu-Daudé 0 siblings, 0 replies; 9+ messages in thread From: Philippe Mathieu-Daudé @ 2021-03-15 15:13 UTC (permalink / raw) To: Thomas Huth, Markus Armbruster, Mahmoud Mandour; +Cc: QEMU Trivial, qemu-devel On 3/15/21 3:53 PM, Thomas Huth wrote: > On 15/03/2021 15.25, Markus Armbruster wrote: >> Mahmoud, it's generally a good idea to cc: people who commented on a >> previous iteration of the same patch. In this case, Thomas. I'm doing >> that for you now. >> >> Mahmoud Mandour <ma.mandourr@gmail.com> writes: >> >>> On Mon, Mar 15, 2021 at 1:13 PM Philippe Mathieu-Daudé >>> <philmd@redhat.com> >>> wrote: >>> >>>> Hi Mahmoud, >>>> >>>> On 3/15/21 11:58 AM, Mahmoud Mandour wrote: >>>>> Replaced a call to malloc() and its respective call to free() >>>>> with g_malloc() and g_free(). >>>>> >>>>> g_malloc() is preferred more than g_try_* functions, which >>>>> return NULL on error, when the size of the requested >>>>> allocation is small. This is because allocating few >>>>> bytes should not be a problem in a healthy system. >>>>> Otherwise, the system is already in a critical state. >>>>> >>>>> Subsequently, removed NULL-checking after g_malloc(). >>>>> >>>>> Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com> >>>>> --- >>>>> util/compatfd.c | 8 ++------ >>>>> 1 file changed, 2 insertions(+), 6 deletions(-) >>>>> >>>>> diff --git a/util/compatfd.c b/util/compatfd.c >>>>> index 174f394533..a8ec525c6c 100644 >>>>> --- a/util/compatfd.c >>>>> +++ b/util/compatfd.c >>>>> @@ -72,14 +72,10 @@ static int qemu_signalfd_compat(const sigset_t >>>>> *mask) >>>>> QemuThread thread; >>>>> int fds[2]; >>>>> >>>>> - info = malloc(sizeof(*info)); >>>>> - if (info == NULL) { >>>>> - errno = ENOMEM; >>>>> - return -1; >>>>> - } >>>>> + info = g_malloc(sizeof(*info)); >>>> >>>> Watch out... >>>> >>>> https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html >>>> >>>> If any call to allocate memory using functions g_new(), g_new0(), >>>> g_renew(), g_malloc(), g_malloc0(), g_malloc0_n(), g_realloc(), >>>> and g_realloc_n() fails, the application is terminated. >>>> >>>> So with your change instead of handling ENOMEM the QEMU process is >>>> simply killed. >>>> >>>> Don't you want to use g_try_new(struct sigfd_compat_info, 1) here >>>> instead? >>>> >>>>> >>>>> if (pipe(fds) == -1) { >>>>> - free(info); >>>>> + g_free(info); >>>>> return -1; >>>>> } >>>>> >>>>> >>>> >>>> >>> Hello Mr. Philippe, >>> >>> That's originally what I did and I sent a patch that uses a g_try_* >>> variant, and was >>> instructed by Mr. Thomas Huth that it was better to use g_malloc instead > > No need to say "Mr." here ... we're not that formal on this mailing list > here :-) > >>> because this is a small allocation and the process is better killed >>> if such >>> an allocation fails because the system is already in a very critical >>> state >>> if it does not handle a small allocation well. >> >> You even explained this in the commit message. Appreciated. >> >>> You can find Mr. Thomas reply to my previous patch here: >>> Re: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant >>> (gnu.org) >>> <https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg05067.html> >>> >>> You can instruct me on what to do further. >> >> I figure this patch is fine. Thomas? > > Yes, looks good now, thanks for the update, Mahmoud! I guess I misunderstood the patch description when :) ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-03-15 15:15 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-03-15 10:58 [PATCH 0/2] util/compatfd.c: Fixed styling and replaced malloc Mahmoud Mandour 2021-03-15 10:58 ` [PATCH 1/2] util/compatfd.c: Fixed style issues Mahmoud Mandour 2021-03-15 14:51 ` Thomas Huth 2021-03-15 10:58 ` [PATCH 2/2] util/compatfd.c: Replaced a malloc call with g_malloc Mahmoud Mandour 2021-03-15 11:13 ` Philippe Mathieu-Daudé 2021-03-15 11:30 ` Mahmoud Mandour 2021-03-15 14:25 ` Markus Armbruster 2021-03-15 14:53 ` Thomas Huth 2021-03-15 15:13 ` Philippe Mathieu-Daudé
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).