From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] usb: typec: anx7411: fix fwnode_handle reference leak
Date: Tue, 19 Nov 2024 17:08:37 +0200 [thread overview]
Message-ID: <Zzyp9cSIoqNBFpFa@kuha.fi.intel.com> (raw)
In-Reply-To: <20241116085124.3832328-1-joe@pf.is.s.u-tokyo.ac.jp>
On Sat, Nov 16, 2024 at 05:51:24PM +0900, Joe Hattori wrote:
> An fwnode_handle is obtained with an incremented refcount in
> anx7411_typec_port_probe(), however the refcount is not decremented in
> the error path or in the .remove() function. Therefore call
> fwnode_handle_put() accordingly.
>
> Fixes: fe6d8a9c8e64 ("usb: typec: anx7411: Add Analogix PD ANX7411 support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> ---
> drivers/usb/typec/anx7411.c | 33 ++++++++++++++++++++++-----------
> 1 file changed, 22 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
> index 7e61c3ac8777..d3c5d8f410ca 100644
> --- a/drivers/usb/typec/anx7411.c
> +++ b/drivers/usb/typec/anx7411.c
> @@ -1023,6 +1023,12 @@ static void anx7411_port_unregister_altmodes(struct typec_altmode **adev)
> }
> }
>
> +static void anx7411_port_unregister(struct typec_params *typecp)
> +{
> + fwnode_handle_put(typecp->caps.fwnode);
> + anx7411_port_unregister_altmodes(typecp->port_amode);
> +}
Why not remove the port here while at it.
Otherwise this LGTM.
> static int anx7411_usb_mux_set(struct typec_mux_dev *mux,
> struct typec_mux_state *state)
> {
> @@ -1158,34 +1164,34 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
> ret = fwnode_property_read_string(fwnode, "power-role", &buf);
> if (ret) {
> dev_err(dev, "power-role not found: %d\n", ret);
> - return ret;
> + goto put_fwnode;
> }
>
> ret = typec_find_port_power_role(buf);
> if (ret < 0)
> - return ret;
> + goto put_fwnode;
> cap->type = ret;
>
> ret = fwnode_property_read_string(fwnode, "data-role", &buf);
> if (ret) {
> dev_err(dev, "data-role not found: %d\n", ret);
> - return ret;
> + goto put_fwnode;
> }
>
> ret = typec_find_port_data_role(buf);
> if (ret < 0)
> - return ret;
> + goto put_fwnode;
> cap->data = ret;
>
> ret = fwnode_property_read_string(fwnode, "try-power-role", &buf);
> if (ret) {
> dev_err(dev, "try-power-role not found: %d\n", ret);
> - return ret;
> + goto put_fwnode;
> }
>
> ret = typec_find_power_role(buf);
> if (ret < 0)
> - return ret;
> + goto put_fwnode;
> cap->prefer_role = ret;
>
> /* Get source pdos */
> @@ -1197,7 +1203,7 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
> typecp->src_pdo_nr);
> if (ret < 0) {
> dev_err(dev, "source cap validate failed: %d\n", ret);
> - return -EINVAL;
> + goto put_fwnode;
> }
>
> typecp->caps_flags |= HAS_SOURCE_CAP;
> @@ -1211,7 +1217,7 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
> typecp->sink_pdo_nr);
> if (ret < 0) {
> dev_err(dev, "sink cap validate failed: %d\n", ret);
> - return -EINVAL;
> + goto put_fwnode;
> }
>
> for (i = 0; i < typecp->sink_pdo_nr; i++) {
> @@ -1255,13 +1261,18 @@ static int anx7411_typec_port_probe(struct anx7411_data *ctx,
> ret = PTR_ERR(ctx->typec.port);
> ctx->typec.port = NULL;
> dev_err(dev, "Failed to register type c port %d\n", ret);
> - return ret;
> + goto put_fwnode;
> }
>
> typec_port_register_altmodes(ctx->typec.port, NULL, ctx,
> ctx->typec.port_amode,
> MAX_ALTMODE);
> return 0;
> +
> +put_fwnode:
> + fwnode_handle_put(fwnode);
> +
> + return ret;
> }
>
> static int anx7411_typec_check_connection(struct anx7411_data *ctx)
> @@ -1528,7 +1539,7 @@ static int anx7411_i2c_probe(struct i2c_client *client)
>
> free_typec_port:
> typec_unregister_port(plat->typec.port);
> - anx7411_port_unregister_altmodes(plat->typec.port_amode);
> + anx7411_port_unregister(&plat->typec);
>
> free_typec_switch:
> anx7411_unregister_switch(plat);
> @@ -1562,7 +1573,7 @@ static void anx7411_i2c_remove(struct i2c_client *client)
> if (plat->typec.port)
> typec_unregister_port(plat->typec.port);
>
> - anx7411_port_unregister_altmodes(plat->typec.port_amode);
> + anx7411_port_unregister(&plat->typec);
> }
>
> static const struct i2c_device_id anx7411_id[] = {
thanks,
--
heikki
prev parent reply other threads:[~2024-11-19 15:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-16 8:51 [PATCH] usb: typec: anx7411: fix fwnode_handle reference leak Joe Hattori
2024-11-19 15:08 ` Heikki Krogerus [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zzyp9cSIoqNBFpFa@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=joe@pf.is.s.u-tokyo.ac.jp \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).