Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566608lkm; Mon, 20 Sep 2021 18:53:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrrNURvKyRuIhlhXd4+dSZF6bFIFkL/wHJKyF0xA9wm4BDorOZQEvkIk0PGZKW3Nt8Vip4 X-Received: by 2002:a6b:5f1b:: with SMTP id t27mr3153690iob.213.1632188871612; Mon, 20 Sep 2021 18:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188871; cv=none; d=google.com; s=arc-20160816; b=N2BpVoRCGheqJnAP16Zjx7kbGLyNH8Kc9LXu+utFrHKdGwqvU0pIu5rWIV/xg5cLIj gBwzNhuClJvuplJBGBwkIE4OaPXzKbTpa3S/argu36b00rOjh/F428r8JcIWmtqR9pZY jCswgUWZamxbHVUKCv2vNYSp77LExN/CO2vdXdu/LjaUyyrsLxz2tVPjI/CKF9Hu04G1 aLd2FR4x7TXzYaCW84FC8ZifA7RqDLx6tkG8ghSSnD5V+FNf/Xuk0RHjwD/KXivVKXf9 DnxLSBOjjHAV8sNhY7tMCtTQ06uR0tg7Tw7ehYApA8LGSwpLNv31EnGfBd/gglDLJlxt G3oQ== 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=IyedEufsB8BewBAii9lU4np3k7Fo/Jn+fHEdpByFo0s=; b=rfrBIZp5pNrXgtGv/3HJEM0WmAVNT6900ag7+lvZ1TtT5Oidk+enrFMVxU80PRZnh1 w6U6BoIJeXmpM3CB1rbpUaNII13mORtweLE5CJg0cUb/kAnpPVJhsdQchSnpbEZNrDKj 09O3cdUQk4zk43KeNuWUVM3pP/xlkXJUTOVzcEhk7HVUe37d6yNPsTy1BN5a/uhVSxAQ vt455PjJdtkSsGiNOf/o3HG2hxn2P3LGqs1tehNHy7j2TiXJrch68IsmwA3OZ6l6DtTX gfty/opFpK0KbIGSeyN9Xct6JWgnSfjftzycwJWIJHk08IgheboSkv4MplMT0ilLFqIo HAFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LstV+0VY; 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 f17si14808484iow.57.2021.09.20.18.47.39; Mon, 20 Sep 2021 18:47:51 -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=LstV+0VY; 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 S245173AbhITRgr (ORCPT + 99 others); Mon, 20 Sep 2021 13:36:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:36226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351607AbhITRec (ORCPT ); Mon, 20 Sep 2021 13:34:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E967561B08; Mon, 20 Sep 2021 17:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157548; bh=+V+55lPU0e89x11WekxDbsZ4MadTMrFS1/1T2QQ+KgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LstV+0VYly2J6bptM7jNlvyNJ0hwOD8/Qv2w3mODXGP3jQz+WmWdLgjbewDIefhUn S8+WhKWDpmXUcrwJCeYukEm9R9+5KVqon08kq4X7RBkKdNPmxj9lEjHkYTNmC//DAo lpWvufAsaI0fLXvyMKcBt/2BqDGbT4fH0vjK7/1Y= 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 4.19 042/293] bcache: add proper error unwinding in bcache_device_init Date: Mon, 20 Sep 2021 18:40:04 +0200 Message-Id: <20210920163934.709456686@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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 7787ec42f81e..2df75db52e91 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -824,20 +824,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); @@ -872,8 +872,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