Input: synaptics-rmi4 - Fix error handling in I2C transport driver
Subsystems (2)
PATCH 1/1 Input: synaptics-rmi4 - Fix error handling in I2C transport driver
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
--- drivers/input/rmi4/rmi_i2c.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/input/rmi4/rmi_i2c.c +10 -3
@@ -285,23 +285,30 @@ static int rmi_i2c_probe(struct i2c_client *client, retval =rmi_set_page (rmi_i2c,0 );if (retval) {dev_err (&client->dev,"Failed to set page select to 0.\n" ); -return retval; + goto error_disable; } retval =rmi_register_transport_device (&rmi_i2c->xport);if (retval) {dev_err (&client->dev,"Failed to register transport driver at 0x%.2X.\n" , client->addr); -return retval; + goto error_disable; } retval =rmi_i2c_init_irq (client);if (retval <0 ) -return retval; + goto error_unregister;dev_info (&client->dev,"registered rmi i2c driver at %#04x.\n" , client->addr);return 0 ; + +error_unregister: +rmi_unregister_transport_device (&rmi_i2c->xport); +error_disable: +regulator_bulk_disable (ARRAY_SIZE (rmi_i2c->supplies), + rmi_i2c->supplies); +return retval; }static int rmi_i2c_remove (struct i2c_client *client)
Signature · 1 line
2.5.0
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")
Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>
Regards,
Bjorn
Quoted 47 lines
Cc Andrew Duggan <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/input/rmi4/rmi_i2c.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/input/rmi4/rmi_i2c.c +10
-3@@ -285,23 +285,30 @@ static int rmi_i2c_probe(struct i2c_client *client, retval =rmi_set_page (rmi_i2c,0 );if (retval) {dev_err (&client->dev,"Failed to set page select to 0.\n" ); -return retval; + goto error_disable; } retval =rmi_register_transport_device (&rmi_i2c->xport);if (retval) {dev_err (&client->dev,"Failed to register transport driver at 0x%.2X.\n" , client->addr); -return retval; + goto error_disable; } retval =rmi_i2c_init_irq (client);if (retval <0 ) -return retval; + goto error_unregister;dev_info (&client->dev,"registered rmi i2c driver at %#04x.\n" , client->addr);return 0 ; + +error_unregister: +rmi_unregister_transport_device (&rmi_i2c->xport); +error_disable: +regulator_bulk_disable (ARRAY_SIZE (rmi_i2c->supplies), + rmi_i2c->supplies); +return retval; }static int rmi_i2c_remove (struct i2c_client *client)Signature · 1 line
2.5.0
Quoted 8 lines · Bjorn Andersson
Quoted 6 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Quoted 8 lines
Quoted 1 line
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>Reviewed-by Bjorn Andersson <[email protected]>
Applied, thank you.
It looks like we have similar issue in rmi_spi.c. Can I get another patch?
Quoted 51 lines
Regards,
BjornQuoted 47 lines
Cc Andrew Duggan <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/input/rmi4/rmi_i2c.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/input/rmi4/rmi_i2c.c +10
-3@@ -285,23 +285,30 @@ static int rmi_i2c_probe(struct i2c_client *client, retval =rmi_set_page (rmi_i2c,0 );if (retval) {dev_err (&client->dev,"Failed to set page select to 0.\n" ); -return retval; + goto error_disable; } retval =rmi_register_transport_device (&rmi_i2c->xport);if (retval) {dev_err (&client->dev,"Failed to register transport driver at 0x%.2X.\n" , client->addr); -return retval; + goto error_disable; } retval =rmi_i2c_init_irq (client);if (retval <0 ) -return retval; + goto error_unregister;dev_info (&client->dev,"registered rmi i2c driver at %#04x.\n" , client->addr);return 0 ; + +error_unregister: +rmi_unregister_transport_device (&rmi_i2c->xport); +error_disable: +regulator_bulk_disable (ARRAY_SIZE (rmi_i2c->supplies), + rmi_i2c->supplies); +return retval; }static int rmi_i2c_remove (struct i2c_client *client)Signature · 1 line
2.5.0
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerQuoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")
Quoted 8 lines
Quoted 6 lines
Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>Reviewed-by Bjorn Andersson <[email protected]>Applied, thank you.
I take it back. rmi_i2c_init_irq() uses devm* so this whole thing mixes up devm* and manual unregistering and unwind order is completely broken.
1. Why do we register interrupt from transport drivers and not make it part of rmi_register_transport_device()?
2. If we need to use some non-devm-ised resources we should use devm_add_action[_or_reset] to work these operations into devm stream.
Thanks,
Quoted 58 lines
It looks like we have similar issue in
rmi_spi.c. Can I get another patch?Quoted 51 lines
Regards,
BjornQuoted 47 lines
Cc Andrew Duggan <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/input/rmi4/rmi_i2c.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/input/rmi4/rmi_i2c.c +10
-3@@ -285,23 +285,30 @@ static int rmi_i2c_probe(struct i2c_client *client, retval =rmi_set_page (rmi_i2c,0 );if (retval) {dev_err (&client->dev,"Failed to set page select to 0.\n" ); -return retval; + goto error_disable; } retval =rmi_register_transport_device (&rmi_i2c->xport);if (retval) {dev_err (&client->dev,"Failed to register transport driver at 0x%.2X.\n" , client->addr); -return retval; + goto error_disable; } retval =rmi_i2c_init_irq (client);if (retval <0 ) -return retval; + goto error_unregister;dev_info (&client->dev,"registered rmi i2c driver at %#04x.\n" , client->addr);return 0 ; + +error_unregister: +rmi_unregister_transport_device (&rmi_i2c->xport); +error_disable: +regulator_bulk_disable (ARRAY_SIZE (rmi_i2c->supplies), + rmi_i2c->supplies); +return retval; }static int rmi_i2c_remove (struct i2c_client *client)Signature · 1 line
2.5.0Signature · 1 line
Dmitry
Signature · 1 line
Dmitry
Quoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Bjorn Andersson <[email protected]>Applied, thank you.
I take it back.
rmi_i2c_init_irq()uses devm* so this whole thing mixes up devm* and manual unregistering and unwind order is completely broken.
Oops ...
Quoted 2 lines
1. Why do we register interrupt from transport drivers and not make it part of
rmi_register_transport_device()?
rmi_register_transport_device() doesn't take dev as parameter.
Quoted 2 lines
2. If we need to use some non-devm-ised resources we should use devm_add_action[_or_reset] to work these operations into devm stream.
Ok, no problem.
Guenter
Quoted 62 lines
Thanks,
Quoted 58 lines
It looks like we have similar issue in
rmi_spi.c. Can I get another patch?Quoted 47 lines
Regards,
BjornQuoted 43 lines
Cc Andrew Duggan <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/input/rmi4/rmi_i2c.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/input/rmi4/rmi_i2c.c +10
-3@@ -285,23 +285,30 @@ static int rmi_i2c_probe(struct i2c_client *client, retval =rmi_set_page (rmi_i2c,0 );if (retval) {dev_err (&client->dev,"Failed to set page select to 0.\n" ); -return retval; + goto error_disable; } retval =rmi_register_transport_device (&rmi_i2c->xport);if (retval) {dev_err (&client->dev,"Failed to register transport driver at 0x%.2X.\n" , client->addr); -return retval; + goto error_disable; } retval =rmi_i2c_init_irq (client);if (retval <0 ) -return retval; + goto error_unregister;dev_info (&client->dev,"registered rmi i2c driver at %#04x.\n" , client->addr);return 0 ; + +error_unregister: +rmi_unregister_transport_device (&rmi_i2c->xport); +error_disable: +regulator_bulk_disable (ARRAY_SIZE (rmi_i2c->supplies), + rmi_i2c->supplies); +return retval; }Quoted 4 lines
Quoted 4 lines
drivers/input/rmi4/rmi_i2c.c +0
-1static int rmi_i2c_remove (struct i2c_client *client) --2.5.0
--
Dmitry
Quoted 20 lines · Guenter Roeck
Quoted 19 lines · Dmitry Torokhov
Quoted 18 lines · Dmitry Torokhov
Quoted 16 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>Reviewed-by Bjorn Andersson <[email protected]>
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Applied, thank you.
I take it back.
rmi_i2c_init_irq()uses devm* so this whole thing mixes up devm* and manual unregistering and unwind order is completely broken.Oops ...
Quoted 2 lines
1. Why do we register interrupt from transport drivers and not make it part of
rmi_register_transport_device()?
Not all RMI devices will have access to interrupts (ie HID and SMBus). The same goes for regulators. Here is a reference to a previous discussion regarding both:
https://lkml.org/lkml/2016/5/9/1055
Quoted 6 lines
rmi_register_transport_device()doesn't take dev as parameter.Quoted 2 lines
2. If we need to use some non-devm-ised resources we should use devm_add_action[_or_reset] to work these operations into devm stream.
Since the regulator functions have their own devm_ versions I would suggest switching to those functions to avoid dealing with unregistering.
Registering and unregistering the transport device is a bit more complicated since these functions add and put the rmi_dev device. But, it sounds like we can handle the unregister using devm_add_action_or_reset().
Andrew
Quoted 71 lines
Ok, no problem.
Guenter
Quoted 62 lines
Thanks,
Quoted 58 lines
It looks like we have similar issue in
rmi_spi.c. Can I get another patch?Quoted 47 lines
Regards,
BjornQuoted 43 lines
Cc Andrew Duggan <[email protected]>Signed-off-by Guenter Roeck <[email protected]>--- drivers/input/rmi4/rmi_i2c.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/input/rmi4/rmi_i2c.c +10
-3@@ -285,23 +285,30 @@ static int rmi_i2c_probe(struct i2c_client *client, retval =rmi_set_page (rmi_i2c,0 );if (retval) {dev_err (&client->dev,"Failed to set page select to 0.\n" ); -return retval; + goto error_disable; } retval =rmi_register_transport_device (&rmi_i2c->xport);if (retval) {dev_err (&client->dev,"Failed to register transport driver at 0x%.2X.\n" , client->addr); -return retval; + goto error_disable; } retval =rmi_i2c_init_irq (client);if (retval <0 ) -return retval; + goto error_unregister;dev_info (&client->dev,"registered rmi i2c driver at %#04x.\n" , client->addr);return 0 ; + +error_unregister: +rmi_unregister_transport_device (&rmi_i2c->xport); +error_disable: +regulator_bulk_disable (ARRAY_SIZE (rmi_i2c->supplies), + rmi_i2c->supplies); +return retval; }Quoted 4 lines
Quoted 4 lines
drivers/input/rmi4/rmi_i2c.c +0
-1static int rmi_i2c_remove (struct i2c_client *client) --2.5.0
--
Dmitry--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 42 lines · Andrew Duggan
Quoted 20 lines · Guenter Roeck
Quoted 19 lines · Dmitry Torokhov
Quoted 18 lines · Dmitry Torokhov
Quoted 16 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>Reviewed-by Bjorn Andersson <[email protected]>Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Applied, thank you.
I take it back.
rmi_i2c_init_irq()uses devm* so this whole thing mixes up devm* and manual unregistering and unwind order is completely broken.Oops ...
Quoted 2 lines
1. Why do we register interrupt from transport drivers and not make it part of
rmi_register_transport_device()?Not all RMI devices will have access to interrupts (ie HID and SMBus). The same goes for regulators. Here is a reference to a previous discussion regarding both:
https://lkml.org/lkml/2016/5/9/1055Quoted 3 lines
rmi_register_transport_device()doesn't take dev as parameter.
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
2. If we need to use some non-devm-ised resources we should use devm_add_action[_or_reset] to work these operations into devm stream.
Since the regulator functions have their own
devm_versions I would suggest switching to those functions to avoid dealing with unregistering.
Maybe I am missing something, but I don't see a devm_regulator_bulk_enable(). devm_regulator_bulk_get() is already used.
Guenter
Quoted 5 lines
Registering and unregistering the transport device is a bit more complicated since these functions add and put the
rmi_devdevice. But, it sounds like we can handle the unregister usingdevm_add_action_or_reset().
Quoted 47 lines · Guenter Roeck
Quoted 46 lines · Andrew Duggan
Quoted 20 lines · Guenter Roeck
Quoted 19 lines · Dmitry Torokhov
Quoted 18 lines · Dmitry Torokhov
Quoted 16 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>Reviewed-by Bjorn Andersson <[email protected]>Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Applied, thank you.
I take it back.
rmi_i2c_init_irq()uses devm* so this whole thing mixes up devm* and manual unregistering and unwind order is completely broken.Oops ...
Quoted 2 lines
1. Why do we register interrupt from transport drivers and not make it part of
rmi_register_transport_device()?Not all RMI devices will have access to interrupts (ie HID and SMBus). The same goes for regulators. Here is a reference to a previous discussion regarding both:
https://lkml.org/lkml/2016/5/9/1055Quoted 6 lines
rmi_register_transport_device()doesn't take dev as parameter.Quoted 2 lines
2. If we need to use some non-devm-ised resources we should use devm_add_action[_or_reset] to work these operations into devm stream.
Quoted 8 lines
Quoted 4 lines
Since the regulator functions have their own
devm_versions I would suggest switching to those functions to avoid dealing with unregistering.Maybe I am missing something, but I don't see a
devm_regulator_bulk_enable().devm_regulator_bulk_get()is already used.
Yeah, I was just double checking that too. You're right, they are already using the devm version.
Andrew
Quoted 7 lines
Guenter
Quoted 5 lines
Registering and unregistering the transport device is a bit more complicated since these functions add and put the
rmi_devdevice. But, it sounds like we can handle the unregister usingdevm_add_action_or_reset().
Dmitry Torokhov
maintainerQuoted 31 lines · Andrew Duggan
Quoted 28 lines · Guenter Roeck
Quoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Bjorn Andersson <[email protected]>Applied, thank you.
I take it back.
rmi_i2c_init_irq()uses devm* so this whole thing mixes up devm* and manual unregistering and unwind order is completely broken.Oops ...
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
1. Why do we register interrupt from transport drivers and not make it part of
rmi_register_transport_device()?Not all RMI devices will have access to interrupts (ie HID and SMBus). The same goes for regulators. Here is a reference to a previous discussion regarding both:
https://lkml.org/lkml/2016/5/9/1055
Yeah, I am wondering if we should not revisit this and have SMBus (and possibly HID) actually provide us with an interrupt.
In the meantime we can just ignore interrupt value if it is set to 0.
Quoted 11 lines
Quoted 7 lines
rmi_register_transport_device()doesn't take dev as parameter.Quoted 2 lines
2. If we need to use some non-devm-ised resources we should use devm_add_action[_or_reset] to work these operations into devm stream.
Since the regulator functions have their own
devm_versions I would suggest switching to those functions to avoid dealing with unregistering.
There is no devm* API for enabling regulators, just acquiring them.
Thanks,
Signature · 1 line
Dmitry
Quoted 40 lines · Dmitry Torokhov
Quoted 31 lines · Andrew Duggan
Quoted 28 lines · Guenter Roeck
Quoted 17 lines · Dmitry Torokhov
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Reviewed-by Bjorn Andersson <[email protected]>Applied, thank you.
I take it back.
rmi_i2c_init_irq()uses devm* so this whole thing mixes up devm* and manual unregistering and unwind order is completely broken.Oops ...
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
1. Why do we register interrupt from transport drivers and not make it part of
rmi_register_transport_device()?Not all RMI devices will have access to interrupts (ie HID and SMBus). The same goes for regulators. Here is a reference to a previous discussion regarding both:
https://lkml.org/lkml/2016/5/9/1055
Quoted 5 lines
Yeah, I am wondering if we should not revisit this and have SMBus (and possibly HID) actually provide us with an interrupt.
In the meantime we can just ignore interrupt value if it is set to 0.
I have another follow-up patch doing that (I have a test setup which doesn't support interrupts); I just wasn't sure if there was interest, so I did not yet send it out. I'll be happy to do that, though I would prefer to keep it separate (it isn't a bug fix, after all).
Thanks,
Guenter
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Bjorn Andersson
Quoted 7 lines · Guenter Roeck
Instantiating the rmi4 I2C transport driver without interrupts assigned (for example using manual i2c instantiation from the command line) caused the driver to fail to load, but it does not clean up its regulator or transport device registrations. Result is a crash at a later time, for example when rebooting the system.
Fixes 946c8432aab0 ("Input: synaptics-rmi4 - support regulator supplies")Sorry for that.
Quoted 2 lines
Fixes fdf51604f104 ("Input: synaptics-rmi4 - add I2C transport driver")Cc Bjorn Andersson <[email protected]>
Quoted 7 lines
Quoted 1 line
Reviewed-by Bjorn Andersson <[email protected]>Applied, thank you.
It looks like we have similar issue in
rmi_spi.c. Can I get another patch?
Sure.
Guenter