Re: RFC: snd_card_create() function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At Mon, 12 Jan 2009 17:08:28 +0100,
Krzysztof Helt wrote:
> 
> On Mon, 12 Jan 2009 15:35:19 +0100
> Takashi Iwai <tiwai@xxxxxxx> 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
unchanged.

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


Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux