diff mbox series

[v2] RDMA/srp: Fix error handling in srp_add_port

Message ID 20241217104605.2924666-1-make_ruc2021@163.com (mailing list archive)
State Superseded
Headers show
Series [v2] RDMA/srp: Fix error handling in srp_add_port | expand

Commit Message

Ma Ke Dec. 17, 2024, 10:46 a.m. UTC
Once device_add() failed, we should call only put_device() to
decrement reference count for cleanup. We should not call device_del()
before put_device().

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: c8e4c2397655 ("RDMA/srp: Rework the srp_add_port() error path")
Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
Changes in v2:
- modified the bug description as suggestions.
---
 drivers/infiniband/ulp/srp/ib_srp.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Bart Van Assche Dec. 17, 2024, 4:14 p.m. UTC | #1
On 12/17/24 2:46 AM, Ma Ke wrote:
> Once device_add() failed, we should call only put_device() to
> decrement reference count for cleanup. We should not call device_del()
> before put_device().
> 
> 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: c8e4c2397655 ("RDMA/srp: Rework the srp_add_port() error path")
> Signed-off-by: Ma Ke <make_ruc2021@163.com>

Patch descriptions should be in the imperative mood.

A blank line should separate the description and the tags.

Otherwise this patch looks good to me. Hence:

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
diff mbox series

Patch

diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 2916e77f589b..7289ae0b83ac 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -3978,7 +3978,6 @@  static struct srp_host *srp_add_port(struct srp_device *device, u32 port)
 	return host;
 
 put_host:
-	device_del(&host->dev);
 	put_device(&host->dev);
 	return NULL;
 }