From: Jason Gunthorpe <jgg@ziepe.ca>
To: Bo Liu <liubo03@inspur.com>
Cc: bvanassche@acm.org, leon@kernel.org, linux-rdma@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RDMA/srp: Check dev_set_name() return value
Date: Fri, 5 Aug 2022 11:02:28 -0300 [thread overview]
Message-ID: <Yu0i9DzLg0kt5Sd9@ziepe.ca> (raw)
In-Reply-To: <20220805053434.3944-1-liubo03@inspur.com>
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
prev parent reply other threads:[~2022-08-05 14:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-05 5:34 Bo Liu
2022-08-05 13:57 ` Bart Van Assche
2022-08-05 14:02 ` Jason Gunthorpe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yu0i9DzLg0kt5Sd9@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=bvanassche@acm.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=liubo03@inspur.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®