Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1822738pxb; Mon, 13 Sep 2021 06:21:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu4byhhFGEKWuKvJro1BJ1kZw4temeX1c8/Y2F778J5V2ERWlDofK/rv40bL0UhujCLb+d X-Received: by 2002:a05:6e02:4a3:: with SMTP id e3mr7368106ils.229.1631539275080; Mon, 13 Sep 2021 06:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631539275; cv=none; d=google.com; s=arc-20160816; b=B9Kuhd3eg+Wbvur8FRylHTLVhNuqdru1KJxl0bqmRXza8LGStsyMOh1E4V7/lx8D1C dlpPjgu+6RFvKOEgfRcI9NVHN6i3vEa6A1MVsGsGEM8w2a+YZ8RSjGoJKeLvdFdc/iCj cTCCdkD0Tj8hQlCA63nJFk6lfequkixTmrP59qixriy+8Z+tgC4zVbTjiip/sDlpzyV3 dqmxy8cIlU3mFdOsclPS/6Iz2Z455jc86ihjX5T16sgWOxDjQjDtdHMaPMvLjSP+I2EJ m6CjzyJxXNSno6zzhFunixIUBf870SIftrYEuD9cfgrBe72Whl47krllAnWGcHdgk+Ib 3P0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N1C7NZdM4UFAeOc37te+07e53GAolo6HyY3Jz4kLaeY=; b=DmSddAPPaCSlPCsNyRMi2R8lYIIC29aL904QLM9frRnsJ+XC0ie6UKmvCcmljKRkTD j3W4bV3CHK3uclTt1FDDNnzvOXGVx2kyGkmh0AFTN96bIPMnNJgKkAxjCUt6mO0FVzch Q44VokrsC2pl/vidVHxtDCW8Uwpdb5sTMYq4lBQadgY5zPZX/6TX6GLLIKo8jGgswL5r D0PHnIFaPW5WID3+f6a/m72HTU6n9Mwgg4NbK62ihh2FFp+GlVFkhoZHeq85sQ7ulCq7 v/M2bCXgGhm1xj4hhYukjgFWVeJugBREeZGiGGTF9K9RBAiPEjZykrRh89AW/G2g5oDX nLqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BNMivdEb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i4si7026890ilj.162.2021.09.13.06.21.02; Mon, 13 Sep 2021 06:21:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BNMivdEb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240337AbhIMNU5 (ORCPT + 99 others); Mon, 13 Sep 2021 09:20:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:34832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239178AbhIMNTt (ORCPT ); Mon, 13 Sep 2021 09:19:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 20355610A3; Mon, 13 Sep 2021 13:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539028; bh=F8pgq0rgX3r7YNCNfkeIUvLn/+DTlaB66BwtqOvDdd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BNMivdEbiLn0Cr7NZcWbqgWeqosKloFn/te1C6kVTszt3K41OTTRhGCeep6NC0sAA tvtT6285GhVbGT8M0CoZqcD5Ff5zyAf5OvKPKMJzghfOXNF9BLLqeZps2qb7nFf65b PDfscAsrR52DWJ6xQR5g2+xz0hjUbPDUmOVx4Beo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 015/144] bcache: add proper error unwinding in bcache_device_init Date: Mon, 13 Sep 2021 15:13:16 +0200 Message-Id: <20210913131048.474512431@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 b0d569032dd4..efdf6ce0443e 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -839,20 +839,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); @@ -887,8 +887,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