From: Coly Li <colyli@suse.de>
To: Jan Kara <jack@suse.cz>, Christian Brauner <brauner@kernel.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>,
Bcache Linux <linux-bcache@vger.kernel.org>
Subject: Re: [PATCH] bcache: Fixup error handling in register_cache()
Date: Sat, 7 Oct 2023 20:41:55 +0800 [thread overview]
Message-ID: <82ACE5AB-5FDB-4598-A384-EF904F394821@suse.de> (raw)
In-Reply-To: <20231004093757.11560-1-jack@suse.cz>
> 2023年10月4日 17:37,Jan Kara <jack@suse.cz> 写道:
>
> Coverity has noticed that the printing of error message in
> register_cache() uses already freed bdev_handle to get to bdev. In fact
> the problem has been there even before commit "bcache: Convert to
> bdev_open_by_path()" just a bit more subtle one - cache object itself
> could have been freed by the time we looked at ca->bdev and we don't
> hold any reference to bdev either so even that could in principle go
> away (due to device unplug or similar). Fix all these problems by
> printing the error message before closing the bdev.
>
> Fixes: dc893f51d24a ("bcache: Convert to bdev_open_by_path()")
> Signed-off-by: Jan Kara <jack@suse.cz>
Asked-by: Coly Li <colyli@suse.de <mailto:colyli@suse.de>>
Thanks.
Coly Li
> ---
> drivers/md/bcache/super.c | 23 ++++++++++-------------
> 1 file changed, 10 insertions(+), 13 deletions(-)
>
> Hello Christian!
>
> Can you please add this to patch to the bdev_handle conversion series? Either
> append it at the end of the series or just fold it into the bcache conversion.
> Whatever looks better for you.
>
>
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index c11ac86be72b..a30c8d4f2ac8 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -2354,6 +2354,13 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
>
> ret = cache_alloc(ca);
> if (ret != 0) {
> + if (ret == -ENOMEM)
> + err = "cache_alloc(): -ENOMEM";
> + else if (ret == -EPERM)
> + err = "cache_alloc(): cache device is too small";
> + else
> + err = "cache_alloc(): unknown error";
> + pr_notice("error %pg: %s\n", bdev_handle->bdev, err);
> /*
> * If we failed here, it means ca->kobj is not initialized yet,
> * kobject_put() won't be called and there is no chance to
> @@ -2361,17 +2368,12 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
> * we explicitly call bdev_release() here.
> */
> bdev_release(bdev_handle);
> - if (ret == -ENOMEM)
> - err = "cache_alloc(): -ENOMEM";
> - else if (ret == -EPERM)
> - err = "cache_alloc(): cache device is too small";
> - else
> - err = "cache_alloc(): unknown error";
> - goto err;
> + return ret;
> }
>
> if (kobject_add(&ca->kobj, bdev_kobj(bdev_handle->bdev), "bcache")) {
> - err = "error calling kobject_add";
> + pr_notice("error %pg: error calling kobject_add\n",
> + bdev_handle->bdev);
> ret = -ENOMEM;
> goto out;
> }
> @@ -2389,11 +2391,6 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
>
> out:
> kobject_put(&ca->kobj);
> -
> -err:
> - if (err)
> - pr_notice("error %pg: %s\n", ca->bdev_handle->bdev, err);
> -
> return ret;
> }
>
> --
> 2.35.3
>
next prev parent reply other threads:[~2023-10-07 12:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 9:37 [PATCH] bcache: Fixup error handling in register_cache() Jan Kara
2023-10-07 12:41 ` Coly Li [this message]
2023-10-09 7:38 ` Christian Brauner
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=82ACE5AB-5FDB-4598-A384-EF904F394821@suse.de \
--to=colyli@suse.de \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=kent.overstreet@gmail.com \
--cc=linux-bcache@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).