* [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init()
@ 2025-10-22 9:18 Ma Ke
2025-10-22 15:19 ` Eddie James
0 siblings, 1 reply; 6+ messages in thread
From: Ma Ke @ 2025-10-22 9:18 UTC (permalink / raw)
To: eajames, ninad, joel, jk; +Cc: linux-fsi, linux-kernel, akpm, Ma Ke, stable
Once cdev_device_add() failed, we should use put_device() to decrement
reference count for cleanup. Or it could cause memory leak. Although
operations in err_free_ida are similar to the operations in callback
function fsi_slave_release(), put_device() is a correct handling
operation as comments require when cdev_device_add() fails.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 371975b0b075 ("fsi/core: Fix error paths on CFAM init")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/fsi/fsi-core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index c6c115993ebc..444878ab9fb1 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1084,7 +1084,8 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
rc = cdev_device_add(&slave->cdev, &slave->dev);
if (rc) {
dev_err(&slave->dev, "Error %d creating slave device\n", rc);
- goto err_free_ida;
+ put_device(&slave->dev);
+ return rc;
}
/* Now that we have the cdev registered with the core, any fatal
@@ -1110,8 +1111,6 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
return 0;
-err_free_ida:
- fsi_free_minor(slave->dev.devt);
err_free:
of_node_put(slave->dev.of_node);
kfree(slave);
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init()
2025-10-22 9:18 [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init() Ma Ke
@ 2025-10-22 15:19 ` Eddie James
0 siblings, 0 replies; 6+ messages in thread
From: Eddie James @ 2025-10-22 15:19 UTC (permalink / raw)
To: Ma Ke, ninad, joel, jk; +Cc: linux-fsi, linux-kernel, akpm, stable
On 10/22/25 4:18 AM, Ma Ke wrote:
> Once cdev_device_add() failed, we should use put_device() to decrement
> reference count for cleanup. Or it could cause memory leak. Although
> operations in err_free_ida are similar to the operations in callback
> function fsi_slave_release(), put_device() is a correct handling
> operation as comments require when cdev_device_add() fails.
>
> As comment of device_add() says, 'if device_add() succeeds, you should
> call device_del() when you want to get rid of it. If device_add() has
> not succeeded, use only put_device() to drop the reference count'.
>
> Found by code review.
Thanks,
Reviewed-by: Eddie James <eajames@linux.ibm.com>
Tested-by: Eddie James <eajames@linux.ibm.com>
>
> Cc: stable@vger.kernel.org
> Fixes: 371975b0b075 ("fsi/core: Fix error paths on CFAM init")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> drivers/fsi/fsi-core.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
> index c6c115993ebc..444878ab9fb1 100644
> --- a/drivers/fsi/fsi-core.c
> +++ b/drivers/fsi/fsi-core.c
> @@ -1084,7 +1084,8 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
> rc = cdev_device_add(&slave->cdev, &slave->dev);
> if (rc) {
> dev_err(&slave->dev, "Error %d creating slave device\n", rc);
> - goto err_free_ida;
> + put_device(&slave->dev);
> + return rc;
> }
>
> /* Now that we have the cdev registered with the core, any fatal
> @@ -1110,8 +1111,6 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
>
> return 0;
>
> -err_free_ida:
> - fsi_free_minor(slave->dev.devt);
> err_free:
> of_node_put(slave->dev.of_node);
> kfree(slave);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init()
@ 2025-07-18 9:24 Ma Ke
0 siblings, 0 replies; 6+ messages in thread
From: Ma Ke @ 2025-07-18 9:24 UTC (permalink / raw)
To: eajames, ninad, jk, joel; +Cc: akpm, linux-fsi, linux-kernel, Ma Ke, stable
Once cdev_device_add() failed, we should use put_device() to decrement
reference count for cleanup. Or it could cause memory leak. Although
operations in err_free_ida are similar to the operations in callback
function fsi_slave_release(), put_device() is a correct handling
operation as comments require when cdev_device_add() fails.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 371975b0b075 ("fsi/core: Fix error paths on CFAM init")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/fsi/fsi-core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 50e8736039fe..c494fc0bd747 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1084,7 +1084,8 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
rc = cdev_device_add(&slave->cdev, &slave->dev);
if (rc) {
dev_err(&slave->dev, "Error %d creating slave device\n", rc);
- goto err_free_ida;
+ put_device(&slave->dev);
+ return rc;
}
/* Now that we have the cdev registered with the core, any fatal
@@ -1110,8 +1111,6 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
return 0;
-err_free_ida:
- fsi_free_minor(slave->dev.devt);
err_free:
of_node_put(slave->dev.of_node);
kfree(slave);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init()
@ 2025-04-14 9:27 Ma Ke
0 siblings, 0 replies; 6+ messages in thread
From: Ma Ke @ 2025-04-14 9:27 UTC (permalink / raw)
To: eajames, ninad, joel; +Cc: linux-fsi, linux-kernel, akpm, Ma Ke, stable
Once cdev_device_add() failed, we should use put_device() to decrement
reference count for cleanup. Or it could cause memory leak. Although
operations in err_free_ida are similar to the operations in callback
function fsi_slave_release(), put_device() is a correct handling
operation as comments require when cdev_device_add() fails.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 371975b0b075 ("fsi/core: Fix error paths on CFAM init")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/fsi/fsi-core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 50e8736039fe..c494fc0bd747 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1084,7 +1084,8 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
rc = cdev_device_add(&slave->cdev, &slave->dev);
if (rc) {
dev_err(&slave->dev, "Error %d creating slave device\n", rc);
- goto err_free_ida;
+ put_device(&slave->dev);
+ return rc;
}
/* Now that we have the cdev registered with the core, any fatal
@@ -1110,8 +1111,6 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
return 0;
-err_free_ida:
- fsi_free_minor(slave->dev.devt);
err_free:
of_node_put(slave->dev.of_node);
kfree(slave);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init()
@ 2025-04-07 7:37 Ma Ke
0 siblings, 0 replies; 6+ messages in thread
From: Ma Ke @ 2025-04-07 7:37 UTC (permalink / raw)
To: eajames, ninad, joel, jk; +Cc: linux-fsi, linux-kernel, Ma Ke, stable
Once cdev_device_add() failed, we should use put_device() to decrement
reference count for cleanup. Or it could cause memory leak. Although
operations in err_free_ida are similar to the operations in callback
function fsi_slave_release(), put_device() is a correct handling
operation as comments require when cdev_device_add() fails.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 371975b0b075 ("fsi/core: Fix error paths on CFAM init")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/fsi/fsi-core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index 50e8736039fe..c494fc0bd747 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1084,7 +1084,8 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
rc = cdev_device_add(&slave->cdev, &slave->dev);
if (rc) {
dev_err(&slave->dev, "Error %d creating slave device\n", rc);
- goto err_free_ida;
+ put_device(&slave->dev);
+ return rc;
}
/* Now that we have the cdev registered with the core, any fatal
@@ -1110,8 +1111,6 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
return 0;
-err_free_ida:
- fsi_free_minor(slave->dev.devt);
err_free:
of_node_put(slave->dev.of_node);
kfree(slave);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init()
@ 2025-03-31 9:13 Ma Ke
0 siblings, 0 replies; 6+ messages in thread
From: Ma Ke @ 2025-03-31 9:13 UTC (permalink / raw)
To: eajames, ninad, jk, joel; +Cc: linux-fsi, linux-kernel, akpm, Ma Ke, stable
Once cdev_device_add() failed, we should use put_device() to decrement
reference count for cleanup. Or it could cause memory leak. Although
operations in err_free_ida are similar to the operations in callback
function fsi_slave_release(), put_device() is a correct handling
operation as comments require when cdev_device_add() fails.
As comment of device_add() says, 'if device_add() succeeds, you should
call device_del() when you want to get rid of it. If device_add() has
not succeeded, use only put_device() to drop the reference count'.
Found by code review.
Cc: stable@vger.kernel.org
Fixes: 371975b0b075 ("fsi/core: Fix error paths on CFAM init")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
drivers/fsi/fsi-core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c
index e2e1e9df6115..1373e05e3659 100644
--- a/drivers/fsi/fsi-core.c
+++ b/drivers/fsi/fsi-core.c
@@ -1084,7 +1084,8 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
rc = cdev_device_add(&slave->cdev, &slave->dev);
if (rc) {
dev_err(&slave->dev, "Error %d creating slave device\n", rc);
- goto err_free_ida;
+ put_device(&slave->dev);
+ return rc;
}
/* Now that we have the cdev registered with the core, any fatal
@@ -1110,8 +1111,6 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id)
return 0;
-err_free_ida:
- fsi_free_minor(slave->dev.devt);
err_free:
of_node_put(slave->dev.of_node);
kfree(slave);
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-10-22 15:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22 9:18 [PATCH RESEND] fsi/core: fix error handling in fsi_slave_init() Ma Ke
2025-10-22 15:19 ` Eddie James
-- strict thread matches above, loose matches on Subject: below --
2025-07-18 9:24 Ma Ke
2025-04-14 9:27 Ma Ke
2025-04-07 7:37 Ma Ke
2025-03-31 9:13 Ma Ke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox