Skip to content

Commit c8e4c23

Browse files
bvanasscherleon
authored andcommitted
RDMA/srp: Rework the srp_add_port() error path
device_register() always calls device_initialize() so calling device_del() is safe even if device_register() fails. Implement the following advice from the comment block above device_register(): "NOTE: _Never_ directly free @dev after calling this function, even if it returned an error! Always use put_device() to give up the reference initialized in this function instead." Keep the kfree() call in the error path since srp_release_dev() does not free the host. Link: https://lore.kernel.org/r/20220825213900.864587-2-bvanassche@acm.org Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 3d67e7e commit c8e4c23

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/infiniband/ulp/srp/ib_srp.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,20 +3909,19 @@ static struct srp_host *srp_add_port(struct srp_device *device, u8 port)
39093909
port);
39103910

39113911
if (device_register(&host->dev))
3912-
goto free_host;
3912+
goto put_host;
39133913
if (device_create_file(&host->dev, &dev_attr_add_target))
3914-
goto err_class;
3914+
goto put_host;
39153915
if (device_create_file(&host->dev, &dev_attr_ibdev))
3916-
goto err_class;
3916+
goto put_host;
39173917
if (device_create_file(&host->dev, &dev_attr_port))
3918-
goto err_class;
3918+
goto put_host;
39193919

39203920
return host;
39213921

3922-
err_class:
3923-
device_unregister(&host->dev);
3924-
3925-
free_host:
3922+
put_host:
3923+
device_del(&host->dev);
3924+
put_device(&host->dev);
39263925
kfree(host);
39273926

39283927
return NULL;

0 commit comments

Comments
 (0)