All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: jack: Access input_dev under mutex
@ 2022-04-01 12:29 Amadeusz Sławiński
  2022-04-01 13:03 ` Cezary Rojewski
  2022-04-07  8:24 ` Takashi Iwai
  0 siblings, 2 replies; 4+ messages in thread
From: Amadeusz Sławiński @ 2022-04-01 12:29 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Amadeusz Sławiński

It is possible when using ASoC that input_dev is unregistered while
calling snd_jack_report, which causes NULL pointer dereference.
In order to prevent this serialize access to input_dev using mutex lock.

Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
---
 include/sound/jack.h |  1 +
 sound/core/jack.c    | 37 ++++++++++++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/include/sound/jack.h b/include/sound/jack.h
index 1181f536557e..1ed90e2109e9 100644
--- a/include/sound/jack.h
+++ b/include/sound/jack.h
@@ -62,6 +62,7 @@ struct snd_jack {
 	const char *id;
 #ifdef CONFIG_SND_JACK_INPUT_DEV
 	struct input_dev *input_dev;
+	struct mutex input_dev_lock;
 	int registered;
 	int type;
 	char name[100];
diff --git a/sound/core/jack.c b/sound/core/jack.c
index d1e3055f2b6a..58b9ebf5e7e1 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -42,8 +42,11 @@ static int snd_jack_dev_disconnect(struct snd_device *device)
 #ifdef CONFIG_SND_JACK_INPUT_DEV
 	struct snd_jack *jack = device->device_data;
 
-	if (!jack->input_dev)
+	mutex_lock(&jack->input_dev_lock);
+	if (!jack->input_dev) {
+		mutex_unlock(&jack->input_dev_lock);
 		return 0;
+	}
 
 	/* If the input device is registered with the input subsystem
 	 * then we need to use a different deallocator. */
@@ -52,6 +55,7 @@ static int snd_jack_dev_disconnect(struct snd_device *device)
 	else
 		input_free_device(jack->input_dev);
 	jack->input_dev = NULL;
+	mutex_unlock(&jack->input_dev_lock);
 #endif /* CONFIG_SND_JACK_INPUT_DEV */
 	return 0;
 }
@@ -90,8 +94,11 @@ static int snd_jack_dev_register(struct snd_device *device)
 	snprintf(jack->name, sizeof(jack->name), "%s %s",
 		 card->shortname, jack->id);
 
-	if (!jack->input_dev)
+	mutex_lock(&jack->input_dev_lock);
+	if (!jack->input_dev) {
+		mutex_unlock(&jack->input_dev_lock);
 		return 0;
+	}
 
 	jack->input_dev->name = jack->name;
 
@@ -116,6 +123,7 @@ static int snd_jack_dev_register(struct snd_device *device)
 	if (err == 0)
 		jack->registered = 1;
 
+	mutex_unlock(&jack->input_dev_lock);
 	return err;
 }
 #endif /* CONFIG_SND_JACK_INPUT_DEV */
@@ -517,11 +525,15 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 		return -ENOMEM;
 	}
 
-	/* don't creat input device for phantom jack */
-	if (!phantom_jack) {
 #ifdef CONFIG_SND_JACK_INPUT_DEV
+	mutex_init(&jack->input_dev_lock);
+
+	/* don't create input device for phantom jack */
+	if (!phantom_jack) {
 		int i;
 
+		mutex_lock(&jack->input_dev_lock);
+
 		jack->input_dev = input_allocate_device();
 		if (jack->input_dev == NULL) {
 			err = -ENOMEM;
@@ -537,8 +549,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 				input_set_capability(jack->input_dev, EV_SW,
 						     jack_switch_types[i]);
 
-#endif /* CONFIG_SND_JACK_INPUT_DEV */
+		mutex_unlock(&jack->input_dev_lock);
 	}
+#endif /* CONFIG_SND_JACK_INPUT_DEV */
 
 	err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
 	if (err < 0)
@@ -556,7 +569,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 
 fail_input:
 #ifdef CONFIG_SND_JACK_INPUT_DEV
+	mutex_lock(&jack->input_dev_lock);
 	input_free_device(jack->input_dev);
+	mutex_unlock(&jack->input_dev_lock);
 #endif
 	kfree(jack->id);
 	kfree(jack);
@@ -578,10 +593,14 @@ EXPORT_SYMBOL(snd_jack_new);
 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent)
 {
 	WARN_ON(jack->registered);
-	if (!jack->input_dev)
+	mutex_lock(&jack->input_dev_lock);
+	if (!jack->input_dev) {
+		mutex_unlock(&jack->input_dev_lock);
 		return;
+	}
 
 	jack->input_dev->dev.parent = parent;
+	mutex_unlock(&jack->input_dev_lock);
 }
 EXPORT_SYMBOL(snd_jack_set_parent);
 
@@ -654,8 +673,11 @@ void snd_jack_report(struct snd_jack *jack, int status)
 					     status & jack_kctl->mask_bits);
 
 #ifdef CONFIG_SND_JACK_INPUT_DEV
