Skip to contentSkip to conversation

RFC: snd_card_create() function

DISCUSSION Takashi Iwai 4 participants 10 messages Jan 12, 2009 – Jan 15, 2009

lore
Share & tools
lore
#0 lore raw

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.

For fixing this situation, I'd like to convert from snd_card_new() to a new function, snd_card_create():

int snd_card_create(int idx, const char *id,

		    struct module *module, int extra_size,
		    struct snd_card **card_ret);

and provides snd_card_new() as a wrapper with deprecated flag:

static inline __deprecated
struct snd_card *snd_card_new(int idx, const char *id,
struct module *module, int extra_size)

{
	struct snd_card *card;
	if (snd_card_create(idx, id, module, extra_size, &card) < 0)
		return NULL;
	return card;
}

The merit of creating a new function is that the older and out-of-tree codes (like xfi) work without modification. There is alternative option, namely to use PTR_ERR() and keep the function as is. But this has no advantage in practice -- it can't detect the old API at build time, and it may Oops.

The preliminary patches are found in test/snd_card_new-err branch
of sound git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git test/snd_card_new-err

If anyone finds problems with this, please let me know.

thanks,

Takashi

#1 lore raw

Sounds good to me.
One can keep the wrapper outside of the kernel, and only available in alsa-driver for those out of tree people.

Kind Regards

James

2009/1/12 Takashi Iwai <[email protected]>:

Quoted 49 lines

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.

For fixing this situation, I'd like to convert from snd_card_new() to a new function, snd_card_create():

int snd_card_create(int idx, const char *id,
struct module *module, int extra_size, struct snd_card **card_ret);

and provides snd_card_new() as a wrapper with deprecated flag:

static inline __deprecated
struct snd_card *snd_card_new(int idx, const char *id,
struct module *module, int extra_size)

{
       struct snd_card *card;
       if (snd_card_create(idx, id, module, extra_size, &card) < 0)
               return NULL;
       return card;
}

The merit of creating a new function is that the older and out-of-tree codes (like xfi) work without modification. There is alternative option, namely to use PTR_ERR() and keep the function as is. But this has no advantage in practice -- it can't detect the old API at build time, and it may Oops.

The preliminary patches are found in test/snd_card_new-err branch
of sound git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git test/snd_card_new-err

If anyone finds problems with this, please let me know.

thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw

At Mon, 12 Jan 2009 14:42:06 +0000,

Quoted 4 lines · James Courtier-Dutton

Sounds good to me.
One can keep the wrapper outside of the kernel, and only available in alsa-driver for those out of tree people.

Yes, that's good.
I think it'd be better to do that after one kernel-cycle later for a softer landing, though.

thanks,

Takashi

Quoted 58 lines

Kind Regards

James

2009/1/12 Takashi Iwai <[email protected]>:

Quoted 49 lines

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.

For fixing this situation, I'd like to convert from snd_card_new() to a new function, snd_card_create():

int snd_card_create(int idx, const char *id,
struct module *module, int extra_size, struct snd_card **card_ret);

and provides snd_card_new() as a wrapper with deprecated flag:

static inline __deprecated
struct snd_card *snd_card_new(int idx, const char *id,
struct module *module, int extra_size)

{
       struct snd_card *card;
       if (snd_card_create(idx, id, module, extra_size, &card) < 0)
               return NULL;
       return card;
}

The merit of creating a new function is that the older and out-of-tree codes (like xfi) work without modification. There is alternative option, namely to use PTR_ERR() and keep the function as is. But this has no advantage in practice -- it can't detect the old API at build time, and it may Oops.

The preliminary patches are found in test/snd_card_new-err branch
of sound git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git test/snd_card_new-err

If anyone finds problems with this, please let me know.

thanks,

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw

2009/1/12 Takashi Iwai <[email protected]>:

Quoted 11 lines

At Mon, 12 Jan 2009 14:42:06 +0000,

Quoted 4 lines · James Courtier-Dutton

