mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 18:52:02 +00:00
ALSA: jack: Use guard() for locking
We can simplify the code gracefully with new guard() macro and co for automatic cleanup of locks. Only the code refactoring, and no functional changes. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://lore.kernel.org/r/20240227085306.9764-11-tiwai@suse.de
This commit is contained in:
parent
84bb065b31
commit
7234795b59
@ -42,11 +42,9 @@ static int snd_jack_dev_disconnect(struct snd_device *device)
|
|||||||
#ifdef CONFIG_SND_JACK_INPUT_DEV
|
#ifdef CONFIG_SND_JACK_INPUT_DEV
|
||||||
struct snd_jack *jack = device->device_data;
|
struct snd_jack *jack = device->device_data;
|
||||||
|
|
||||||
mutex_lock(&jack->input_dev_lock);
|
guard(mutex)(&jack->input_dev_lock);
|
||||||
if (!jack->input_dev) {
|
if (!jack->input_dev)
|
||||||
mutex_unlock(&jack->input_dev_lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* If the input device is registered with the input subsystem
|
/* If the input device is registered with the input subsystem
|
||||||
* then we need to use a different deallocator. */
|
* then we need to use a different deallocator. */
|
||||||
@ -55,7 +53,6 @@ static int snd_jack_dev_disconnect(struct snd_device *device)
|
|||||||
else
|
else
|
||||||
input_free_device(jack->input_dev);
|
input_free_device(jack->input_dev);
|
||||||
jack->input_dev = NULL;
|
jack->input_dev = NULL;
|
||||||
mutex_unlock(&jack->input_dev_lock);
|
|
||||||
#endif /* CONFIG_SND_JACK_INPUT_DEV */
|
#endif /* CONFIG_SND_JACK_INPUT_DEV */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -92,11 +89,9 @@ static int snd_jack_dev_register(struct snd_device *device)
|
|||||||
snprintf(jack->name, sizeof(jack->name), "%s %s",
|
snprintf(jack->name, sizeof(jack->name), "%s %s",
|
||||||
card->shortname, jack->id);
|
card->shortname, jack->id);
|
||||||
|
|
||||||
mutex_lock(&jack->input_dev_lock);
|
guard(mutex)(&jack->input_dev_lock);
|
||||||
if (!jack->input_dev) {
|
if (!jack->input_dev)
|
||||||
mutex_unlock(&jack->input_dev_lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
jack->input_dev->name = jack->name;
|
jack->input_dev->name = jack->name;
|
||||||
|
|
||||||
@ -121,7 +116,6 @@ static int snd_jack_dev_register(struct snd_device *device)
|
|||||||
if (err == 0)
|
if (err == 0)
|
||||||
jack->registered = 1;
|
jack->registered = 1;
|
||||||
|
|
||||||
mutex_unlock(&jack->input_dev_lock);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_SND_JACK_INPUT_DEV */
|
#endif /* CONFIG_SND_JACK_INPUT_DEV */
|
||||||
@ -586,14 +580,9 @@ EXPORT_SYMBOL(snd_jack_new);
|
|||||||
void snd_jack_set_parent(struct snd_jack *jack, struct device *parent)
|
void snd_jack_set_parent(struct snd_jack *jack, struct device *parent)
|
||||||
{
|
{
|
||||||
WARN_ON(jack->registered);
|
WARN_ON(jack->registered);
|
||||||
mutex_lock(&jack->input_dev_lock);
|
guard(mutex)(&jack->input_dev_lock);
|
||||||
if (!jack->input_dev) {
|
if (jack->input_dev)
|
||||||
mutex_unlock(&jack->input_dev_lock);
|
jack->input_dev->dev.parent = parent;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
jack->input_dev->dev.parent = parent;
|
|
||||||
mutex_unlock(&jack->input_dev_lock);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(snd_jack_set_parent);
|
EXPORT_SYMBOL(snd_jack_set_parent);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user