From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Yuan Can <yuancan@huawei.com>
Cc: michael.jamet@intel.com, YehezkelShB@gmail.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, andriy.shevchenko@linux.intel.com,
amir.jer.levy@intel.com, netdev@vger.kernel.org
Subject: Re: [PATCH] net: thunderbolt: Fix error handling in tbnet_init()
Date: Mon, 14 Nov 2022 12:09:49 +0200 [thread overview]
Message-ID: <Y3IT7aiOOe2b3Qhy@black.fi.intel.com> (raw)
In-Reply-To: <20221114081936.35804-1-yuancan@huawei.com>
Hi,
On Mon, Nov 14, 2022 at 08:19:36AM +0000, Yuan Can wrote:
> A problem about insmod thunderbolt-net failed is triggered with following
> log given while lsmod does not show thunderbolt_net:
>
> insmod: ERROR: could not insert module thunderbolt-net.ko: File exists
>
> The reason is that tbnet_init() returns tb_register_service_driver()
> directly without checking its return value, if tb_register_service_driver()
> failed, it returns without removing property directory, resulting the
> property directory can never be created later.
>
> tbnet_init()
> tb_register_property_dir() # register property directory
> tb_register_service_driver()
> driver_register()
> bus_add_driver()
> priv = kzalloc(...) # OOM happened
> # return without remove property directory
>
> Fix by remove property directory when tb_register_service_driver() returns
> error.
>
> Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
> drivers/net/thunderbolt.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/thunderbolt.c b/drivers/net/thunderbolt.c
> index 83fcaeb2ac5e..fe6a9881cc75 100644
> --- a/drivers/net/thunderbolt.c
> +++ b/drivers/net/thunderbolt.c
> @@ -1396,7 +1396,14 @@ static int __init tbnet_init(void)
> return ret;
> }
>
> - return tb_register_service_driver(&tbnet_driver);
> + ret = tb_register_service_driver(&tbnet_driver);
> + if (ret) {
> + tb_unregister_property_dir("network", tbnet_dir);
> + tb_property_free_dir(tbnet_dir);
> + return ret;
> + }
> +
> + return 0;
Okay but I suggest that you make it like:
ret = tb_register_property_dir("network", tbnet_dir);
if (ret)
goto err_free_dir;
ret = tb_register_service_driver(&tbnet_driver);
if (ret)
goto err_unregister;
return 0;
err_unregister:
tb_unregister_property_dir("network", tbnet_dir);
err_free_dir:
tb_property_free_dir(tbnet_dir);
return ret;
}
next prev parent reply other threads:[~2022-11-14 10:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 8:19 [PATCH] net: thunderbolt: Fix error handling in tbnet_init() Yuan Can
2022-11-14 10:09 ` Mika Westerberg [this message]
2022-11-14 12:06 ` Yuan Can
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=Y3IT7aiOOe2b3Qhy@black.fi.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=amir.jer.levy@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=michael.jamet@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--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 NNTP newsgroup(s).