From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8CFEC433FE for ; Mon, 6 Sep 2021 01:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8F1E610D2 for ; Mon, 6 Sep 2021 01:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239719AbhIFBX1 (ORCPT ); Sun, 5 Sep 2021 21:23:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:37826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239025AbhIFBW3 (ORCPT ); Sun, 5 Sep 2021 21:22:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 849E361106; Mon, 6 Sep 2021 01:21:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630891273; bh=P3byreIPuZnbPrwJUZckS3L+rpi9RwiluUft/czke64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rpkcQjvOJ869xKBgCHCamVAe08EA9LwAxzQRlUfK9G2vQotAaAfQ6GNoWVX7sn4lF 6wL99/IyGCY+rVpVr9x01mYJPNxZ30Qy0G5t2Ko0oa/hj+Fjh2+275HRtffUDwm6mV VdB85MZgI6mK/nbkv7lWEwzbrNjU/qFKBM5Q2TP5VCcdmpI6cBi3KJVAyXWON+58LD 4obpVifxlr1lYJS2Sk2Bvx+989evkBiBI0P1wQL+Z0TH2tM3oVKjIqy5zLko/jx8vX 9ERavH533IvZudzL7OKIG3TeXubI9/UKtbccmPNKKZIeWdX3p4PnrRQa+AvnOQ3xf7 PMEv+gmOla6aw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christoph Hellwig , Coly Li , Jens Axboe , Sasha Levin , linux-bcache@vger.kernel.org Subject: [PATCH AUTOSEL 5.13 17/46] bcache: add proper error unwinding in bcache_device_init Date: Sun, 5 Sep 2021 21:20:22 -0400 Message-Id: <20210906012052.929174-17-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210906012052.929174-1-sashal@kernel.org> References: <20210906012052.929174-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bcache@vger.kernel.org From: Christoph Hellwig [ Upstream commit 224b0683228c5f332f9cee615d85e75e9a347170 ] Except for the IDA none of the allocations in bcache_device_init is unwound on error, fix that. Signed-off-by: Christoph Hellwig Acked-by: Coly Li Link: https://lore.kernel.org/r/20210809064028.1198327-7-hch@lst.de Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/super.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index bea8c4429ae8..a407e3be0f17 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -935,20 +935,20 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size, n = BITS_TO_LONGS(d->nr_stripes) * sizeof(unsigned long); d->full_dirty_stripes = kvzalloc(n, GFP_KERNEL); if (!d->full_dirty_stripes) - return -ENOMEM; + goto out_free_stripe_sectors_dirty; idx = ida_simple_get(&bcache_device_idx, 0, BCACHE_DEVICE_IDX_MAX, GFP_KERNEL); if (idx < 0) - return idx; + goto out_free_full_dirty_stripes; if (bioset_init(&d->bio_split, 4, offsetof(struct bbio, bio), BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER)) - goto err; + goto out_ida_remove; d->disk = alloc_disk(BCACHE_MINORS); if (!d->disk) - goto err; + goto out_bioset_exit; set_capacity(d->disk, sectors); snprintf(d->disk->disk_name, DISK_NAME_LEN, "bcache%i", idx); @@ -994,8 +994,14 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size, return 0; -err: +out_bioset_exit: + bioset_exit(&d->bio_split); +out_ida_remove: ida_simple_remove(&bcache_device_idx, idx); +out_free_full_dirty_stripes: + kvfree(d->full_dirty_stripes); +out_free_stripe_sectors_dirty: + kvfree(d->stripe_sectors_dirty); return -ENOMEM; } -- 2.30.2