public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 02/13] USB: ULPI: fix memory leak with using debugfs_lookup()
Date: Fri, 3 Feb 2023 11:05:55 +0200	[thread overview]
Message-ID: <Y9zOc+MeD+LbAdi8@kuha.fi.intel.com> (raw)
In-Reply-To: <20230202153235.2412790-2-gregkh@linuxfoundation.org>

On Thu, Feb 02, 2023 at 04:32:24PM +0100, Greg Kroah-Hartman wrote:
> When calling debugfs_lookup() the result must have dput() called on it,
> otherwise the memory will leak over time.  To make things simpler, just
> call debugfs_lookup_and_remove() instead which handles all of the logic
> at once.
> 
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/common/ulpi.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
> index 67b780b256a9..a98b2108376a 100644
> --- a/drivers/usb/common/ulpi.c
> +++ b/drivers/usb/common/ulpi.c
> @@ -271,7 +271,7 @@ static int ulpi_regs_show(struct seq_file *seq, void *data)
>  }
>  DEFINE_SHOW_ATTRIBUTE(ulpi_regs);
>  
> -#define ULPI_ROOT debugfs_lookup(KBUILD_MODNAME, NULL)
> +static struct dentry *ulpi_root;
>  
>  static int ulpi_register(struct device *dev, struct ulpi *ulpi)
>  {
> @@ -301,7 +301,7 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)
>  		return ret;
>  	}
>  
> -	root = debugfs_create_dir(dev_name(dev), ULPI_ROOT);
> +	root = debugfs_create_dir(dev_name(dev), ulpi_root);
>  	debugfs_create_file("regs", 0444, root, ulpi, &ulpi_regs_fops);
>  
>  	dev_dbg(&ulpi->dev, "registered ULPI PHY: vendor %04x, product %04x\n",
> @@ -349,8 +349,7 @@ EXPORT_SYMBOL_GPL(ulpi_register_interface);
>   */
>  void ulpi_unregister_interface(struct ulpi *ulpi)
>  {
> -	debugfs_remove_recursive(debugfs_lookup(dev_name(&ulpi->dev),
> -						ULPI_ROOT));
> +	debugfs_lookup_and_remove(dev_name(&ulpi->dev), ulpi_root);
>  	device_unregister(&ulpi->dev);
>  }
>  EXPORT_SYMBOL_GPL(ulpi_unregister_interface);
> @@ -360,12 +359,11 @@ EXPORT_SYMBOL_GPL(ulpi_unregister_interface);
>  static int __init ulpi_init(void)
>  {
>  	int ret;
> -	struct dentry *root;
>  
> -	root = debugfs_create_dir(KBUILD_MODNAME, NULL);
> +	ulpi_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
>  	ret = bus_register(&ulpi_bus);
>  	if (ret)
> -		debugfs_remove(root);
> +		debugfs_remove(ulpi_root);
>  	return ret;
>  }
>  subsys_initcall(ulpi_init);
> @@ -373,7 +371,7 @@ subsys_initcall(ulpi_init);
>  static void __exit ulpi_exit(void)
>  {
>  	bus_unregister(&ulpi_bus);
> -	debugfs_remove_recursive(ULPI_ROOT);
> +	debugfs_remove(ulpi_root);
>  }
>  module_exit(ulpi_exit);
>  
> -- 
> 2.39.1

-- 
heikki

  reply	other threads:[~2023-02-03  9:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 15:32 [PATCH 01/13] USB: chipidea: fix memory leak with using debugfs_lookup() Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 02/13] USB: ULPI: " Greg Kroah-Hartman
2023-02-03  9:05   ` Heikki Krogerus [this message]
2023-02-02 15:32 ` [PATCH 03/13] USB: uhci: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 04/13] USB: sl811: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 05/13] USB: fotg210: " Greg Kroah-Hartman
2023-02-02 22:15   ` Linus Walleij
2023-02-02 15:32 ` [PATCH 06/13] USB: isp116x: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 07/13] USB: isp1362: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 08/13] USB: gadget: gr_udc: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 09/13] USB: gadget: bcm63xx_udc: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 10/13] USB: gadget: lpc32xx_udc: " Greg Kroah-Hartman
2023-02-02 16:24   ` Vladimir Zapolskiy
2023-02-02 15:32 ` [PATCH 11/13] USB: gadget: pxa25x_udc: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 12/13] USB: gadget: pxa27x_udc: " Greg Kroah-Hartman
2023-02-02 15:32 ` [PATCH 13/13] USB: gadget: s3c2410_udc: " Greg Kroah-Hartman
2023-02-03  8:20   ` Krzysztof Kozlowski
2023-02-06  9:57     ` Greg Kroah-Hartman
2023-02-10  8:51 ` [PATCH 01/13] USB: chipidea: " Peter Chen

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=Y9zOc+MeD+LbAdi8@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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