HID: hid-input: allow input_configured callback return errors
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 29 Sep 2015 22:52:59 +0000 (15:52 -0700)
committerJiri Kosina <jkosina@suse.cz>
Wed, 30 Sep 2015 08:07:09 +0000 (10:07 +0200)
When configuring input device via input_configured callback we may
encounter errors (for example input_mt_init_slots() may fail). Instead
of continuing with half-initialized input device let's allow driver
indicate failures.

Signed-off-by: Jaikumar Ganesh <jaikumarg@android.com>
Signed-off-by: Arve Hjønnevåg <arve@android.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Acked-by: Andrew Duggan <aduggan@synaptics.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
12 files changed:
drivers/hid/hid-appleir.c
drivers/hid/hid-elo.c
drivers/hid/hid-input.c
drivers/hid/hid-lenovo.c
drivers/hid/hid-logitech-hidpp.c
drivers/hid/hid-magicmouse.c
drivers/hid/hid-multitouch.c
drivers/hid/hid-ntrig.c
drivers/hid/hid-rmi.c
drivers/hid/hid-sony.c
drivers/hid/hid-uclogic.c
include/linux/hid.h

index 0e6a42d37eb6f374ef864f383fc23d15bf844736..07cbc70f00e7dfc8ddbfc7554f8e9c134721bc1f 100644 (file)
@@ -256,7 +256,7 @@ out:
        return 0;
 }
 
