Skip to content

Commit fe0d128

Browse files
committed
ALSA: jack: Allow building the jack layer without input device
Since the recent integration of kctl jack and input jack layers, we can basically build the jack layer even without input devices. That is, the jack layer itself can be built with conditional to enable the input device support or not, while the users may enable always CONFIG_SND_JACK unconditionally. For achieving it, this patch changes the following: - A new Kconfig, CONFIG_SND_JACK_INPUT_DEV, was introduced to indicate whether the jack layer supports the input device, - A few items in snd_jack struct and relevant codes are conditionally built upon CONFIG_SND_JACK_INPUT_DEV, - The users of CONFIG_SND_JACK drop the messy dependency on CONFIG_INPUT. This change also automagically fixes a potential bug in HD-audio driver Arnd reported, where the NULL or uninitialized jack instance is dereferenced. Reported-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 94a5735 commit fe0d128

6 files changed

Lines changed: 43 additions & 18 deletions

File tree

‎include/sound/jack.h‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ enum snd_jack_types {
7272
#define SND_JACK_SWITCH_TYPES 6
7373

7474
struct snd_jack {
75-
struct input_dev *input_dev;
7675
struct list_head kctl_list;
7776
struct snd_card *card;
77+
const char *id;
78+
#ifdef CONFIG_SND_JACK_INPUT_DEV
79+
struct input_dev *input_dev;
7880
int registered;
7981
int type;
80-
const char *id;
8182
char name[100];
8283
unsigned int key[6]; /* Keep in sync with definitions above */
84+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
8385
void *private_data;
8486
void (*private_free)(struct snd_jack *);
8587
};
@@ -89,10 +91,11 @@ struct snd_jack {
8991
int snd_jack_new(struct snd_card *card, const char *id, int type,
9092
struct snd_jack **jack, bool initial_kctl, bool phantom_jack);
9193
int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask);
94+
#ifdef CONFIG_SND_JACK_INPUT_DEV
9295
void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
9396
int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
9497
int keytype);
95-
98+
#endif
9699
void snd_jack_report(struct snd_jack *jack, int status);
97100

98101
#else
@@ -107,6 +110,13 @@ static inline int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name
107110
return 0;
108111
}
109112

