Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1084136ybt; Wed, 1 Jul 2020 18:28:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/XCQOCLxW3IYtNGCgae9eHTWVuOJhhJ3mt73/qzFkK+eN8PIdZATaFvca+9KEa3YrIKhl X-Received: by 2002:a05:6402:1c07:: with SMTP id ck7mr20517945edb.297.1593653299249; Wed, 01 Jul 2020 18:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593653299; cv=none; d=google.com; s=arc-20160816; b=b50R+llNF2VM5kihQfgsfDnOjFLqkmmF4FZNzSsQMkReskiqtfVCvNepxrWSO0R+2x bEkdsMnuP44QUoNmatiaW2UurcsldTTvVpXD/Tp5/NTQZpyD6DKmF3RGYmt5NIlkhty2 t42ylbhWOaS1e4W0nbKdVYhhT4uNAsN7Xi6I1+JIdUWROjDG1zgYXaFzWntEHi0wXSN4 tSDUj2OQ8LEZG6qmuRJdD+G5aKTAILiI3ny1a6XDG8mz0oUseDXueueXtgInZuIvIcX9 Icz9FKSqrVng5AmSPxjusa23PseWPXtfG+kzg2RLaxJscUdTmAmTqcsFVmtOmvSdnTQS ctEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nHBG3qgLlOV40Obo8tYfAtjFEeGDWQUiknPjH9YT8KA=; b=LpNuCWeeg727H+qTDdueMfSXFpIIgVo9/nRIR5+142I6p9JruXantcfhmc5HZLvUfk mRIEmzkbk+7pLyEvIKnJM3zDZCYrOaDbKwzsoJ6okeKSeYSMB4z+WFnQodR52k/Ol/WG dUZEjHIHP3xtkAcybaKW8LTCZLkI+DfisoDoT+dpRT66n6MNt5kumwuy0QBvnCL5s0NF ZWUHkur8I3iYSmyJhkIIzURkGnc50jh9CIXrprHbI3rgRQscqfm0tUKOpxq0wjuPnOhF s9m2qIVYVFznkAbI0R4IcPTXTXrAyWX8fSGDASM2V/ixcRquQ7X2F5kWwY5OazlvFy3+ m2Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wGWSw6Og; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si4939395ejv.383.2020.07.01.18.27.56; Wed, 01 Jul 2020 18:28:19 -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=@kernel.org header.s=default header.b=wGWSw6Og; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728713AbgGBBY5 (ORCPT + 99 others); Wed, 1 Jul 2020 21:24:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:54676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728514AbgGBBXx (ORCPT ); Wed, 1 Jul 2020 21:23:53 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C205320936; Thu, 2 Jul 2020 01:23:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593653032; bh=PSzzfbTuoUNF3dRKfP49WxHtPiD1fc3IO882Ix6zJLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wGWSw6Ogv21+EWuPjwRsjTi8HNEziUeBQLEoxZ9yYUGf4aatkk3qBXYeKljJaulmT i+/a12NP6wOztiURnLR5gNWjFz6ItQuehe7UdmmvX5GuA8p5ZH/6k/QdkY/zC0xWnc jCcFquRw8L2BBQb+mowJYdBDutrbcLhCXCDhbPHU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Chengguang Xu , Christoph Hellwig , "Martin K . Petersen" , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 46/53] block: release bip in a right way in error path Date: Wed, 1 Jul 2020 21:21:55 -0400 Message-Id: <20200702012202.2700645-46-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702012202.2700645-1-sashal@kernel.org> References: <20200702012202.2700645-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chengguang Xu [ Upstream commit 0b8eb629a700c0ef15a437758db8255f8444e76c ] Release bip using kfree() in error path when that was allocated by kmalloc(). Signed-off-by: Chengguang Xu Reviewed-by: Christoph Hellwig Acked-by: Martin K. Petersen Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bio-integrity.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index bf62c25cde8f4..1d173feb38831 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -24,6 +24,18 @@ void blk_flush_integrity(void) flush_workqueue(kintegrityd_wq); } +void __bio_integrity_free(struct bio_set *bs, struct bio_integrity_payload *bip) +{ + if (bs && mempool_initialized(&bs->bio_integrity_pool)) { + if (bip->bip_vec) + bvec_free(&bs->bvec_integrity_pool, bip->bip_vec, + bip->bip_slab); + mempool_free(bip, &bs->bio_integrity_pool); + } else { + kfree(bip); + } +} + /** * bio_integrity_alloc - Allocate integrity payload and attach it to bio * @bio: bio to attach integrity metadata to @@ -75,7 +87,7 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio, return bip; err: - mempool_free(bip, &bs->bio_integrity_pool); + __bio_integrity_free(bs, bip); return ERR_PTR(-ENOMEM); } EXPORT_SYMBOL(bio_integrity_alloc); @@ -96,14 +108,7 @@ void bio_integrity_free(struct bio *bio) kfree(page_address(bip->bip_vec->bv_page) + bip->bip_vec->bv_offset); - if (bs && mempool_initialized(&bs->bio_integrity_pool)) { - bvec_free(&bs->bvec_integrity_pool, bip->bip_vec, bip->bip_slab); - - mempool_free(bip, &bs->bio_integrity_pool); - } else { - kfree(bip); - } - + __bio_integrity_free(bs, bip); bio->bi_integrity = NULL; bio->bi_opf &= ~REQ_INTEGRITY; } -- 2.25.1