linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] input: automate of_node_put() calls for device_node
@ 2024-10-10 21:25 Javier Carrasco
  2024-10-10 21:25 ` [PATCH 01/10] Input: cap11xx - switch to for_each_child_of_node_scoped Javier Carrasco
                   ` (9 more replies)
  0 siblings, 10 replies; 26+ messages in thread
From: Javier Carrasco @ 2024-10-10 21:25 UTC (permalink / raw)
  To: Dmitry Torokhov, Matthias Brugger, AngeloGioacchino Del Regno,
	Hans de Goede, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Florian Fainelli, Broadcom internal kernel review list
  Cc: linux-input, linux-kernel, linux-arm-kernel, linux-mediatek,
	linux-sunxi, linux-rpi-kernel, Javier Carrasco

This series removes the explicit calls to 'of_node_put()' from the input
subsystem, either by switching from 'for_each_child_of_node()' to its
scoped variant 'for_each_child_of_node_scoped()', or by adding the
cleanup attribute to the device_node by means of the '__free()' macro.

This series simplifies the code in some cases, and it makes it in
general more robust, as it will avoid memory leaks if early returns are
added without the required call to 'of_node_put()', which is a rather
common issue.

The following drivers unconditionally release the device node after
using it:

  - misc/twl4030-vibra.c ('of_node_put()' under an if, but only if the
    node received a valid value).
  - misc/sparcspkr.c
  - serio/i8042-sparcio.h
  - touchscreen/raspberrypi-ts.c
  - touchscreen/ts4800-ts.c

The usage of the cleanup faciliy for these drivers offers no real gain
at the moment, but as soon as an error path is added to them, things can
go wrong, as it has happened multiple times with such nodes. I intended
to remove this error-prone pattern from the subsystem, so it is not
"borrowed" by new users. But if someone has strong feelings about the
automatic cleanup for those drives, I will not complain if they are left
as they are (at least until a new buggy error path is introduced ;)).

The approach for the variable declaration is the one that has been
followed in previous clean ups: as near as possible to its usage,
instead of at the top. I have no strong feelings about that either, but
I would prefer it that way for consistency and to have a common pattern
for future additions.

A single call to 'of_node_put()' has been left behind in rmi4/rmi_bus.c,
as it is used to release a node passed as a parameter, which would make
the use of the cleanup attribute too cumbersome for no real gain. It is
called unconditionally, and it will probably not be used as a common
pattern for new users of a device_node.

There has been some previous work from Dmitry to use the cleanup
facilities for 'fwnode_handle' and mutexes[1][2], which this series
aims to complement for 'device_node'.

Link: https://lore.kernel.org/linux-input/20240904044244.1042174-1-dmitry.torokhov@gmail.com/ [1]
Link: https://lore.kernel.org/linux-input/20240825051627.2848495-1-dmitry.torokhov@gmail.com/ [2]

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Javier Carrasco (10):
      Input: cap11xx - switch to for_each_child_of_node_scoped
      Input: mtk-pmic-keys - switch to for_each_child_of_node_scoped
      Input: sun4i-lradc-keys - switch to for_each_child_of_node_scoped
      Input: twl6040-vibra - use cleanup facility for device_node
      Input: twl4030-vibra - use cleanup facility for device_node
      Input: sparcspkr - use cleanup facility for device_node
      Input: 88pm860x - use cleanup facility for device_node
      Input: i8042 - use cleanup facility for device_node
      Input: raspberrypi-ts - use cleanup facility for device_node
      Input: ts4800-ts - use cleanup facility for device_node

 drivers/input/keyboard/cap11xx.c           | 12 ++++--------
 drivers/input/keyboard/mtk-pmic-keys.c     | 17 +++++------------
 drivers/input/keyboard/sun4i-lradc-keys.c  |  7 ++-----
 drivers/input/misc/sparcspkr.c             |  4 +---
 drivers/input/misc/twl4030-vibra.c         | 11 +++--------
 drivers/input/misc/twl6040-vibra.c         |  8 ++------
 drivers/input/serio/i8042-sparcio.h        |  6 +-----
 drivers/input/touchscreen/88pm860x-ts.c    | 20 +++++++-------------
 drivers/input/touchscreen/raspberrypi-ts.c |  4 +---
 drivers/input/touchscreen/ts4800-ts.c      |  5 ++---
 10 files changed, 28 insertions(+), 66 deletions(-)
---
base-commit: 515ef92b4939fa51f9f1ee278618e2d419b0b8b0
change-id: 20241009-input_automate_of_node_put-1bae9f5c02d9

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2024-10-20  4:20 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-10 21:25 [PATCH 00/10] input: automate of_node_put() calls for device_node Javier Carrasco
2024-10-10 21:25 ` [PATCH 01/10] Input: cap11xx - switch to for_each_child_of_node_scoped Javier Carrasco
2024-10-20  3:59   ` Dmitry Torokhov
2024-10-10 21:25 ` [PATCH 02/10] Input: mtk-pmic-keys " Javier Carrasco
2024-10-20  4:00   ` Dmitry Torokhov
2024-10-10 21:25 ` [PATCH 03/10] Input: sun4i-lradc-keys " Javier Carrasco
2024-10-11 10:36   ` Andre Przywara
2024-10-20  4:02   ` Dmitry Torokhov
2024-10-10 21:25 ` [PATCH 04/10] Input: twl6040-vibra - use cleanup facility for device_node Javier Carrasco
2024-10-20  4:09   ` Dmitry Torokhov
2024-10-10 21:25 ` [PATCH 05/10] Input: twl4030-vibra " Javier Carrasco
2024-10-20  4:09   ` Dmitry Torokhov
2024-10-10 21:25 ` [PATCH 06/10] Input: sparcspkr " Javier Carrasco
2024-10-10 21:43   ` Al Viro
2024-10-10 22:01     ` Javier Carrasco
2024-10-10 22:09       ` Javier Carrasco
2024-10-10 22:22         ` Al Viro
2024-10-10 22:28           ` Javier Carrasco
2024-10-10 21:25 ` [PATCH 07/10] Input: 88pm860x " Javier Carrasco
2024-10-20  4:19   ` Dmitry Torokhov
2024-10-10 21:25 ` [PATCH 08/10] Input: i8042 " Javier Carrasco
2024-10-20  4:19   ` Dmitry Torokhov
2024-10-10 21:25 ` [PATCH 09/10] Input: raspberrypi-ts " Javier Carrasco
2024-10-20  4:20   ` Dmitry Torokhov
2024-10-10 21:26 ` [PATCH 10/10] Input: ts4800-ts " Javier Carrasco
2024-10-20  4:20   ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).