qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: jcd@tribudubois.net
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Fri, 29 May 2009 13:00:42 +0100 (GMT+01:00)	[thread overview]
Message-ID: <9974029.69061243598442059.JavaMail.root@srv-05.w4a.fr> (raw)
In-Reply-To: <2171027.69001243598252547.JavaMail.root@srv-05.w4a.fr>


----- "Kevin Wolf" <kwolf@redhat.com> a écrit :

> jcd@tribudubois.net schrieb:
> > Kevin,
> > 
> > I certainly understand your goal ... 
> > 
> > Anyway, I will update my patche and resubmit.
> > 
> > BTW it has to be noted that most of the time the return value of
> malloc/qemu_malloc is not checked which can also prove problematic
> whatever the qemu_malloc/malloc behavior is.
> 
> It doesn't need to be checked, qemu_malloc never returns if it fails.
> If
> malloc(0) returns NULL (on success!) checking it is even wrong in
> places
> where this can happen.

I don't necessarily speak about the malloc(0) case.

Up to now the qemu_io code (for example) was using malloc() without checking for the returned value. If allocation fails, I believe it would be quite wrong to pass the returned (NULL) pointer to memcpy/memset/memcmp whatever platform you are considering ...

So it seems to me you definitively need a way to dicriminate between the value returned on succesfull malloc(0) and the value returned on a failed malloc(1000).

So now, back to the malloc(0) case.

Granted, it would be important to have a standard behavior of malloc() on all platforms to be able to check for failure. And malloc(0) returning NULL on success (on some plateform) is not very compatible with other malloc() failure schemes. 

qemu_malloc is a nice place to unify all the malloc() behavior. Now it just has to be decided for the "qemu platform" if we allow the malloc(0) usage. 
- If yes, we have to allow it for all platforms in qemu_alloc() [using malloc(1) under the cover for example] returning a valid/non NULL pointer for all underlying platforms (even the ones that were returning NULL on success).
- If not, we can just abort() to catch these case early as it is proposed.

It seems to be just a fact that all malloc implementation are not compatible in their behavior. None of these implementations are necessarily wrong, but we just need to decide what is the allowed behavior for the qemu "platform" and then make sure that the qemu_malloc() implemetation is consistent on all underlying platforms.

> 
> Kevin

       reply	other threads:[~2009-05-29 12:03 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2171027.69001243598252547.JavaMail.root@srv-05.w4a.fr>
2009-05-29 12:00 ` jcd [this message]
2009-05-29 12:05   ` [Qemu-devel] [PATCH] use qemu_malloc and friends consistently Kevin Wolf
2009-05-29 12:13     ` jcd
2009-05-29 12:32   ` Markus Armbruster
2009-05-29 12:38     ` jcd
     [not found] <1758936.71791243858884274.JavaMail.root@srv-05.w4a.fr>
2009-06-01 12:24 ` jcd
2009-06-01 23:46   ` Jamie Lokier
     [not found] <33383337.69831243610071896.JavaMail.root@srv-05.w4a.fr>
2009-05-29 15:15 ` jcd
     [not found] <28912134.69441243608238156.JavaMail.root@srv-05.w4a.fr>
2009-05-29 14:46 ` jcd
     [not found] <28932640.69341243603994530.JavaMail.root@srv-05.w4a.fr>
2009-05-29 13:35 ` jcd
     [not found] <18212122.68761243590277678.JavaMail.root@srv-05.w4a.fr>
2009-05-29 10:00 ` jcd
2009-05-29 10:10   ` Kevin Wolf
2009-05-29  5:58 Jean-Christophe Dubois
2009-05-29  8:42 ` Kevin Wolf
2009-05-29  9:05   ` Anthony Liguori
2009-05-29  9:51     ` malc
2009-05-29 10:05       ` Kevin Wolf
2009-05-29 10:23         ` malc
2009-05-29 10:34           ` Kevin Wolf
2009-05-29 10:40             ` malc
2009-05-29 10:49               ` Kevin Wolf
2009-05-29 10:56                 ` Anthony Liguori
2009-05-29 11:06                 ` malc
2009-05-29 11:14                   ` Kevin Wolf
2009-05-29 10:53       ` Anthony Liguori
2009-05-29 11:24         ` malc
2009-05-29 12:36           ` Gerd Hoffmann
2009-05-29 13:07             ` Paul Brook
2009-05-29 13:46               ` Gerd Hoffmann
2009-05-29 13:59               ` Glauber Costa
2009-05-29 14:34               ` Anthony Liguori
2009-05-29 15:06                 ` malc
2009-05-29 17:17               ` Julian Seward
2009-05-29 18:41                 ` Gerd Hoffmann
2009-05-29 21:12                 ` David Turner
2009-05-29 21:13                   ` David Turner
2009-06-02  7:26                   ` Gerd Hoffmann
2009-06-02  7:47                     ` Anthony Liguori
2009-06-02  8:58                       ` Daniel P. Berrange
2009-06-02 18:03                         ` David Turner
2009-06-02  8:48                     ` Avi Kivity
2009-06-02 18:02                     ` David Turner
2009-06-02 18:13                       ` Paul Brook
2009-06-02 19:49                         ` David Turner
2009-06-02 20:04                           ` Paul Brook
2009-06-02 20:42                             ` David Turner
2009-06-02 20:45                               ` Gerd Hoffmann
2009-06-02 20:48                               ` Gerd Hoffmann
2009-06-02 20:58                               ` Paul Brook
2009-06-02 21:19                                 ` David Turner
2009-06-02 19:03                       ` Avi Kivity
2009-05-29 12:51           ` Markus Armbruster
2009-05-29 10:57       ` Gerd Hoffmann
2009-05-29 11:28         ` malc
2009-05-29  9:28   ` jcd
2009-05-29  9:38     ` Kevin Wolf
2009-06-01 11:59     ` Jamie Lokier

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=9974029.69061243598442059.JavaMail.root@srv-05.w4a.fr \
    --to=jcd@tribudubois.net \
    --cc=kwolf@redhat.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).