* [PATCH v2 0/2] usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes()
@ 2024-10-21 20:45 Javier Carrasco
2024-10-21 20:45 ` [PATCH v2 1/2] " Javier Carrasco
2024-10-21 20:45 ` [PATCH v2 2/2] usb: typec: use cleanup facility for 'altmodes_node' Javier Carrasco
0 siblings, 2 replies; 4+ messages in thread
From: Javier Carrasco @ 2024-10-21 20:45 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, Hans de Goede
Cc: linux-usb, linux-kernel, Javier Carrasco, stable
The first patch simply adds the missing call to fwnode_handle_put() when
the node is no longer required to make it compatible with stable kernels
that don't support the cleanup attribute in its current form. The second
patch adds the __free() macro to make the code more robust and avoid
similar issues in the future.
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Changes in v2:
- Add patch for the automatic cleanup facility.
- Link to v1: https://lore.kernel.org/r/20241019-typec-class-fwnode_handle_put-v1-1-a3b5a0a02795@gmail.com
---
Javier Carrasco (2):
usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes()
usb: typec: use cleanup facility for 'altmodes_node'
drivers/usb/typec/class.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
---
base-commit: f2493655d2d3d5c6958ed996b043c821c23ae8d3
change-id: 20241019-typec-class-fwnode_handle_put-b3648f5bc51b
Best regards,
--
Javier Carrasco <javier.carrasco.cruz@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 1/2] usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes() 2024-10-21 20:45 [PATCH v2 0/2] usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes() Javier Carrasco @ 2024-10-21 20:45 ` Javier Carrasco 2024-10-21 20:45 ` [PATCH v2 2/2] usb: typec: use cleanup facility for 'altmodes_node' Javier Carrasco 1 sibling, 0 replies; 4+ messages in thread From: Javier Carrasco @ 2024-10-21 20:45 UTC (permalink / raw) To: Heikki Krogerus, Greg Kroah-Hartman, Hans de Goede Cc: linux-usb, linux-kernel, Javier Carrasco, stable The 'altmodes_node' fwnode_handle is never released after it is no longer required, which leaks the resource. Add the required call to fwnode_handle_put() when 'altmodes_node' is no longer required. Cc: stable@vger.kernel.org Fixes: 7b458a4c5d73 ("usb: typec: Add typec_port_register_altmodes()") Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com> --- drivers/usb/typec/class.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index d61b4c74648d..1eb240604cf6 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -2341,6 +2341,7 @@ void typec_port_register_altmodes(struct typec_port *port, altmodes[index] = alt; index++; } + fwnode_handle_put(altmodes_node); } EXPORT_SYMBOL_GPL(typec_port_register_altmodes); -- 2.43.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] usb: typec: use cleanup facility for 'altmodes_node' 2024-10-21 20:45 [PATCH v2 0/2] usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes() Javier Carrasco 2024-10-21 20:45 ` [PATCH v2 1/2] " Javier Carrasco @ 2024-10-21 20:45 ` Javier Carrasco 2024-10-22 14:12 ` Heikki Krogerus 1 sibling, 1 reply; 4+ messages in thread From: Javier Carrasco @ 2024-10-21 20:45 UTC (permalink / raw) To: Heikki Krogerus, Greg Kroah-Hartman, Hans de Goede Cc: linux-usb, linux-kernel, Javier Carrasco Use the __free() macro for 'altmodes_node' to automatically release the node when it goes out of scope, removing the need for explicit calls to fwnode_handle_put(). Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com> --- drivers/usb/typec/class.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 1eb240604cf6..58f40156de56 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -2293,7 +2293,7 @@ void typec_port_register_altmodes(struct typec_port *port, const struct typec_altmode_ops *ops, void *drvdata, struct typec_altmode **altmodes, size_t n) { - struct fwnode_handle *altmodes_node, *child; + struct fwnode_handle *child; struct typec_altmode_desc desc; struct typec_altmode *alt; size_t index = 0; @@ -2301,7 +2301,9 @@ void typec_port_register_altmodes(struct typec_port *port, u32 vdo; int ret; - altmodes_node = device_get_named_child_node(&port->dev, "altmodes"); + struct fwnode_handle *altmodes_node __free(fwnode_handle) = + device_get_named_child_node(&port->dev, "altmodes"); + if (!altmodes_node) return; /* No altmodes specified */ @@ -2341,7 +2343,6 @@ void typec_port_register_altmodes(struct typec_port *port, altmodes[index] = alt; index++; } - fwnode_handle_put(altmodes_node); } EXPORT_SYMBOL_GPL(typec_port_register_altmodes); -- 2.43.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] usb: typec: use cleanup facility for 'altmodes_node' 2024-10-21 20:45 ` [PATCH v2 2/2] usb: typec: use cleanup facility for 'altmodes_node' Javier Carrasco @ 2024-10-22 14:12 ` Heikki Krogerus 0 siblings, 0 replies; 4+ messages in thread From: Heikki Krogerus @ 2024-10-22 14:12 UTC (permalink / raw) To: Javier Carrasco Cc: Greg Kroah-Hartman, Hans de Goede, linux-usb, linux-kernel On Mon, Oct 21, 2024 at 10:45:30PM +0200, Javier Carrasco wrote: > Use the __free() macro for 'altmodes_node' to automatically release the > node when it goes out of scope, removing the need for explicit calls to > fwnode_handle_put(). > > Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> > --- > drivers/usb/typec/class.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index 1eb240604cf6..58f40156de56 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -2293,7 +2293,7 @@ void typec_port_register_altmodes(struct typec_port *port, > const struct typec_altmode_ops *ops, void *drvdata, > struct typec_altmode **altmodes, size_t n) > { > - struct fwnode_handle *altmodes_node, *child; > + struct fwnode_handle *child; > struct typec_altmode_desc desc; > struct typec_altmode *alt; > size_t index = 0; > @@ -2301,7 +2301,9 @@ void typec_port_register_altmodes(struct typec_port *port, > u32 vdo; > int ret; > > - altmodes_node = device_get_named_child_node(&port->dev, "altmodes"); > + struct fwnode_handle *altmodes_node __free(fwnode_handle) = > + device_get_named_child_node(&port->dev, "altmodes"); > + > if (!altmodes_node) > return; /* No altmodes specified */ > > @@ -2341,7 +2343,6 @@ void typec_port_register_altmodes(struct typec_port *port, > altmodes[index] = alt; > index++; > } > - fwnode_handle_put(altmodes_node); > } > EXPORT_SYMBOL_GPL(typec_port_register_altmodes); > -- heikki ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-22 14:12 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-10-21 20:45 [PATCH v2 0/2] usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes() Javier Carrasco 2024-10-21 20:45 ` [PATCH v2 1/2] " Javier Carrasco 2024-10-21 20:45 ` [PATCH v2 2/2] usb: typec: use cleanup facility for 'altmodes_node' Javier Carrasco 2024-10-22 14:12 ` Heikki Krogerus
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®