1From 4bfd1f15114550e1be7e43ae37a61906e1bff809 Mon Sep 17 00:00:00 2001
2From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
3Date: Sun, 17 Jul 2022 18:59:48 +0200
4Subject: [PATCH] alsactl/info.c: fix conditionals on __ALSA_PCM_H and
5 __ALSA_RAWMIDI_H
6
7Commit bbc74a61ac7c35e506c3d7f76ecf943cb55736a6 ("alsactl: implement
8'info' command") implemented an alsactl info command. In this
9implementation, there was an attempt to properly address optional
10features from alsa-lib by using conditions on __ALSA_PCM_H,
11__ALSA_RAWMIDI_H.
12
13Unfortunately, this attempt does not work entirely: only the code
14inside pcm_device_list(), rawmidi_device_list() was conditionally
15compiled, but their very prototype also use type definitions provided
16in pcm.h and rawmidi.h. So really, it's the entire function that needs
17to be conditionally implemented.
18
19Also, snd_rawmidi_stream_name() was not handled properly, for the same
20reason.
21
22This commit implements pcm_device_list() only if __ALSA_PCM_H is
23defined, and implements snd_rawmidi_stream_name() and
24rawmidi_device_list() only if __ALSA_RAWMIDI_H is defined.
25
26general_card_info() is modified to not call the PCM or raw MIDI
27functions when support is not available.
28
29Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
30Upstream: https://mailman.alsa-project.org/pipermail/alsa-devel/2022-July/203846.html
31---
32 alsactl/info.c | 14 ++++++++++----
33 1 file changed, 10 insertions(+), 4 deletions(-)
34
35diff --git a/alsactl/info.c b/alsactl/info.c
36index 253539d..9bd72af 100644
37--- a/alsactl/info.c
38+++ b/alsactl/info.c
39@@ -22,9 +22,9 @@
40 #include "aconfig.h"
41 #include "alsactl.h"
42
43+#ifdef __ALSA_PCM_H
44 static int pcm_device_list(snd_ctl_t *ctl, snd_pcm_stream_t stream, bool *first)
45 {
46-#ifdef __ALSA_PCM_H
47 	int err, dev, idx;
48 	unsigned int count;
49 	snd_pcm_info_t *pcminfo;
50@@ -76,10 +76,12 @@ static int pcm_device_list(snd_ctl_t *ctl, snd_pcm_stream_t stream, bool *first)
51 						idx, snd_pcm_info_get_subdevice_name(pcminfo));
52 		}
53 	}
54-#endif
55+
56 	return 0;
57 }
58+#endif
59
60+#ifdef __ALSA_RAWMIDI_H
61 static const char *snd_rawmidi_stream_name(snd_rawmidi_stream_t stream)
62 {
63 	if (stream == SND_RAWMIDI_STREAM_INPUT)
64@@ -91,7 +93,6 @@ static const char *snd_rawmidi_stream_name(snd_rawmidi_stream_t stream)
65
66 static int rawmidi_device_list(snd_ctl_t *ctl, snd_rawmidi_stream_t stream, bool *first)
67 {
68-#ifdef __ALSA_RAWMIDI_H
69 	int err, dev, idx;
70 	unsigned int count;
71 	snd_rawmidi_info_t *info;
72@@ -143,9 +144,10 @@ static int rawmidi_device_list(snd_ctl_t *ctl, snd_rawmidi_stream_t stream, bool
73 						idx, snd_rawmidi_info_get_subdevice_name(info));
74 		}
75 	}
76-#endif
77+
78 	return 0;
79 }
80+#endif
81
82 static int hwdep_device_list(snd_ctl_t *ctl)
83 {
84@@ -227,17 +229,21 @@ int general_card_info(int cardno)
85 	}
86 	err = card_info(ctl);
87
88+#ifdef __ALSA_PCM_H
89 	first = true;
90 	if (err >= 0)
91 		err = pcm_device_list(ctl, SND_PCM_STREAM_PLAYBACK, &first);
92 	if (err >= 0)
93 		err = pcm_device_list(ctl, SND_PCM_STREAM_CAPTURE, &first);
94+#endif
95
96+#ifdef __ALSA_RAWMIDI_H
97 	first = true;
98 	if (err >= 0)
99 		err = rawmidi_device_list(ctl, SND_PCM_STREAM_PLAYBACK, &first);
100 	if (err >= 0)
101 		err = rawmidi_device_list(ctl, SND_PCM_STREAM_CAPTURE, &first);
102+#endif
103
104 	if (err >= 0)
105 		err = hwdep_device_list(ctl);
106--
1072.36.1
108
109