linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] RDMA/srp: Check dev_set_name() return value
@ 2022-08-05  5:34 Bo Liu
  2022-08-05 13:57 ` Bart Van Assche
  2022-08-05 14:02 ` Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Bo Liu @ 2022-08-05  5:34 UTC (permalink / raw)
  To: bvanassche, jgg, leon; +Cc: linux-rdma, linux-kernel, Bo Liu

It's possible that dev_set_name() returns -ENOMEM, catch and handle this.

Signed-off-by: Bo Liu <liubo03@inspur.com>
---
 drivers/infiniband/ulp/srp/ib_srp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 7720ea270ed8..a6f788e3b84b 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -3905,8 +3905,9 @@ static struct srp_host *srp_add_port(struct srp_device *device, u8 port)
 
 	host->dev.class = &srp_class;
 	host->dev.parent = device->dev->dev.parent;
-	dev_set_name(&host->dev, "srp-%s-%d", dev_name(&device->dev->dev),
-		     port);
+	if (dev_set_name(&host->dev, "srp-%s-%d", dev_name(&device->dev->dev),
+		     port))
+		goto free_host;
 
 	if (device_register(&host->dev))
 		goto free_host;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/srp: Check dev_set_name() return value
  2022-08-05  5:34 [PATCH] RDMA/srp: Check dev_set_name() return value Bo Liu
@ 2022-08-05 13:57 ` Bart Van Assche
  2022-08-05 14:02 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Van Assche @ 2022-08-05 13:57 UTC (permalink / raw)
  To: Bo Liu, jgg, leon; +Cc: linux-rdma, linux-kernel

On 8/4/22 22:34, Bo Liu wrote:
> It's possible that dev_set_name() returns -ENOMEM, catch and handle this.
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>   drivers/infiniband/ulp/srp/ib_srp.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
> index 7720ea270ed8..a6f788e3b84b 100644
> --- a/drivers/infiniband/ulp/srp/ib_srp.c
> +++ b/drivers/infiniband/ulp/srp/ib_srp.c
> @@ -3905,8 +3905,9 @@ static struct srp_host *srp_add_port(struct srp_device *device, u8 port)
>   
>   	host->dev.class = &srp_class;
>   	host->dev.parent = device->dev->dev.parent;
> -	dev_set_name(&host->dev, "srp-%s-%d", dev_name(&device->dev->dev),
> -		     port);
> +	if (dev_set_name(&host->dev, "srp-%s-%d", dev_name(&device->dev->dev),
> +		     port))
> +		goto free_host;
>   
>   	if (device_register(&host->dev))
>   		goto free_host;

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/srp: Check dev_set_name() return value
  2022-08-05  5:34 [PATCH] RDMA/srp: Check dev_set_name() return value Bo Liu
  2022-08-05 13:57 ` Bart Van Assche
@ 2022-08-05 14:02 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2022-08-05 14:02 UTC (permalink / raw)
  To: Bo Liu; +Cc: bvanassche, leon, linux-rdma, linux-kernel

On Fri, Aug 05, 2022 at 01:34:34AM -0400, Bo Liu wrote:
> It's possible that dev_set_name() returns -ENOMEM, catch and handle this.
> 
> Signed-off-by: Bo Liu <liubo03@inspur.com>
> ---
>  drivers/infiniband/ulp/srp/ib_srp.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Ah, while you are here can you fix this:

>  	if (device_register(&host->dev))
>  		goto free_host;
[..]
> free_host:
>         kfree(host);

That isn't allowed, you have to do put_device():

/**
 * device_register - register a device with the system.
 * @dev: pointer to the device structure
 *
 * This happens in two clean steps - initialize the device
 * and add it to the system. The two steps can be called
 * separately, but this is the easiest and most common.
 * I.e. you should only call the two helpers separately if
 * have a clearly defined need to use and refcount the device
 * before it is added to the hierarchy.
 *
 * For more information, see the kerneldoc for device_initialize()
 * and device_add().
 *
 * 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.
 */
int device_register(struct device *dev)

Everyone get this wrong, it is why I think device_register is a
terrible interface. Write it as device_initialize()/device_add() as
seperate steps and never call kfree().

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-05 14:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-05  5:34 [PATCH] RDMA/srp: Check dev_set_name() return value Bo Liu
2022-08-05 13:57 ` Bart Van Assche
2022-08-05 14:02 ` Jason Gunthorpe

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).