xserver: Cleaning up memory allocation functions and macros
Magnus Vigerlöf
Magnus.Vigerlof at home.se
Wed May 2 10:53:40 PDT 2007
On tisdag 01 maj 2007, Egbert Eich wrote:
> Magnus Vigerlöf writes:
> > Imo that's a lazy programmers argument. I can't think of any case where
> > crashing the Xserver with only an 'Out of memory' in the log will be a
> > meaningful error message for our end-users.
>
> Lazy programmer, yes.
> These should *never* be called in a running Xserver. I would consider
> them only useful at *startup( time when no clients are yet connected
> and for the unliekly case when there is no memory.
> If for example the driver wants to allocate memory for some internal
> structures but doesn't get it.
> In this case the programmer would just do:
> if (!(foo = (whatever *)xalloc(sizeof(whatever)))) {
> xf86DrvMsg(...,"Out of memory\n");
> return NULL;
> }
> and will continue for a while and may crash some point later when some
> code decides that there is no use to continue when no more memory is
> available at that time.
> if we do:
> foo = (whatever *)xnfalloc(sizeof(whatever));
> In this case we fail immediately.
>
> > If this have been an argument about an X-client I would probably not be
> > as bothered by this, as that would only affect that program. Annoying,
> > yes but that wouldn't kill all my other applications that I have
> > running, which would be the case we're talking about here.
>
> I think I mentioned that the use of xnfalloc() outside of initialization
> would be a *bad* abuse.
> - When you get an out of memory at initiaization there is probably no use
> continuing.
> - When you get an out of memory *after* initialization you need to be
> much more careful with what yo do.
Good, then we have the same view of xnf*. The thing I see is that more and
more devices are getting hot-pluggable. Input devices are next in queue, and
I'm just waiting for people wanting to use VGA-adapters connected via USB or
other hot-pluggable busses.
So the code where calling xnf* is not a problem is steadily decreasing and
making sure we then uses proper fault propagation instead of crashing will
hopefully avoid future headache and patches.
xf86AddDriver/xf86AddInputDriver are excellent examples of functions that
hasn't been a 'problem' but can be when hotplugging is working. They also
doesn't have a return value so we'll have to change these in order to get rid
of the xnf*-function calls..
Cheers
Magnus
More information about the xorg
mailing list