Jarvis: Prevent crash with invalid input device
David DSH [Sat, 21 Jan 2017 02:02:47 +0000 (18:02 -0800)]
Bug 1864174

Change-Id: I3c62d723bc15817c687a7c70567238825703bc19
Signed-off-by: David DSH <ddastoussthi@nvidia.com>
Reviewed-on: http://git-master/r/1291898
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vinayak Pane <vpane@nvidia.com>
Reviewed-by: Robert Shih <rshih@nvidia.com>
Tested-by: Robert Shih <rshih@nvidia.com>
(cherry picked from commit 27d75519b396282a2f688ce14fdb6a0491068b65)
Reviewed-on: http://git-master/r/1298934
Reviewed-by: Manish Tuteja <mtuteja@nvidia.com>
Tested-by: Manish Tuteja <mtuteja@nvidia.com>

drivers/hid/hid-atv-jarvis.c

index be6e7eb..6d42a48 100644 (file)
@@ -1436,9 +1436,14 @@ static int atvr_snd_initialize(struct hid_device *hdev,
        int err;
        int i;
        int dev = 0;
-       struct hid_input *hidinput = list_first_entry(&hdev->inputs,
+       struct hid_input *hidinput = list_first_entry_or_null(&hdev->inputs,
                        struct hid_input, list);
-       struct input_dev *shdr_input_dev = hidinput->input;
+       struct input_dev *shdr_input_dev;
+
+       if (hidinput == NULL)
+               return -ENODEV;
+
+       shdr_input_dev = hidinput->input;
 
        while (dev < SNDRV_CARDS && cards_in_use[dev])
                dev++;