113+
static inline void snd_jack_report(struct snd_jack *jack, int status)
114+
{
115+
}
116+
117+
#endif
118+
119+
#if !defined(CONFIG_SND_JACK) || !defined(CONFIG_SND_JACK_INPUT_DEV)
110120
static inline void snd_jack_set_parent(struct snd_jack *jack,
111121
struct device *parent)
112122
{
@@ -118,11 +128,6 @@ static inline int snd_jack_set_key(struct snd_jack *jack,
118128
{
119129
return 0;
120130
}
121-
122-
static inline void snd_jack_report(struct snd_jack *jack, int status)
123-
{
124-
}
125-
126-
#endif
131+
#endif /* !CONFIG_SND_JACK || !CONFIG_SND_JACK_INPUT_DEV */
127132

128133
#endif

‎sound/core/Kconfig‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ config SND_RAWMIDI
2424
config SND_COMPRESS_OFFLOAD
2525
tristate
2626

27-
# To be effective this also requires INPUT - users should say:
28-
# select SND_JACK if INPUT=y || INPUT=SND
29-
# to avoid having to force INPUT on.
3027
config SND_JACK
3128
bool
3229

30+
# enable input device support in jack layer
31+
config SND_JACK_INPUT_DEV
32+
bool
33+
depends on SND_JACK
34+
default y if INPUT=y || INPUT=SND
35+
3336
config SND_SEQUENCER
3437
tristate "Sequencer support"
3538
select SND_TIMER

‎sound/core/jack.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct snd_jack_kctl {
3232
unsigned int mask_bits; /* only masked status bits are reported via kctl */
3333
};
3434

35+
#ifdef CONFIG_SND_JACK_INPUT_DEV
3536
static int jack_switch_types[SND_JACK_SWITCH_TYPES] = {
3637
SW_HEADPHONE_INSERT,
3738
SW_MICROPHONE_INSERT,
@@ -40,9 +41,11 @@ static int jack_switch_types[SND_JACK_SWITCH_TYPES] = {
4041
SW_VIDEOOUT_INSERT,
4142
SW_LINEIN_INSERT,
4243
};
44+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
4345

4446
static int snd_jack_dev_disconnect(struct snd_device *device)
4547
{
48+
#ifdef CONFIG_SND_JACK_INPUT_DEV
4649
struct snd_jack *jack = device->device_data;
4750

4851
if (!jack->input_dev)
@@ -55,6 +58,7 @@ static int snd_jack_dev_disconnect(struct snd_device *device)
5558
else
5659
input_free_device(jack->input_dev);
5760
jack->input_dev = NULL;
61+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
5862
return 0;
5963
}
6064

@@ -79,6 +83,7 @@ static int snd_jack_dev_free(struct snd_device *device)
7983
return 0;
8084
}
8185

86+
#ifdef CONFIG_SND_JACK_INPUT_DEV
8287
static int snd_jack_dev_register(struct snd_device *device)
8388
{
8489
struct snd_jack *jack = device->device_data;
@@ -116,6 +121,7 @@ static int snd_jack_dev_register(struct snd_device *device)
116121

117122
return err;
118123
}
124+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
119125

120126
static void snd_jack_kctl_private_free(struct snd_kcontrol *kctl)
121127
{
@@ -209,11 +215,12 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
209215
struct snd_jack *jack;
210216
struct snd_jack_kctl *jack_kctl = NULL;
211217
int err;
212-
int i;
213218
static struct snd_device_ops ops = {
214219
.dev_free = snd_jack_dev_free,
220+
#ifdef CONFIG_SND_JACK_INPUT_DEV
215221
.dev_register = snd_jack_dev_register,
216222
.dev_disconnect = snd_jack_dev_disconnect,
223+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
217224
};
218225

219226
if (initial_kctl) {
@@ -230,6 +237,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
230237

231238
/* don't creat input device for phantom jack */
232239
if (!phantom_jack) {
240+
#ifdef CONFIG_SND_JACK_INPUT_DEV
241+
int i;
242+
233243
jack->input_dev = input_allocate_device();
234244
if (jack->input_dev == NULL) {
235245
err = -ENOMEM;
@@ -245,6 +255,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
245255
input_set_capability(jack->input_dev, EV_SW,
246256
jack_switch_types[i]);
247257

258+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
248259
}
249260

250261
err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
@@ -262,13 +273,16 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
262273
return 0;
263274

264275
fail_input:
276+
#ifdef CONFIG_SND_JACK_INPUT_DEV
265277
input_free_device(jack->input_dev);
278+
#endif
266279
kfree(jack->id);
267280
kfree(jack);
268281
return err;
269282
}
270283
EXPORT_SYMBOL(snd_jack_new);
271284

285+
#ifdef CONFIG_SND_JACK_INPUT_DEV
272286
/**
273287
* snd_jack_set_parent - Set the parent device for a jack
274288
*
@@ -326,10 +340,10 @@ int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
326340

327341
jack->type |= type;
328342
jack->key[key] = keytype;
329-
330343
return 0;
331344
}
332345
EXPORT_SYMBOL(snd_jack_set_key);
346+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
333347

334348
/**
335349
* snd_jack_report - Report the current status of a jack
@@ -340,7 +354,9 @@ EXPORT_SYMBOL(snd_jack_set_key);
340354
void snd_jack_report(struct snd_jack *jack, int status)
341355
{
342356
struct snd_jack_kctl *jack_kctl;
357+
#ifdef CONFIG_SND_JACK_INPUT_DEV
343358
int i;
359+
#endif
344360

345361
if (!jack)
346362
return;
@@ -349,6 +365,7 @@ void snd_jack_report(struct snd_jack *jack, int status)
349365
snd_kctl_jack_report(jack->card, jack_kctl->kctl,
350366
status & jack_kctl->mask_bits);
351367

368+
#ifdef CONFIG_SND_JACK_INPUT_DEV
352369
if (!jack->input_dev)
353370
return;
354371

@@ -369,6 +386,6 @@ void snd_jack_report(struct snd_jack *jack, int status)
369386
}
370387

371388
input_sync(jack->input_dev);
372-
389+
#endif /* CONFIG_SND_JACK_INPUT_DEV */
373390
}
374391
EXPORT_SYMBOL(snd_jack_report);

‎sound/pci/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ config SND_VIRTUOSO
866866
select SND_OXYGEN_LIB
867867
select SND_PCM
868868
select SND_MPU401_UART
869-
select SND_JACK if INPUT=y || INPUT=SND
869+
select SND_JACK
870870
help
871871
Say Y here to include support for sound cards based on the
872872
Asus AV66/AV100/AV200 chips, i.e., Xonar D1, DX, D2, D2X, DS, DSX,

‎sound/pci/hda/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ config SND_HDA
44
tristate
55
select SND_PCM
66
select SND_VMASTER
7-
select SND_JACK if INPUT=y || INPUT=SND
7+
select SND_JACK
88
select SND_HDA_CORE
99

1010
config SND_HDA_INTEL

‎sound/soc/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ menuconfig SND_SOC
66
tristate "ALSA for SoC audio support"
77
select SND_PCM
88
select AC97_BUS if SND_SOC_AC97_BUS
9-
select SND_JACK if INPUT=y || INPUT=SND
9+
select SND_JACK
1010
select REGMAP_I2C if I2C
1111
select REGMAP_SPI if SPI_MASTER
1212
---help---

0 commit comments

Comments
 (0)