[alsa-devel] RFC: snd_card_create() function

Takashi Iwai tiwai at suse.de
Mon Jan 12 17:12:54 CET 2009

At Mon, 12 Jan 2009 17:08:28 +0100,
Krzysztof Helt wrote:
> On Mon, 12 Jan 2009 15:35:19 +0100
> Takashi Iwai <tiwai at suse.de> wrote:
> > Hi,
> > 
> > so far, we use snd_card_new() function to create a card instance.
> > A known problem regarding this API is that it doesn't return a proper
> > error code, thus the probe callback always returns -ENOMEM (or
> > whatever the driver defines) no matter which error occurred actually.
> > A typical case is the card slot conflict.  Even in such a case, it
> > returns -ENOMEM, which may mislead the user.
> Another approach is PTR_ERR macro used already in the kernel
> (see include/linux/err.h).
> It encodes the error code in the returned pointer value. There
> are already hndy macros/inlines to get this code, test error, etc.

Yep.  However, as I mentioned in the paragraph after the text above,
it gives you little advantage in this case.

If an error occurs, the new function returns a non-NULL value.  Since
the old caller side does only a NULL-check, it would accept the error
pointer as is, ended up an Oops.

More badly, this old-style return-value check can't be detected at the
compile time because the API (at least the function calling) is

So, PTR_ERR() is nice to be introduced at the first place but pretty
bad as a transition from a NULL/non-NULL API.


More information about the Alsa-devel mailing list