Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

greybus: audio: Report jack events conditionally

Now jack & jack-buttons are registered to snd_jack framework based on
the capability shared by module's topology data. Thus, jack events
should be reported to above snd framework only in case corresponding
jack type is registered. This patch adds additional checks to avoid
reporting fake jack events.

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>

authored by

Vaibhav Agarwal and committed by
Greg Kroah-Hartman
cec89df4 847175e8

+29 -7
+29 -7
drivers/staging/greybus/audio_module.c
··· 21 21 static int gbaudio_request_jack(struct gbaudio_module_info *module, 22 22 struct gb_audio_jack_event_request *req) 23 23 { 24 - int report, button_status; 24 + int report; 25 + struct snd_jack *jack = module->headset_jack.jack; 26 + struct snd_jack *btn_jack = module->button_jack.jack; 27 + 28 + if (!jack) { 29 + dev_err_ratelimited(module->dev, 30 + "Invalid jack event received:type: %u, event: %u\n", 31 + req->jack_attribute, req->event); 32 + return -EINVAL; 33 + } 25 34 26 35 dev_warn_ratelimited(module->dev, 27 36 "Jack Event received: type: %u, event: %u\n", ··· 38 29 39 30 if (req->event == GB_AUDIO_JACK_EVENT_REMOVAL) { 40 31 module->jack_type = 0; 41 - button_status = module->button_status; 42 - module->button_status = 0; 43 - if (button_status) 32 + if (btn_jack && module->button_status) { 44 33 snd_soc_jack_report(&module->button_jack, 0, 45 34 module->button_mask); 35 + module->button_status = 0; 36 + } 46 37 snd_soc_jack_report(&module->headset_jack, 0, 47 38 module->jack_mask); 48 39 return 0; 49 40 } 50 41 51 - /* currently supports Headphone, Headset & Lineout only */ 52 - report &= ~module->jack_mask; 53 - report |= req->jack_attribute & module->jack_mask; 42 + report = req->jack_attribute & module->jack_mask; 43 + if (!report) { 44 + dev_err_ratelimited(module->dev, 45 + "Invalid jack event received:type: %u, event: %u\n", 46 + req->jack_attribute, req->event); 47 + return -EINVAL; 48 + } 49 + 54 50 if (module->jack_type) 55 51 dev_warn_ratelimited(module->dev, 56 52 "Modifying jack from %d to %d\n", ··· 71 57 struct gb_audio_button_event_request *req) 72 58 { 73 59 int soc_button_id, report; 60 + struct snd_jack *btn_jack = module->button_jack.jack; 61 + 62 + if (!btn_jack) { 63 + dev_err_ratelimited(module->dev, 64 + "Invalid button event received:type: %u, event: %u\n", 65 + req->button_id, req->event); 66 + return -EINVAL; 67 + } 74 68 75 69 dev_warn_ratelimited(module->dev, 76 70 "Button Event received: id: %u, event: %u\n",