ntb.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Serge Semin <fancer.lancer@gmail.com>
To: Yuan Can <yuancan@huawei.com>
Cc: jdmason@kudzu.us, dave.jiang@intel.com, allenbh@gmail.com,
	ntb@lists.linux.dev
Subject: Re: [PATCH] ntb: idt: Fix error handling in idt_pci_driver_init()
Date: Thu, 9 Mar 2023 15:21:16 +0300	[thread overview]
Message-ID: <20230309122116.dd77crokt2rmmbuw@mobilestation> (raw)
In-Reply-To: <20221105094301.106276-1-yuancan@huawei.com>

On Sat, Nov 05, 2022 at 09:43:01AM +0000, Yuan Can wrote:
> A problem about ntb_hw_idt create debugfs failed is triggered with the
> following log given:
> 
>  [ 1236.637636] IDT PCI-E Non-Transparent Bridge Driver 2.0
>  [ 1236.639292] debugfs: Directory 'ntb_hw_idt' with parent '/' already present!
> 
> The reason is that idt_pci_driver_init() returns pci_register_driver()
> directly without checking its return value, if pci_register_driver()
> failed, it returns without destroy the newly created debugfs, resulting
> the debugfs of ntb_hw_idt can never be created later.
> 
>  idt_pci_driver_init()
>    debugfs_create_dir() # create debugfs directory
>    pci_register_driver()
>      driver_register()
>        bus_add_driver()
>          priv = kzalloc(...) # OOM happened
>    # return without destroy debugfs directory
> 
> Fix by removing debugfs when pci_register_driver() returns error.

Indeed. Thanks for the patch.
Acked-by: Serge Semin <fancer.lancer@gmail.com>

-Serge(y)

> 
> Fixes: bf2a952d31d2 ("NTB: Add IDT 89HPESxNTx PCIe-switches support")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/ntb/hw/idt/ntb_hw_idt.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/ntb/hw/idt/ntb_hw_idt.c b/drivers/ntb/hw/idt/ntb_hw_idt.c
> index 0ed6f809ff2e..51799fccf840 100644
> --- a/drivers/ntb/hw/idt/ntb_hw_idt.c
> +++ b/drivers/ntb/hw/idt/ntb_hw_idt.c
> @@ -2891,6 +2891,7 @@ static struct pci_driver idt_pci_driver = {
>  
>  static int __init idt_pci_driver_init(void)
>  {
> +	int ret;
>  	pr_info("%s %s\n", NTB_DESC, NTB_VER);
>  
>  	/* Create the top DebugFS directory if the FS is initialized */
> @@ -2898,7 +2899,11 @@ static int __init idt_pci_driver_init(void)
>  		dbgfs_topdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
>  
>  	/* Register the NTB hardware driver to handle the PCI device */
> -	return pci_register_driver(&idt_pci_driver);
> +	ret = pci_register_driver(&idt_pci_driver);
> +	if (ret)
> +		debugfs_remove_recursive(dbgfs_topdir);
> +
> +	return ret;
>  }
>  module_init(idt_pci_driver_init);
>  
> -- 
> 2.17.1
> 

      reply	other threads:[~2023-03-09 12:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-05  9:43 [PATCH] ntb: idt: Fix error handling in idt_pci_driver_init() Yuan Can
2023-03-09 12:21 ` Serge Semin [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=20230309122116.dd77crokt2rmmbuw@mobilestation \
    --to=fancer.lancer@gmail.com \
    --cc=allenbh@gmail.com \
    --cc=dave.jiang@intel.com \
    --cc=jdmason@kudzu.us \
    --cc=ntb@lists.linux.dev \
    --cc=yuancan@huawei.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).