1- <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
2-
3- <book>
4- <?dbhtml filename="index.html">
1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3+ "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
54
65<!-- ****************************************************** -->
76<!-- Header -->
87<!-- ****************************************************** -->
8+ <book id =" Writing-an-ALSA-Driver" >
99 <bookinfo >
1010 <title >Writing an ALSA Driver</title >
1111 <author >
492492 }
493493
494494 /* (2) */
495- card = snd_card_new (index[dev], id[dev], THIS_MODULE, 0);
496- if (card == NULL )
497- return -ENOMEM ;
495+ err = snd_card_create (index[dev], id[dev], THIS_MODULE, 0, &card );
496+ if (err < 0 )
497+ return err ;
498498
499499 /* (3) */
500500 err = snd_mychip_create(card, pci, &chip);
590590 <programlisting >
591591<![CDATA[
592592 struct snd_card *card;
593+ int err;
593594 ....
594- card = snd_card_new (index[dev], id[dev], THIS_MODULE, 0);
595+ err = snd_card_create (index[dev], id[dev], THIS_MODULE, 0, &card );
595596]]>
596597 </programlisting >
597598 </informalexample >
809810
810811 <para >
811812 As mentioned above, to create a card instance, call
812- <function>snd_card_new ()</function>.
813+ <function >snd_card_create ()</function >.
813814
814815 <informalexample >
815816 <programlisting >
816817<![CDATA[
817818 struct snd_card *card;
818- card = snd_card_new(index, id, module, extra_size);
819+ int err;
820+ err = snd_card_create(index, id, module, extra_size, &card);
819821]]>
820822 </programlisting >
821823 </informalexample >
822824 </para >
823825
824826 <para >
825- The function takes four arguments, the card-index number, the
827+ The function takes five arguments, the card-index number, the
826828 id string, the module pointer (usually
827829 <constant >THIS_MODULE</constant >),
828- and the size of extra-data space. The last argument is used to
830+ the size of extra-data space, and the pointer to return the
831+ card instance. The extra_size argument is used to
829832 allocate card-> private_data for the
830833 chip-specific data. Note that these data
831- are allocated by <function>snd_card_new ()</function>.
834+ are allocated by <function >snd_card_create ()</function >.
832835 </para >
833836 </section >
834837
915918 </para >
916919
917920 <section id =" card-management-chip-specific-snd-card-new" >
918- <title>1. Allocating via <function>snd_card_new ()</function>.</title>
921+ <title >1. Allocating via <function >snd_card_create ()</function >.</title >
919922 <para >
920923 As mentioned above, you can pass the extra-data-length
921- to the 4th argument of <function>snd_card_new ()</function>, i.e.
924+ to the 4th argument of <function >snd_card_create ()</function >, i.e.
922925
923926 <informalexample >
924927 <programlisting >
925928<![CDATA[
926- card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct mychip));
929+ err = snd_card_create(index[dev], id[dev], THIS_MODULE,
930+ sizeof(struct mychip), &card);
927931]]>
928932 </programlisting >
929933 </informalexample >
952956
953957 <para >
954958 After allocating a card instance via
955- <function>snd_card_new ()</function> (with
956- <constant>NULL </constant> on the 4th arg), call
959+ <function >snd_card_create ()</function > (with
960+ <constant >0 </constant > on the 4th arg), call
957961 <function >kzalloc()</function >.
958962
959963 <informalexample >
960964 <programlisting >
961965<![CDATA[
962966 struct snd_card *card;
963967 struct mychip *chip;
964- card = snd_card_new (index[dev], id[dev], THIS_MODULE, NULL );
968+ err = snd_card_create (index[dev], id[dev], THIS_MODULE, 0, &card );
965969 .....
966970 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
967971]]>
@@ -5750,8 +5754,9 @@ struct _snd_pcm_runtime {
57505754 ....
57515755 struct snd_card *card;
57525756 struct mychip *chip;
5757+ int err;
57535758 ....
5754- card = snd_card_new (index[dev], id[dev], THIS_MODULE, NULL );
5759+ err = snd_card_create (index[dev], id[dev], THIS_MODULE, 0, &card );
57555760 ....
57565761 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
57575762 ....
@@ -5763,7 +5768,7 @@ struct _snd_pcm_runtime {
57635768 </informalexample >
57645769
57655770 When you created the chip data with
5766- <function>snd_card_new ()</function>, it's anyway accessible
5771+ <function >snd_card_create ()</function >, it's anyway accessible
57675772 via <structfield >private_data</structfield > field.
57685773
57695774 <informalexample >
@@ -5775,9 +5780,10 @@ struct _snd_pcm_runtime {
57755780 ....
57765781 struct snd_card *card;
57775782 struct mychip *chip;
5783+ int err;
57785784 ....
5779- card = snd_card_new (index[dev], id[dev], THIS_MODULE,
5780- sizeof(struct mychip));
5785+ err = snd_card_create (index[dev], id[dev], THIS_MODULE,
5786+ sizeof(struct mychip), &card );
57815787 ....
57825788 chip = card->private_data;
57835789 ....
0 commit comments