-	if (!jack->input_dev)
+	mutex_lock(&jack->input_dev_lock);
+	if (!jack->input_dev) {
+		mutex_unlock(&jack->input_dev_lock);
 		return;
+	}
 
 	for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
 		int testbit = ((SND_JACK_BTN_0 >> i) & ~mask_bits);
@@ -675,6 +697,7 @@ void snd_jack_report(struct snd_jack *jack, int status)
 	}
 
 	input_sync(jack->input_dev);
+	mutex_unlock(&jack->input_dev_lock);
 #endif /* CONFIG_SND_JACK_INPUT_DEV */
 }
 EXPORT_SYMBOL(snd_jack_report);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: jack: Access input_dev under mutex
  2022-04-01 12:29 [PATCH] ALSA: jack: Access input_dev under mutex Amadeusz Sławiński
@ 2022-04-01 13:03 ` Cezary Rojewski
  2022-04-07  8:24 ` Takashi Iwai
  1 sibling, 0 replies; 4+ messages in thread
From: Cezary Rojewski @ 2022-04-01 13:03 UTC (permalink / raw)
  To: Amadeusz Sławiński; +Cc: alsa-devel, Takashi Iwai

On 2022-04-01 2:29 PM, Amadeusz Sławiński wrote:
> It is possible when using ASoC that input_dev is unregistered while
> calling snd_jack_report, which causes NULL pointer dereference.
> In order to prevent this serialize access to input_dev using mutex lock.
> 
> Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>

Nitpick: "when using ASoC" is quite a generic statement. By that I guess 
you relate to concept of splitting audio functionality into smaller 
logical blocks - components (struct snd_soc_components) - and the 
possible synchronization issues that are part of that division.


That alone is probably not a reason for re-send so:

Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>

> ---
>   include/sound/jack.h |  1 +
>   sound/core/jack.c    | 37 ++++++++++++++++++++++++++++++-------
>   2 files changed, 31 insertions(+), 7 deletions(-)
> 
> diff --git a/include/sound/jack.h b/include/sound/jack.h
> index 1181f536557e..1ed90e2109e9 100644
> --- a/include/sound/jack.h
> +++ b/include/sound/jack.h
> @@ -62,6 +62,7 @@ struct snd_jack {
>   	const char *id;
>   #ifdef CONFIG_SND_JACK_INPUT_DEV
>   	struct input_dev *input_dev;
> +	struct mutex input_dev_lock;
>   	int registered;
>   	int type;
>   	char name[100];
> diff --git a/sound/core/jack.c b/sound/core/jack.c
> index d1e3055f2b6a..58b9ebf5e7e1 100644
> --- a/sound/core/jack.c
> +++ b/sound/core/jack.c
> @@ -42,8 +42,11 @@ static int snd_jack_dev_disconnect(struct snd_device *device)
>   #ifdef CONFIG_SND_JACK_INPUT_DEV
>   	struct snd_jack *jack = device->device_data;
>   
> -	if (!jack->input_dev)
> +	mutex_lock(&jack->input_dev_lock);
> +	if (!jack->input_dev) {
> +		mutex_unlock(&jack->input_dev_lock);
>   		return 0;
> +	}
>   
>   	/* If the input device is registered with the input subsystem
>   	 * then we need to use a different deallocator. */
> @@ -52,6 +55,7 @@ static int snd_jack_dev_disconnect(struct snd_device *device)
>   	else
>   		input_free_device(jack->input_dev);
>   	jack->input_dev = NULL;
> +	mutex_unlock(&jack->input_dev_lock);
>   #endif /* CONFIG_SND_JACK_INPUT_DEV */
>   	return 0;
>   }
> @@ -90,8 +94,11 @@ static int snd_jack_dev_register(struct snd_device *device)
>   	snprintf(jack->name, sizeof(jack->name), "%s %s",
>   		 card->shortname, jack->id);
>   
> -	if (!jack->input_dev)
> +	mutex_lock(&jack->input_dev_lock);
> +	if (!jack->input_dev) {
> +		mutex_unlock(&jack->input_dev_lock);
>   		return 0;
> +	}
>   
>   	jack->input_dev->name = jack->name;
>   
> @@ -116,6 +123,7 @@ static int snd_jack_dev_register(struct snd_device *device)
>   	if (err == 0)
>   		jack->registered = 1;
>   
> +	mutex_unlock(&jack->input_dev_lock);
>   	return err;
>   }
>   #endif /* CONFIG_SND_JACK_INPUT_DEV */
> @@ -517,11 +525,15 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
>   		return -ENOMEM;
>   	}
>   
> -	/* don't creat input device for phantom jack */
> -	if (!phantom_jack) {
>   #ifdef CONFIG_SND_JACK_INPUT_DEV
> +	mutex_init(&jack->input_dev_lock);
> +
> +	/* don't create input device for phantom jack */
> +	if (!phantom_jack) {
>   		int i;
>   
> +		mutex_lock(&jack->input_dev_lock);
> +
>   		jack->input_dev = input_allocate_device();
>   		if (jack->input_dev == NULL) {
>   			err = -ENOMEM;
> @@ -537,8 +549,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
>   				input_set_capability(jack->input_dev, EV_SW,
>   						     jack_switch_types[i]);
>   
> -#endif /* CONFIG_SND_JACK_INPUT_DEV */
> +		mutex_unlock(&jack->input_dev_lock);
>   	}
> +#endif /* CONFIG_SND_JACK_INPUT_DEV */
>   
>   	err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
>   	if (err < 0)
> @@ -556,7 +569,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
>   
>   fail_input:
>   #ifdef CONFIG_SND_JACK_INPUT_DEV
> +	mutex_lock(&jack->input_dev_lock);
>   	input_free_device(jack->input_dev);
> +	mutex_unlock(&jack->input_dev_lock);
>   #endif
>   	kfree(jack->id);
>   	kfree(jack);
> @@ -578,10 +593,14 @@ EXPORT_SYMBOL(snd_jack_new);
>   void snd_jack_set_parent(struct snd_jack *jack, struct device *parent)
>   {
>   	WARN_ON(jack->registered);
> -	if (!jack->input_dev)
> +	mutex_lock(&jack->input_dev_lock);
> +	if (!jack->input_dev) {
> +		mutex_unlock(&jack->input_dev_lock);
>   		return;
> +	}
>   
>   	jack->input_dev->dev.parent = parent;
> +	mutex_unlock(&jack->input_dev_lock);
>   }
>   EXPORT_SYMBOL(snd_jack_set_parent);
>   
> @@ -654,8 +673,11 @@ void snd_jack_report(struct snd_jack *jack, int status)
>   					     status & jack_kctl->mask_bits);
>   
>   #ifdef CONFIG_SND_JACK_INPUT_DEV
> -	if (!jack->input_dev)
> +	mutex_lock(&jack->input_dev_lock);
> +	if (!jack->input_dev) {
> +		mutex_unlock(&jack->input_dev_lock);
>   		return;
> +	}
>   
>   	for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
>   		int testbit = ((SND_JACK_BTN_0 >> i) & ~mask_bits);
> @@ -675,6 +697,7 @@ void snd_jack_report(struct snd_jack *jack, int status)
>   	}
>   
>   	input_sync(jack->input_dev);
> +	mutex_unlock(&jack->input_dev_lock);
>   #endif /* CONFIG_SND_JACK_INPUT_DEV */
>   }
>   EXPORT_SYMBOL(snd_jack_report);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: jack: Access input_dev under mutex
  2022-04-01 12:29 [PATCH] ALSA: jack: Access input_dev under mutex Amadeusz Sławiński
  2022-04-01 13:03 ` Cezary Rojewski
@ 2022-04-07  8:24 ` Takashi Iwai
  1 sibling, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2022-04-07  8:24 UTC (permalink / raw)
  To: Amadeusz Sławiński; +Cc: alsa-devel, Takashi Iwai

