staging: greybus: Add missing rwsem around snd_ctl_remove() calls
PATCH 1/1 staging: greybus: Add missing rwsem around snd_ctl_remove() calls
snd_ctl_remove() has to be called with card->controls_rwsem held (when called after the card instantiation). This patch adds the missing rwsem calls around it.
--- drivers/staging/greybus/audio_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/greybus/audio_helper.c +6 -2
@@ -192,7 +192,11 @@ int gbaudio_remove_component_controls(struct snd_soc_component *component, unsigned int num_controls) {struct snd_card *card = component->card->snd_card; +int err; -return gbaudio_remove_controls (card, component->dev, controls, - num_controls, component->name_prefix); +down_write (&card->controls_rwsem); + err =gbaudio_remove_controls (card, component->dev, controls, + num_controls, component->name_prefix); +up_write (&card->controls_rwsem); +return err; }
Signature · 1 line
2.31.1
Quoted 3 lines · Takashi Iwai
snd_ctl_remove()has to be called withcard->controls_rwsemheld (when called after the card instantiation). This patch adds the missing rwsem calls around it.
I see the comment above snd_ctl_remove() that says you must hold the write lock. And given that, this seems correct to me.
I understand why you want to take the lock just once, rather than each time snd_ctl_remove() is called.
However I believe the acquisition and release of the lock belongs inside gbaudio_remove_controls(), not in its caller.
If you disagree, can you please explain why?
Otherwise, will you please submit version two, taking the lock inside gbaudio_remove_controls()?
Thanks.
-Alex
Quoted 25 lines
Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio modules")Signed-off-by Takashi Iwai <[email protected]>--- drivers/staging/greybus/audio_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/staging/greybus/audio_helper.c +6
-2@@ -192,7 +192,11 @@ int gbaudio_remove_component_controls(struct snd_soc_component *component, unsigned int num_controls) {struct snd_card *card = component->card->snd_card; +int err; -return gbaudio_remove_controls (card, component->dev, controls, - num_controls, component->name_prefix); +down_write (&card->controls_rwsem); + err =gbaudio_remove_controls (card, component->dev, controls, + num_controls, component->name_prefix); +up_write (&card->controls_rwsem); +return err; }
Quoted 9 lines · Alex Elder
Quoted 3 lines · Takashi Iwai
snd_ctl_remove()has to be called withcard->controls_rwsemheld (when called after the card instantiation). This patch adds the missing rwsem calls around it.I see the comment above
snd_ctl_remove()that says you must hold the write lock. And given that, this seems correct to me.
Quoted 7 lines
I understand why you want to take the lock just once, rather than each time
snd_ctl_remove()is called.However I believe the acquisition and release of the lock belongs inside
gbaudio_remove_controls(), not in its caller.If you disagree, can you please explain why?
In general if the function returns an error and has a loop inside, taking a lock in the caller side avoids the forgotten unlock.
Takashi
Quoted 32 lines
Otherwise, will you please submit version two, taking the lock inside
gbaudio_remove_controls()?Thanks.
-Alex
Quoted 24 lines
Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio modules")Signed-off-by Takashi Iwai <[email protected]>--- drivers/staging/greybus/audio_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/staging/greybus/audio_helper.c +6
-1@@ -192,7 +192,11 @@ int gbaudio_remove_component_controls(struct snd_soc_component *component, unsigned int num_controls) {struct snd_card *card = component->card->snd_card; +int err; - return gbaudio_remove_controls(card, component->dev, controls, - num_controls, component->name_prefix); + down_write(&card->controls_rwsem); + err =gbaudio_remove_controls (card, component->dev, controls, + num_controls, component->name_prefix); +up_write (&card->controls_rwsem); +return err; }
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Alex Elder
Quoted 3 lines · Takashi Iwai
snd_ctl_remove()has to be called withcard->controls_rwsemheld (when called after the card instantiation). This patch adds the missing rwsem calls around it.I see the comment above
snd_ctl_remove()that says you must hold the write lock. And given that, this seems correct to me.I understand why you want to take the lock just once, rather than each time
snd_ctl_remove()is called.
Quoted 7 lines
Quoted 4 lines
However I believe the acquisition and release of the lock belongs inside
gbaudio_remove_controls(), not in its caller.If you disagree, can you please explain why?
In general if the function returns an error and has a loop inside, taking a lock in the caller side avoids the forgotten unlock.
But taking the lock in the called function makes the caller not need to take the lock (which would be even more valuable if there were more than one caller).
I prefer having the lock acquisition in the called function. Please send version 2, as I suggested.
-Alex
Quoted 35 lines
Takashi
Quoted 32 lines
Otherwise, will you please submit version two, taking the lock inside
gbaudio_remove_controls()?Thanks.
-Alex
Quoted 24 lines
Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio modules")Signed-off-by Takashi Iwai <[email protected]>--- drivers/staging/greybus/audio_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/staging/greybus/audio_helper.c +6
-1@@ -192,7 +192,11 @@ int gbaudio_remove_component_controls(struct snd_soc_component *component, unsigned int num_controls) {struct snd_card *card = component->card->snd_card; +int err; - return gbaudio_remove_controls(card, component->dev, controls, - num_controls, component->name_prefix); + down_write(&card->controls_rwsem); + err =gbaudio_remove_controls (card, component->dev, controls, + num_controls, component->name_prefix); +up_write (&card->controls_rwsem); +return err; }
Quoted 24 lines · Alex Elder
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Alex Elder
Quoted 3 lines · Takashi Iwai
snd_ctl_remove()has to be called withcard->controls_rwsemheld (when called after the card instantiation). This patch adds the missing rwsem calls around it.I see the comment above
snd_ctl_remove()that says you must hold the write lock. And given that, this seems correct to me.I understand why you want to take the lock just once, rather than each time
snd_ctl_remove()is called.Quoted 7 lines
Quoted 4 lines
However I believe the acquisition and release of the lock belongs inside
gbaudio_remove_controls(), not in its caller.If you disagree, can you please explain why?
In general if the function returns an error and has a loop inside, taking a lock in the caller side avoids the forgotten unlock.
Quoted 6 lines
But taking the lock in the called function makes the caller not need to take the lock (which would be even more valuable if there were more than one caller).
I prefer having the lock acquisition in the called function. Please send version 2, as I suggested.
Hi Takashi,
Thanks for sharing this patch. In reference to the suggestion from Alex, do you think replacing snd_ctl_find_id(), snd_ctl_remove() with snd_ctl_remove_id() inside gbaudio_remove_controls() would be an even better choice without worrying about locks?
--
vaibhav
Quoted 44 lines
-Alex
Quoted 35 lines
Takashi
Quoted 32 lines
Otherwise, will you please submit version two, taking the lock inside
gbaudio_remove_controls()?Thanks.
-Alex
Quoted 24 lines
Fixes 510e340efe0c ("staging: greybus: audio: Add helper APIs for dynamic audio modules")Signed-off-by Takashi Iwai <[email protected]>--- drivers/staging/greybus/audio_helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/staging/greybus/audio_helper.c +6
-1@@ -192,7 +192,11 @@ int gbaudio_remove_component_controls(struct snd_soc_component *component, unsigned int num_controls) {struct snd_card *card = component->card->snd_card; +int err; - return gbaudio_remove_controls(card, component->dev, controls, - num_controls, component->name_prefix); + down_write(&card->controls_rwsem); + err =gbaudio_remove_controls (card, component->dev, controls, + num_controls, component->name_prefix); +up_write (&card->controls_rwsem); +return err; }_______________________________________________
greybus-dev mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/greybus-dev
Quoted 34 lines · Vaibhav Agarwal
Quoted 24 lines · Alex Elder
Quoted 14 lines · Takashi Iwai
Quoted 12 lines · Alex Elder
Quoted 3 lines · Takashi Iwai
snd_ctl_remove()has to be called withcard->controls_rwsemheld (when called after the card instantiation). This patch adds the missing rwsem calls around it.I see the comment above
snd_ctl_remove()that says you must hold the write lock. And given that, this seems correct to me.I understand why you want to take the lock just once, rather than each time
snd_ctl_remove()is called.Quoted 7 lines
Quoted 4 lines
However I believe the acquisition and release of the lock belongs inside
gbaudio_remove_controls(), not in its caller.If you disagree, can you please explain why?
In general if the function returns an error and has a loop inside, taking a lock in the caller side avoids the forgotten unlock.
Quoted 6 lines
But taking the lock in the called function makes the caller not need to take the lock (which would be even more valuable if there were more than one caller).
I prefer having the lock acquisition in the called function. Please send version 2, as I suggested.
Quoted 6 lines
Hi Takashi,
Thanks for sharing this patch. In reference to the suggestion from Alex, do you think replacing
snd_ctl_find_id(),snd_ctl_remove()withsnd_ctl_remove_id()insidegbaudio_remove_controls()would be an even better choice without worrying about locks?
Yeah, that sounds like a better plan, indeed.
Takashi