-static void appleir_input_configured(struct hid_device *hid,
+static int appleir_input_configured(struct hid_device *hid,
                struct hid_input *hidinput)
 {
        struct input_dev *input_dev = hidinput->input;
@@ -275,6 +275,8 @@ static void appleir_input_configured(struct hid_device *hid,
        for (i = 0; i < ARRAY_SIZE(appleir_key_table); i++)
                set_bit(appleir->keymap[i], input_dev->keybit);
        clear_bit(KEY_RESERVED, input_dev->keybit);
+
+       return 0;
 }
 
 static int appleir_input_mapping(struct hid_device *hid,
index 4e49462870abdf2f265c1528ae6c07fa4f783ec8..aad8c162a825dc60516700b1bd8caf8efeec4244 100644 (file)
@@ -37,7 +37,7 @@ static bool use_fw_quirk = true;
 module_param(use_fw_quirk, bool, S_IRUGO);
 MODULE_PARM_DESC(use_fw_quirk, "Do periodic pokes for broken M firmwares (default = true)");
 
-static void elo_input_configured(struct hid_device *hdev,
+static int elo_input_configured(struct hid_device *hdev,
                struct hid_input *hidinput)
 {
        struct input_dev *input = hidinput->input;
@@ -45,6 +45,8 @@ static void elo_input_configured(struct hid_device *hdev,
        set_bit(BTN_TOUCH, input->keybit);
        set_bit(ABS_PRESSURE, input->absbit);
        input_set_abs_params(input, ABS_PRESSURE, 0, 256, 0, 0);
+
+       return 0;
 }
 
 static void elo_process_data(struct input_dev *input, const u8 *data, int size)
index 53aeaf6252c75a039cb94a13af27fffbb0f2bddb..2ba6bf69b7d0c45c3ca76b612de5d647d513e3ba 100644 (file)
@@ -1510,8 +1510,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
                                 * UGCI) cram a lot of unrelated inputs into the
                                 * same interface. */
                                hidinput->report = report;
-                               if (drv->input_configured)
-                                       drv->input_configured(hid, hidinput);
+                               if (drv->input_configured &&
+                                   drv->input_configured(hid, hidinput))
+                                       goto out_cleanup;
                                if (input_register_device(hidinput->input))
                                        goto out_cleanup;
                                hidinput = NULL;
@@ -1532,8 +1533,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
        }
 
        if (hidinput) {
-               if (drv->input_configured)
-                       drv->input_configured(hid, hidinput);
+               if (drv->input_configured &&
+                   drv->input_configured(hid, hidinput))
+                       goto out_cleanup;
                if (input_register_device(hidinput->input))
                        goto out_cleanup;
        }
index e4bc6cb6d7fa5d5481f650c87fde01a7348fdb6a..8979f1fd5208f95e9f707c46b77373f4c975b3b4 100644 (file)
@@ -848,7 +848,7 @@ static void lenovo_remove(struct hid_device *hdev)
        hid_hw_stop(hdev);
 }
 
-static void lenovo_input_configured(struct hid_device *hdev,
+static int lenovo_input_configured(struct hid_device *hdev,
                struct hid_input *hi)
 {
        switch (hdev->product) {
@@ -863,6 +863,8 @@ static void lenovo_input_configured(struct hid_device *hdev,
                        }
                        break;
        }
+
+       return 0;
 }
 
 
index 484196459305577c19433fe4fe35b21c2ac39905..a25f562f2d7bcf0651765019850bc12f7b900e4a 100644 (file)
@@ -1160,13 +1160,15 @@ static void hidpp_populate_input(struct hidpp_device *hidpp,
                m560_populate_input(hidpp, input, origin_is_hid_core);
 }
 
-static void hidpp_input_configured(struct hid_device *hdev,
+static int hidpp_input_configured(struct hid_device *hdev,
                                struct hid_input *hidinput)
 {
        struct hidpp_device *hidpp = hid_get_drvdata(hdev);
        struct input_dev *input = hidinput->input;
 
        hidpp_populate_input(hidpp, input, true);
+
+       return 0;
 }
 
 static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
index 29a74c1efcb85fa727536c4b72be844f9963cd70..d6fa496d0ca25c17035233315ba9f5d5ebddc4fd 100644 (file)
@@ -471,18 +471,22 @@ static int magicmouse_input_mapping(struct hid_device *hdev,
        return 0;
 }
 
-static void magicmouse_input_configured(struct hid_device *hdev,
+static int magicmouse_input_configured(struct hid_device *hdev,
                struct hid_input *hi)
 
 {
        struct magicmouse_sc *msc = hid_get_drvdata(hdev);
+       int ret;
 
-       int ret = magicmouse_setup_input(msc->input, hdev);
+       ret = magicmouse_setup_input(msc->input, hdev);
        if (ret) {
                hid_err(hdev, "magicmouse setup input failed (%d)\n", ret);
                /* clean msc->input to notify probe() of the failure */
                msc->input = NULL;
+               return ret;
        }
+
+       return 0;
 }
 
 
index 426b2f1a34501c7516ab39dc631d3c2073591aac..2ed42d8f805b57dd87273f7413873469ed11faf3 100644 (file)
@@ -725,12 +725,13 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
                mt_sync_frame(td, report->field[0]->hidinput->input);
 }
 
-static void mt_touch_input_configured(struct hid_device *hdev,
+static int mt_touch_input_configured(struct hid_device *hdev,
                                        struct hid_input *hi)
 {
        struct mt_device *td = hid_get_drvdata(hdev);
        struct mt_class *cls = &td->mtclass;
        struct input_dev *input = hi->input;
+       int ret;
 
        if (!td->maxcontacts)
                td->maxcontacts = MT_DEFAULT_MAXCONTACT;
@@ -752,9 +753,12 @@ static void mt_touch_input_configured(struct hid_device *hdev,
        if (td->is_buttonpad)
                __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 
-       input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
+       ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
+       if (ret)
+               return ret;
 
        td->mt_flags = 0;
+       return 0;
 }
 
 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
@@ -930,15 +934,19 @@ static void mt_post_parse(struct mt_device *td)
                cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
 }
 
-static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
+static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
 {
        struct mt_device *td = hid_get_drvdata(hdev);
        char *name;
        const char *suffix = NULL;
        struct hid_field *field = hi->report->field[0];
+       int ret;
 
-       if (hi->report->id == td->mt_report_id)
-               mt_touch_input_configured(hdev, hi);
+       if (hi->report->id == td->mt_report_id) {
+               ret = mt_touch_input_configured(hdev, hi);
+               if (ret)
+                       return ret;
+       }
 
        /*
         * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
@@ -989,6 +997,8 @@ static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
                        hi->input->name = name;
                }
        }
+
+       return 0;
 }
 
 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
index 600f2075512ff1895852212c67a0fbcb9764566c..756d1ef9bd991d9f77df5835f0cb1f44391493ed 100644 (file)
@@ -859,14 +859,14 @@ not_claimed_input:
        return 1;
 }
 
-static void ntrig_input_configured(struct hid_device *hid,
+static int ntrig_input_configured(struct hid_device *hid,
                struct hid_input *hidinput)
 
 {
        struct input_dev *input = hidinput->input;
 
        if (hidinput->report->maxfield < 1)
-               return;
+               return 0;
 
        switch (hidinput->report->field[0]->application) {
        case HID_DG_PEN:
@@ -890,6 +890,8 @@ static void ntrig_input_configured(struct hid_device *hid,
                                                        "N-Trig MultiTouch";
                break;
        }
+
+       return 0;
 }
 
 static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
index 2c148129beb2f0a746f4661660be47e79421274e..67cd059a8f46cdf7dab8d73cb0edb7bd5aff1333 100644 (file)
@@ -1173,7 +1173,7 @@ static int rmi_populate(struct hid_device *hdev)
        return 0;
 }
 
-static void rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
+static int rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
 {
        struct rmi_data *data = hid_get_drvdata(hdev);
        struct input_dev *input = hi->input;
@@ -1185,10 +1185,10 @@ static void rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
        hid_dbg(hdev, "Opening low level driver\n");
        ret = hid_hw_open(hdev);
        if (ret)
-               return;
+               return ret;
 
        if (!(data->device_flags & RMI_DEVICE))
-               return;
+               return 0;
 
        /* Allow incoming hid reports */
        hid_device_io_start(hdev);
@@ -1228,7 +1228,9 @@ static void rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
        input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 0x0f, 0, 0);
        input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 0x0f, 0, 0);
 
-       input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER);
+       ret = input_mt_init_slots(input, data->max_fingers, INPUT_MT_POINTER);
+       if (ret < 0)
+               goto exit;
 
        if (data->button_count) {
                __set_bit(EV_KEY, input->evbit);
@@ -1244,6 +1246,7 @@ static void rmi_input_configured(struct hid_device *hdev, struct hid_input *hi)
 exit:
        hid_device_io_stop(hdev);
        hid_hw_close(hdev);
+       return ret;
 }
 
 static int rmi_input_mapping(struct hid_device *hdev,
index 661f94f8ab8b0b0aafc9dace1073b08849e23784..774cd221056659f5bacd480b8b07744c1a5a138f 100644 (file)
@@ -1360,20 +1360,27 @@ static int sony_register_touchpad(struct hid_input *hi, int touch_count,
        return 0;
 }
 
-static void sony_input_configured(struct hid_device *hdev,
+static int sony_input_configured(struct hid_device *hdev,
                                        struct hid_input *hidinput)
 {
        struct sony_sc *sc = hid_get_drvdata(hdev);
+       int ret;
 
        /*
         * The Dualshock 4 touchpad supports 2 touches and has a
         * resolution of 1920x942 (44.86 dots/mm).
         */
        if (sc->quirks & DUALSHOCK4_CONTROLLER) {
-               if (sony_register_touchpad(hidinput, 2, 1920, 942) != 0)
+               ret = sony_register_touchpad(hidinput, 2, 1920, 942);
+               if (ret) {
                        hid_err(sc->hdev,
-                               "Unable to initialize multi-touch slots\n");
+                               "Unable to initialize multi-touch slots: %d\n",
+                               ret);
+                       return ret;
+               }
        }
+
+       return 0;
 }
 
 /*
index b905d501e752d607b6fc1731ad89ff3d23ce7cd0..85ac43517e3ffc3232461f54d43054cd36a39a29 100644 (file)
@@ -731,7 +731,7 @@ static int uclogic_input_mapping(struct hid_device *hdev, struct hid_input *hi,
        return 0;
 }
 
-static void uclogic_input_configured(struct hid_device *hdev,
+static int uclogic_input_configured(struct hid_device *hdev,
                struct hid_input *hi)
 {
        char *name;
@@ -741,7 +741,7 @@ static void uclogic_input_configured(struct hid_device *hdev,
 
        /* no report associated (HID_QUIRK_MULTI_INPUT not set) */
        if (!hi->report)
-               return;
+               return 0;
 
        field = hi->report->field[0];
 
@@ -774,6 +774,8 @@ static void uclogic_input_configured(struct hid_device *hdev,
                        hi->input->name = name;
                }
        }
+
+       return 0;
 }
 
 /**
index f17980de26629fbf65365047a0cfe8ce6034b53e..251a1d382e2325a17e0acb169d6e111589cf7444 100644 (file)
@@ -698,8 +698,8 @@ struct hid_driver {
        int (*input_mapped)(struct hid_device *hdev,
                        struct hid_input *hidinput, struct hid_field *field,
                        struct hid_usage *usage, unsigned long **bit, int *max);
-       void (*input_configured)(struct hid_device *hdev,
-                                struct hid_input *hidinput);
+       int (*input_configured)(struct hid_device *hdev,
+                               struct hid_input *hidinput);
        void (*feature_mapping)(struct hid_device *hdev,
                        struct hid_field *field,
                        struct hid_usage *usage);