* [PATCH] i2c: npcm7xx: Fix error handling in npcm_i2c_init()
@ 2022-11-09 11:22 Yuan Can
2022-11-09 13:34 ` Tali Perry
2022-11-12 20:27 ` Wolfram Sang
0 siblings, 2 replies; 3+ messages in thread
From: Yuan Can @ 2022-11-09 11:22 UTC (permalink / raw)
To: avifishman70, tmaimon77, tali.perry1, venture, yuenn,
benjaminfair, wsa, andriy.shevchenko, openbmc, linux-i2c
Cc: yuancan
A problem about i2c-npcm7xx create debugfs failed is triggered with the
following log given:
[ 173.827310] debugfs: Directory 'npcm_i2c' with parent '/' already present!
The reason is that npcm_i2c_init() returns platform_driver_register()
directly without checking its return value, if platform_driver_register()
failed, it returns without destroy the newly created debugfs, resulting
the debugfs of npcm_i2c can never be created later.
npcm_i2c_init()
debugfs_create_dir() # create debugfs directory
platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened
# return without destroy debugfs directory
Fix by removing debugfs when platform_driver_register() returns error.
Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
drivers/i2c/busses/i2c-npcm7xx.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
index 0c365b57d957..83457359ec45 100644
--- a/drivers/i2c/busses/i2c-npcm7xx.c
+++ b/drivers/i2c/busses/i2c-npcm7xx.c
@@ -2393,8 +2393,17 @@ static struct platform_driver npcm_i2c_bus_driver = {
static int __init npcm_i2c_init(void)
{
+ int ret;
+
npcm_i2c_debugfs_dir = debugfs_create_dir("npcm_i2c", NULL);
- return platform_driver_register(&npcm_i2c_bus_driver);
+
+ ret = platform_driver_register(&npcm_i2c_bus_driver);
+ if (ret) {
+ debugfs_remove_recursive(npcm_i2c_debugfs_dir);
+ return ret;
+ }
+
+ return 0;
}
module_init(npcm_i2c_init);
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: npcm7xx: Fix error handling in npcm_i2c_init()
2022-11-09 11:22 [PATCH] i2c: npcm7xx: Fix error handling in npcm_i2c_init() Yuan Can
@ 2022-11-09 13:34 ` Tali Perry
2022-11-12 20:27 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Tali Perry @ 2022-11-09 13:34 UTC (permalink / raw)
To: Yuan Can
Cc: avifishman70, tmaimon77, venture, yuenn, benjaminfair, wsa,
andriy.shevchenko, openbmc, linux-i2c
On Wed, Nov 9, 2022 at 1:24 PM Yuan Can <yuancan@huawei.com> wrote:
>
> A problem about i2c-npcm7xx create debugfs failed is triggered with the
> following log given:
>
> [ 173.827310] debugfs: Directory 'npcm_i2c' with parent '/' already present!
>
> The reason is that npcm_i2c_init() returns platform_driver_register()
> directly without checking its return value, if platform_driver_register()
> failed, it returns without destroy the newly created debugfs, resulting
> the debugfs of npcm_i2c can never be created later.
>
> npcm_i2c_init()
> debugfs_create_dir() # create debugfs directory
> platform_driver_register()
> driver_register()
> bus_add_driver()
> priv = kzalloc(...) # OOM happened
> # return without destroy debugfs directory
>
> Fix by removing debugfs when platform_driver_register() returns error.
>
> Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
> drivers/i2c/busses/i2c-npcm7xx.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c
> index 0c365b57d957..83457359ec45 100644
> --- a/drivers/i2c/busses/i2c-npcm7xx.c
> +++ b/drivers/i2c/busses/i2c-npcm7xx.c
> @@ -2393,8 +2393,17 @@ static struct platform_driver npcm_i2c_bus_driver = {
>
> static int __init npcm_i2c_init(void)
> {
> + int ret;
> +
> npcm_i2c_debugfs_dir = debugfs_create_dir("npcm_i2c", NULL);
> - return platform_driver_register(&npcm_i2c_bus_driver);
> +
> + ret = platform_driver_register(&npcm_i2c_bus_driver);
> + if (ret) {
> + debugfs_remove_recursive(npcm_i2c_debugfs_dir);
> + return ret;
> + }
> +
> + return 0;
> }
> module_init(npcm_i2c_init);
>
> --
> 2.17.1
>
Thanks Yuan!
Reviewed-by: Tali Perry <tali.perry@nuvoton.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: npcm7xx: Fix error handling in npcm_i2c_init()
2022-11-09 11:22 [PATCH] i2c: npcm7xx: Fix error handling in npcm_i2c_init() Yuan Can
2022-11-09 13:34 ` Tali Perry
@ 2022-11-12 20:27 ` Wolfram Sang
1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2022-11-12 20:27 UTC (permalink / raw)
To: Yuan Can
Cc: avifishman70, tmaimon77, tali.perry1, venture, yuenn,
benjaminfair, andriy.shevchenko, openbmc, linux-i2c
[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]
On Wed, Nov 09, 2022 at 11:22:50AM +0000, Yuan Can wrote:
> A problem about i2c-npcm7xx create debugfs failed is triggered with the
> following log given:
>
> [ 173.827310] debugfs: Directory 'npcm_i2c' with parent '/' already present!
>
> The reason is that npcm_i2c_init() returns platform_driver_register()
> directly without checking its return value, if platform_driver_register()
> failed, it returns without destroy the newly created debugfs, resulting
> the debugfs of npcm_i2c can never be created later.
>
> npcm_i2c_init()
> debugfs_create_dir() # create debugfs directory
> platform_driver_register()
> driver_register()
> bus_add_driver()
> priv = kzalloc(...) # OOM happened
> # return without destroy debugfs directory
>
> Fix by removing debugfs when platform_driver_register() returns error.
>
> Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
Applied to for-current, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-12 20:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09 11:22 [PATCH] i2c: npcm7xx: Fix error handling in npcm_i2c_init() Yuan Can
2022-11-09 13:34 ` Tali Perry
2022-11-12 20:27 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox