All of lore.kernel.org
 help / color / mirror / Atom feed
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 v3] usb: typec: anx7411: fix OF node reference leaks in anx7411_typec_switch_probe()
Date: Mon, 25 Nov 2024 13:16:03 +0200	[thread overview]
Message-ID: <Z0Rcc3_E25-2KJaw@kuha.fi.intel.com> (raw)
In-Reply-To: <20241121023914.1194333-1-joe@pf.is.s.u-tokyo.ac.jp>

Hi,

Sorry to keep you waiting.

On Thu, Nov 21, 2024 at 11:39:14AM +0900, Joe Hattori wrote:
> The refcounts of the OF nodes obtained in by of_get_child_by_name()
> calls in anx7411_typec_switch_probe() are not decremented. Add
> additional device_node fields to anx7411_data, and call of_node_put() on
> them in the error path and in the unregister functions.
> 
> Fixes: e45d7337dc0e ("usb: typec: anx7411: Use of_get_child_by_name() instead of of_find_node_by_name()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> ---
> Changes in v3:
> - Add new fields to anx7411_data.
> - Remove an unnecessary include.
> ---
>  drivers/usb/typec/anx7411.c | 19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
> index 95607efb9f7e..e714b04399fa 100644
> --- a/drivers/usb/typec/anx7411.c
> +++ b/drivers/usb/typec/anx7411.c
> @@ -290,6 +290,8 @@ struct anx7411_data {
>  	struct power_supply *psy;
>  	struct power_supply_desc psy_desc;
>  	struct device *dev;
> +	struct device_node *switch_node;
> +	struct device_node *mux_node;

Please make these fwnodes.

>  };
>  
>  static u8 snk_identity[] = {
> @@ -1099,6 +1101,7 @@ static void anx7411_unregister_mux(struct anx7411_data *ctx)
>  	if (ctx->typec.typec_mux) {
>  		typec_mux_unregister(ctx->typec.typec_mux);
>  		ctx->typec.typec_mux = NULL;
> +		of_node_put(ctx->mux_node);

fwnode_handle_put(ctx->mux_node);

>  	}
>  }
>  
> @@ -1107,6 +1110,7 @@ static void anx7411_unregister_switch(struct anx7411_data *ctx)
>  	if (ctx->typec.typec_switch) {
>  		typec_switch_unregister(ctx->typec.typec_switch);
>  		ctx->typec.typec_switch = NULL;
> +		of_node_put(ctx->switch_node);

fwnode_handle_put(ctx->switch_node);

>  	}
>  }
>  
> @@ -1114,28 +1118,29 @@ static int anx7411_typec_switch_probe(struct anx7411_data *ctx,
>  				      struct device *dev)
>  {
>  	int ret;
> -	struct device_node *node;
>  
> -	node = of_get_child_by_name(dev->of_node, "orientation_switch");
> -	if (!node)
> +	ctx->switch_node = of_get_child_by_name(dev->of_node, "orientation_switch");

ctx->switch_node = device_get_named_child_node(dev, "orientation_switch");

> +	if (!ctx->switch_node)
>  		return 0;
>  
> -	ret = anx7411_register_switch(ctx, dev, &node->fwnode);
> +	ret = anx7411_register_switch(ctx, dev, &ctx->switch_node->fwnode);
>  	if (ret) {
>  		dev_err(dev, "failed register switch");
> +		of_node_put(ctx->switch_node);
>  		return ret;
>  	}
>  
> -	node = of_get_child_by_name(dev->of_node, "mode_switch");
> -	if (!node) {
> +	ctx->mux_node = of_get_child_by_name(dev->of_node, "mode_switch");

ctx->mux_node = device_get_named_child_node(dev, "mode_switch");

> +	if (!ctx->mux_node) {
>  		dev_err(dev, "no typec mux exist");
>  		ret = -ENODEV;
>  		goto unregister_switch;
>  	}
>  
> -	ret = anx7411_register_mux(ctx, dev, &node->fwnode);
> +	ret = anx7411_register_mux(ctx, dev, &ctx->mux_node->fwnode);
>  	if (ret) {
>  		dev_err(dev, "failed register mode switch");
> +		of_node_put(ctx->mux_node);
>  		ret = -ENODEV;
>  		goto unregister_switch;
>  	}

thanks,

-- 
heikki

  reply	other threads:[~2024-11-25 11:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-21  2:39 [PATCH v3] usb: typec: anx7411: fix OF node reference leaks in anx7411_typec_switch_probe() Joe Hattori
2024-11-25 11:16 ` Heikki Krogerus [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-11-26  1:49 Joe Hattori
2024-11-26  9:27 ` Heikki Krogerus

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=Z0Rcc3_E25-2KJaw@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.