Skip to content

Commit

Permalink
bcache: properly initialize 'path' and 'err' in register_bcache()
Browse files Browse the repository at this point in the history
[ Upstream commit 29cda39 ]

Patch "bcache: rework error unwinding in register_bcache" from
Christoph Hellwig changes the local variables 'path' and 'err'
in undefined initial state. If the code in register_bcache() jumps
to label 'out:' or 'out_module_put:' by goto, these two variables
might be reference with undefined value by the following line,

	out_module_put:
	        module_put(THIS_MODULE);
	out:
	        pr_info("error %s: %s", path, err);
	        return ret;

Therefore this patch initializes these two local variables properly
in register_bcache() to avoid such issue.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Coly Li authored and Greg Kroah-Hartman committed Feb 24, 2020
1 parent 7967c32 commit cea9007
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/md/bcache/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2373,18 +2373,20 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
const char *buffer, size_t size)
{
const char *err;
char *path;
char *path = NULL;
struct cache_sb *sb;
struct block_device *bdev = NULL;
struct page *sb_page;
ssize_t ret;

ret = -EBUSY;
err = "failed to reference bcache module";
if (!try_module_get(THIS_MODULE))
goto out;

/* For latest state of bcache_is_reboot */
smp_mb();
err = "bcache is in reboot";
if (bcache_is_reboot)
goto out_module_put;

Expand Down

0 comments on commit cea9007

Please sign in to comment.