Input: adc-joystick - fix ordering in adc_joystick_probe()
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 2 Aug 2022 17:00:00 +0000 (10:00 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 2 Aug 2022 17:01:16 +0000 (10:01 -0700)
We should register the IIO buffer before we register the input device,
because as soon as the device is registered input handlers may attach to
it, resulting in a call to adc_joystick_open() which makes use of the said
buffer.

Acked-by: Artur Rojek <contact@artur-rojek.eu>
Link: https://lore.kernel.org/r/YskFh4NHnlcryMkk@google.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/joystick/adc-joystick.c

index 78ebca7..e0cfdc8 100644 (file)
@@ -222,13 +222,6 @@ static int adc_joystick_probe(struct platform_device *pdev)
        if (error)
                return error;
 
-       input_set_drvdata(input, joy);
-       error = input_register_device(input);
-       if (error) {
-               dev_err(dev, "Unable to register input device\n");
-               return error;
-       }
-
        joy->buffer = iio_channel_get_all_cb(dev, adc_joystick_handle, joy);
        if (IS_ERR(joy->buffer)) {
                dev_err(dev, "Unable to allocate callback buffer\n");
@@ -241,6 +234,14 @@ static int adc_joystick_probe(struct platform_device *pdev)
                return error;
        }
 
+       input_set_drvdata(input, joy);
+
+       error = input_register_device(input);
+       if (error) {
+               dev_err(dev, "Unable to register input device\n");
+               return error;
+       }
+
        return 0;
 }