From: Takashi Iwai Subject: Re: RFC: snd_card_create() function Date: Mon, 12 Jan 2009 17:12:54 +0100 Message-ID: References: <20090112170828.50154e1f.krzysztof.h1@poczta.fm> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.suse.de (ns.suse.de [195.135.220.2]) by alsa0.perex.cz (Postfix) with ESMTP id 2EA991037EF for ; Mon, 12 Jan 2009 17:12:55 +0100 (CET) In-Reply-To: <20090112170828.50154e1f.krzysztof.h1@poczta.fm> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: Krzysztof Helt Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Mon, 12 Jan 2009 17:08:28 +0100, Krzysztof Helt wrote: > > On Mon, 12 Jan 2009 15:35:19 +0100 > Takashi Iwai 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