greybus: audio: Avoid reporting spurious button events
authorVaibhav Agarwal <vaibhav.agarwal@linaro.org>
Thu, 1 Sep 2016 06:08:42 +0000 (11:38 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Fri, 2 Sep 2016 12:13:39 +0000 (14:13 +0200)
Now jack-button are registered to snd framework based on capabilities
populated by codec module's topology data. Thus, valid ids for button
events can also vary for different modules. This patch modifies existing
button reporting mechanism to avoid reporting spurious button events for
invalid button ids.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/audio_module.c

index d3284ab1dacfc8432eb72901d4593937b07f52c3..411735df2bb41698321fcb27aedf2c2d3610fe63 100644 (file)
@@ -92,24 +92,27 @@ static int gbaudio_request_button(struct gbaudio_module_info *module,
        }
 
        report = module->button_status & module->button_mask;
+       soc_button_id = 0;
 
        switch (req->button_id) {
        case 1:
-               soc_button_id = SND_JACK_BTN_0;
+               soc_button_id = SND_JACK_BTN_0 & module->button_mask;
                break;
 
        case 2:
-               soc_button_id = SND_JACK_BTN_1;
+               soc_button_id = SND_JACK_BTN_1 & module->button_mask;
                break;
 
        case 3:
-               soc_button_id = SND_JACK_BTN_2;
+               soc_button_id = SND_JACK_BTN_2 & module->button_mask;
                break;
 
        case 4:
-               soc_button_id = SND_JACK_BTN_3;
+               soc_button_id = SND_JACK_BTN_3 & module->button_mask;
                break;
-       default:
+       }
+
+       if (!soc_button_id) {
                dev_err_ratelimited(module->dev,
                                    "Invalid button request received\n");
                return -EINVAL;