Sounds good to me.
One can keep the wrapper outside of the kernel, and only available in alsa-driver for those out of tree people.

Yes, that's good.
I think it'd be better to do that after one kernel-cycle later for a softer landing, though.

How soft do we need this?
The change is probably max of 3 lines of code per sound card that has an out of tree driver.
The only one I am aware of is the xfi one. With the wrapper being more than 3 lines of code being put into the kernel only to be removed again seems a little un-necessary to me.
For internal kernel changes, I don't think we should care about out of kernel drivers. None of the rest of the kernel developers go out of their way for anything out-of-mainline.

Kind Regards

James

#4 lore raw

At Mon, 12 Jan 2009 15:06:51 +0000,

Quoted 9 lines · James Courtier-Dutton

2009/1/12 Takashi Iwai <[email protected]>:

Quoted 7 lines

At Mon, 12 Jan 2009 14:42:06 +0000,

Quoted 4 lines · James Courtier-Dutton

Sounds good to me.
One can keep the wrapper outside of the kernel, and only available in alsa-driver for those out of tree people.

Quoted 6 lines
Quoted 4 lines

Yes, that's good.
I think it'd be better to do that after one kernel-cycle later for a softer landing, though.

How soft do we need this?

One kernel cycle is enough.

Quoted 8 lines

The change is probably max of 3 lines of code per sound card that has an out of tree driver.
The only one I am aware of is the xfi one. With the wrapper being more than 3 lines of code being put into the kernel only to be removed again seems a little un-necessary to me.
For internal kernel changes, I don't think we should care about out of kernel drivers. None of the rest of the kernel developers go out of their way for anything out-of-mainline.

Well, my main concern isn't about out-of-kernel drivers like xfi, but the drivers that will come from other trees. The codes outside ALSA tree, for example, V4L, can't be always controlled by us (suppose a new V4L driver comes in for the next kernel). And these are more or less "mainline" development.

If you see the linux-next development, you'll find how the internal API can be a pain among several tree merges. A typical API change (that has been often seen in driver-core area) introduces first a wrapper while converting all in the present kernel, then kill it at the next cycle.

Takashi

#5 lore raw
Quoted 31 lines · Takashi Iwai

At Mon, 12 Jan 2009 15:06:51 +0000,

Quoted 11 lines · James Courtier-Dutton

2009/1/12 Takashi Iwai <[email protected]>:

Quoted 9 lines

At Mon, 12 Jan 2009 14:42:06 +0000,

Quoted 3 lines · James Courtier-Dutton

Sounds good to me.
One can keep the wrapper outside of the kernel, and only available in alsa-driver for those out of tree people.

Yes, that's good.
I think it'd be better to do that after one kernel-cycle later for a softer landing, though.

How soft do we need this?

One kernel cycle is enough.

Quoted 8 lines

The change is probably max of 3 lines of code per sound card that has an out of tree driver.
The only one I am aware of is the xfi one. With the wrapper being more than 3 lines of code being put into the kernel only to be removed again seems a little un-necessary to me.
For internal kernel changes, I don't think we should care about out of kernel drivers. None of the rest of the kernel developers go out of their way for anything out-of-mainline.

Well, my main concern isn't about out-of-kernel drivers like xfi, but the drivers that will come from other trees. The codes outside ALSA tree, for example, V4L, can't be always controlled by us (suppose a new V4L driver comes in for the next kernel). And these are more or less "mainline" development.

Quoted 6 lines

If you see the linux-next development, you'll find how the internal API can be a pain among several tree merges. A typical API change (that has been often seen in driver-core area) introduces first a wrapper while converting all in the present kernel, then kill it at the next cycle.

Ah! I did not think of V4L. Once cycle seems OK to me. I hope it creates a warning message to the V4L developers, although, I don't see why you cannot include a patch to V4L together with all the other alsa cards drivers that would get into linux-next.

#6 lore raw

At Wed, 14 Jan 2009 15:14:54 +0000,