On Fri, 01 Apr 2022 14:29:31 +0200,
Amadeusz Sławiński wrote:
> 
> @@ -517,11 +525,15 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
>  		return -ENOMEM;
>  	}
>  
> -	/* don't creat input device for phantom jack */
> -	if (!phantom_jack) {
>  #ifdef CONFIG_SND_JACK_INPUT_DEV
> +	mutex_init(&jack->input_dev_lock);
> +
> +	/* don't create input device for phantom jack */
> +	if (!phantom_jack) {
>  		int i;
>  
> +		mutex_lock(&jack->input_dev_lock);
> +

This lock is superfluous.  The object is being created here and isn't
registered anywhere, so no one else can use it yet.
And moreover ....

>  		jack->input_dev = input_allocate_device();
>  		if (jack->input_dev == NULL) {
>  			err = -ENOMEM;

... you forgot unlock here, and this error path will lead to a
deadlock.


> @@ -537,8 +549,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
>  				input_set_capability(jack->input_dev, EV_SW,
>  						     jack_switch_types[i]);
>  
> -#endif /* CONFIG_SND_JACK_INPUT_DEV */
> +		mutex_unlock(&jack->input_dev_lock);
>  	}
> +#endif /* CONFIG_SND_JACK_INPUT_DEV */
>  
>  	err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
>  	if (err < 0)
> @@ -556,7 +569,9 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
>  
>  fail_input:
>  #ifdef CONFIG_SND_JACK_INPUT_DEV
> +	mutex_lock(&jack->input_dev_lock);
>  	input_free_device(jack->input_dev);
> +	mutex_unlock(&jack->input_dev_lock);

Ditto, no need for mutex lock yet.

One thing I'm not sure is whether it's good to use mutex.
Basically snd_jack_report() is considered to be callable from
non-atomic context, too, so far, and we don't need to prohibit it.
OTOH, all current calls are in the sleepable context, so it's likely
no big problem.  But if we use mutex, it should be documented in
snd_jack_report() function, too.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ALSA: jack: Access input_dev under mutex
@ 2022-04-01 16:16 kernel test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2022-04-01 16:16 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 9206 bytes --]

CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220401122931.4181700-1-amadeuszx.slawinski@linux.intel.com>
References: <20220401122931.4181700-1-amadeuszx.slawinski@linux.intel.com>
TO: "Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>
TO: Takashi Iwai <tiwai@suse.com>
CC: alsa-devel(a)alsa-project.org
CC: "Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>

Hi "Amadeusz,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on v5.17 next-20220401]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Amadeusz-S-awi-ski/ALSA-jack-Access-input_dev-under-mutex/20220401-203645
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
:::::: branch date: 4 hours ago
:::::: commit date: 4 hours ago
config: powerpc-randconfig-c024-20220331 (https://download.01.org/0day-ci/archive/20220402/202204020033.S4YFojPq-lkp(a)intel.com/config)
compiler: powerpc-linux-gcc (GCC) 11.2.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>


cocci warnings: (new ones prefixed by >>)
>> sound/core/jack.c:535:2-12: second lock on line 572

vim +535 sound/core/jack.c

9058cbe1eed293 Jie Yang           2015-04-27  482  
e76d8ceaaff9d7 Mark Brown         2008-07-28  483  /**
e76d8ceaaff9d7 Mark Brown         2008-07-28  484   * snd_jack_new - Create a new jack
e76d8ceaaff9d7 Mark Brown         2008-07-28  485   * @card:  the card instance
e76d8ceaaff9d7 Mark Brown         2008-07-28  486   * @id:    an identifying string for this jack
e76d8ceaaff9d7 Mark Brown         2008-07-28  487   * @type:  a bitmask of enum snd_jack_type values that can be detected by
e76d8ceaaff9d7 Mark Brown         2008-07-28  488   *         this jack
e76d8ceaaff9d7 Mark Brown         2008-07-28  489   * @jjack: Used to provide the allocated jack object to the caller.
4e3f0dc65883ca Jie Yang           2015-04-27  490   * @initial_kctl: if true, create a kcontrol and add it to the jack list.
4e3f0dc65883ca Jie Yang           2015-04-27  491   * @phantom_jack: Don't create a input device for phantom jacks.
e76d8ceaaff9d7 Mark Brown         2008-07-28  492   *
e76d8ceaaff9d7 Mark Brown         2008-07-28  493   * Creates a new jack object.
e76d8ceaaff9d7 Mark Brown         2008-07-28  494   *
eb7c06e8e9c93b Yacine Belkadi     2013-03-11  495   * Return: Zero if successful, or a negative error code on failure.
eb7c06e8e9c93b Yacine Belkadi     2013-03-11  496   * On success @jjack will be initialised.
e76d8ceaaff9d7 Mark Brown         2008-07-28  497   */
e76d8ceaaff9d7 Mark Brown         2008-07-28  498  int snd_jack_new(struct snd_card *card, const char *id, int type,
4e3f0dc65883ca Jie Yang           2015-04-27  499  		 struct snd_jack **jjack, bool initial_kctl, bool phantom_jack)
e76d8ceaaff9d7 Mark Brown         2008-07-28  500  {
e76d8ceaaff9d7 Mark Brown         2008-07-28  501  	struct snd_jack *jack;
4e3f0dc65883ca Jie Yang           2015-04-27  502  	struct snd_jack_kctl *jack_kctl = NULL;
e76d8ceaaff9d7 Mark Brown         2008-07-28  503  	int err;
f15ee210cdb87f Takashi Iwai       2020-01-03  504  	static const struct snd_device_ops ops = {
e76d8ceaaff9d7 Mark Brown         2008-07-28  505  		.dev_free = snd_jack_dev_free,
fe0d128c57bf92 Takashi Iwai       2016-02-17  506  #ifdef CONFIG_SND_JACK_INPUT_DEV
e76d8ceaaff9d7 Mark Brown         2008-07-28  507  		.dev_register = snd_jack_dev_register,
32b8544296b944 Takashi Iwai       2013-11-14  508  		.dev_disconnect = snd_jack_dev_disconnect,
fe0d128c57bf92 Takashi Iwai       2016-02-17  509  #endif /* CONFIG_SND_JACK_INPUT_DEV */
e76d8ceaaff9d7 Mark Brown         2008-07-28  510  	};
e76d8ceaaff9d7 Mark Brown         2008-07-28  511  
4e3f0dc65883ca Jie Yang           2015-04-27  512  	if (initial_kctl) {
4e3f0dc65883ca Jie Yang           2015-04-27  513  		jack_kctl = snd_jack_kctl_new(card, id, type);
4e3f0dc65883ca Jie Yang           2015-04-27  514  		if (!jack_kctl)
4e3f0dc65883ca Jie Yang           2015-04-27  515  			return -ENOMEM;
4e3f0dc65883ca Jie Yang           2015-04-27  516  	}
4e3f0dc65883ca Jie Yang           2015-04-27  517  
e76d8ceaaff9d7 Mark Brown         2008-07-28  518  	jack = kzalloc(sizeof(struct snd_jack), GFP_KERNEL);
e76d8ceaaff9d7 Mark Brown         2008-07-28  519  	if (jack == NULL)
e76d8ceaaff9d7 Mark Brown         2008-07-28  520  		return -ENOMEM;
e76d8ceaaff9d7 Mark Brown         2008-07-28  521  
282cd76ffca781 Matt Ranostay      2008-10-25  522  	jack->id = kstrdup(id, GFP_KERNEL);
c01c1db1dc632e Xiaoke Wang        2021-12-13  523  	if (jack->id == NULL) {
c01c1db1dc632e Xiaoke Wang        2021-12-13  524  		kfree(jack);
c01c1db1dc632e Xiaoke Wang        2021-12-13  525  		return -ENOMEM;
c01c1db1dc632e Xiaoke Wang        2021-12-13  526  	}
e76d8ceaaff9d7 Mark Brown         2008-07-28  527  
fe0d128c57bf92 Takashi Iwai       2016-02-17  528  #ifdef CONFIG_SND_JACK_INPUT_DEV
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  529  	mutex_init(&jack->input_dev_lock);
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  530  
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  531  	/* don't create input device for phantom jack */
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  532  	if (!phantom_jack) {
fe0d128c57bf92 Takashi Iwai       2016-02-17  533  		int i;
fe0d128c57bf92 Takashi Iwai       2016-02-17  534  
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01 @535  		mutex_lock(&jack->input_dev_lock);
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  536  
e76d8ceaaff9d7 Mark Brown         2008-07-28  537  		jack->input_dev = input_allocate_device();
e76d8ceaaff9d7 Mark Brown         2008-07-28  538  		if (jack->input_dev == NULL) {
e76d8ceaaff9d7 Mark Brown         2008-07-28  539  			err = -ENOMEM;
e76d8ceaaff9d7 Mark Brown         2008-07-28  540  			goto fail_input;
e76d8ceaaff9d7 Mark Brown         2008-07-28  541  		}
e76d8ceaaff9d7 Mark Brown         2008-07-28  542  
e76d8ceaaff9d7 Mark Brown         2008-07-28  543  		jack->input_dev->phys = "ALSA";
e76d8ceaaff9d7 Mark Brown         2008-07-28  544  
e76d8ceaaff9d7 Mark Brown         2008-07-28  545  		jack->type = type;
e76d8ceaaff9d7 Mark Brown         2008-07-28  546  
53803aead010a3 Mark Brown         2012-02-07  547  		for (i = 0; i < SND_JACK_SWITCH_TYPES; i++)
bd8a71a7b0f50d Mark Brown         2009-01-03  548  			if (type & (1 << i))
e76d8ceaaff9d7 Mark Brown         2008-07-28  549  				input_set_capability(jack->input_dev, EV_SW,
1c6e555c3a66af Mark Brown         2010-03-17  550  						     jack_switch_types[i]);
e76d8ceaaff9d7 Mark Brown         2008-07-28  551  
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  552  		mutex_unlock(&jack->input_dev_lock);
4e3f0dc65883ca Jie Yang           2015-04-27  553  	}
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  554  #endif /* CONFIG_SND_JACK_INPUT_DEV */
4e3f0dc65883ca Jie Yang           2015-04-27  555  
e76d8ceaaff9d7 Mark Brown         2008-07-28  556  	err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
e76d8ceaaff9d7 Mark Brown         2008-07-28  557  	if (err < 0)
e76d8ceaaff9d7 Mark Brown         2008-07-28  558  		goto fail_input;
e76d8ceaaff9d7 Mark Brown         2008-07-28  559  
9058cbe1eed293 Jie Yang           2015-04-27  560  	jack->card = card;
9058cbe1eed293 Jie Yang           2015-04-27  561  	INIT_LIST_HEAD(&jack->kctl_list);
9058cbe1eed293 Jie Yang           2015-04-27  562  
4e3f0dc65883ca Jie Yang           2015-04-27  563  	if (initial_kctl)
4e3f0dc65883ca Jie Yang           2015-04-27  564  		snd_jack_kctl_add(jack, jack_kctl);
4e3f0dc65883ca Jie Yang           2015-04-27  565  
e76d8ceaaff9d7 Mark Brown         2008-07-28  566  	*jjack = jack;
e76d8ceaaff9d7 Mark Brown         2008-07-28  567  
e76d8ceaaff9d7 Mark Brown         2008-07-28  568  	return 0;
e76d8ceaaff9d7 Mark Brown         2008-07-28  569  
e76d8ceaaff9d7 Mark Brown         2008-07-28  570  fail_input:
fe0d128c57bf92 Takashi Iwai       2016-02-17  571  #ifdef CONFIG_SND_JACK_INPUT_DEV
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01 @572  	mutex_lock(&jack->input_dev_lock);
e76d8ceaaff9d7 Mark Brown         2008-07-28  573  	input_free_device(jack->input_dev);
ddb977b25cdc65 Amadeusz Sławiński 2022-04-01  574  	mutex_unlock(&jack->input_dev_lock);
fe0d128c57bf92 Takashi Iwai       2016-02-17  575  #endif
eeda276bef3602 Lu Guanqun         2011-02-21  576  	kfree(jack->id);
e76d8ceaaff9d7 Mark Brown         2008-07-28  577  	kfree(jack);
e76d8ceaaff9d7 Mark Brown         2008-07-28  578  	return err;
e76d8ceaaff9d7 Mark Brown         2008-07-28  579  }
e76d8ceaaff9d7 Mark Brown         2008-07-28  580  EXPORT_SYMBOL(snd_jack_new);
e76d8ceaaff9d7 Mark Brown         2008-07-28  581  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-07  8:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 12:29 [PATCH] ALSA: jack: Access input_dev under mutex Amadeusz Sławiński
2022-04-01 13:03 ` Cezary Rojewski
2022-04-07  8:24 ` Takashi Iwai
2022-04-01 16:16 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.