Quoted 40 lines · James Courtier-Dutton
Quoted 31 lines · Takashi Iwai

At Mon, 12 Jan 2009 15:06:51 +0000,

Quoted 11 lines · James Courtier-Dutton

2009/1/12 Takashi Iwai <[email protected]>:

Quoted 9 lines

At Mon, 12 Jan 2009 14:42:06 +0000,

Quoted 3 lines · James Courtier-Dutton

Sounds good to me.
One can keep the wrapper outside of the kernel, and only available in alsa-driver for those out of tree people.

Yes, that's good.
I think it'd be better to do that after one kernel-cycle later for a softer landing, though.

How soft do we need this?

One kernel cycle is enough.

Quoted 8 lines

The change is probably max of 3 lines of code per sound card that has an out of tree driver.
The only one I am aware of is the xfi one. With the wrapper being more than 3 lines of code being put into the kernel only to be removed again seems a little un-necessary to me.
For internal kernel changes, I don't think we should care about out of kernel drivers. None of the rest of the kernel developers go out of their way for anything out-of-mainline.

Well, my main concern isn't about out-of-kernel drivers like xfi, but the drivers that will come from other trees. The codes outside ALSA tree, for example, V4L, can't be always controlled by us (suppose a new V4L driver comes in for the next kernel). And these are more or less "mainline" development.

Quoted 6 lines

If you see the linux-next development, you'll find how the internal API can be a pain among several tree merges. A typical API change (that has been often seen in driver-core area) introduces first a wrapper while converting all in the present kernel, then kill it at the next cycle.

Quoted 4 lines

Ah! I did not think of V4L. Once cycle seems OK to me. I hope it creates a warning message to the V4L developers, although, I don't see why you cannot include a patch to V4L together with all the other alsa cards drivers that would get into linux-next.

It's possible, but often not too easy if a new V4L driver is introduced in their tree. In that case, either we or they import their/out patch. This can be a mess once if the tree gets rebased or a similar thing happens.

Of course, I already patched the existing drivers (also found in usb gadget). But any upcoming stuff can be hard to expect...

thanks,

Takashi

#7 lore raw
In reply to Takashi Iwai
Quoted 8 lines · On Mon, 12 Jan 2009 15:35:19 +0100 Takashi Iwai <[email protected]> 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.

Regards,
Krzysztof

----------------------------------------------------------------------
Speak Up. Angielski szybko i skutecznie. 3 miesiace nauki gratis. Sprawdz. >> http://link.interia.pl/f2019

#8 lore raw

At Mon, 12 Jan 2009 17:08:28 +0100,

Quoted 13 lines · Krzysztof Helt
Quoted 8 lines · On Mon, 12 Jan 2009 15:35:19 +0100 Takashi Iwai <[email protected]> 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.

Quoted 4 lines

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

#9 lore raw
In reply to Takashi Iwai

At Mon, 12 Jan 2009 15:35:19 +0100,

Quoted 35 lines · I 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.

For fixing this situation, I'd like to convert from snd_card_new() to a new function, snd_card_create():

int snd_card_create(int idx, const char *id,

		    struct module *module, int extra_size,
		    struct snd_card **card_ret);

and provides snd_card_new() as a wrapper with deprecated flag:

static inline __deprecated
struct snd_card *snd_card_new(int idx, const char *id,
struct module *module, int extra_size)

{
	struct snd_card *card;
	if (snd_card_create(idx, id, module, extra_size, &card) < 0)
		return NULL;
	return card;
}

The merit of creating a new function is that the older and out-of-tree codes (like xfi) work without modification. There is alternative option, namely to use PTR_ERR() and keep the function as is. But this has no advantage in practice -- it can't detect the old API at build time, and it may Oops.

Quoted 5 lines

The preliminary patches are found in test/snd_card_new-err branch
of sound git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git test/snd_card_new-err

If anyone finds problems with this, please let me know.

Since no big issues came up, I merged that branch to master branch. Thanks for all your comments.

Takashi