From patchwork Tue Sep 28 06:39:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinyoung Choi X-Patchwork-Id: 12521889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC2FEC433F5 for ; Tue, 28 Sep 2021 06:39:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D8FE61159 for ; Tue, 28 Sep 2021 06:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237798AbhI1GlL (ORCPT ); Tue, 28 Sep 2021 02:41:11 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:51636 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234207AbhI1GlG (ORCPT ); Tue, 28 Sep 2021 02:41:06 -0400 Received: from epcas2p4.samsung.com (unknown [182.195.41.56]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20210928063921epoutp02346835ec01d127cf3e759d17cdd81ad7~o6Rm7DfZm2766127661epoutp02f for ; Tue, 28 Sep 2021 06:39:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20210928063921epoutp02346835ec01d127cf3e759d17cdd81ad7~o6Rm7DfZm2766127661epoutp02f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1632811161; bh=ec/cnE/B9m6a4wLi6h6bXa6hyK8Qh1NGtayht6ko26w=; h=Subject:Reply-To:From:To:Date:References:From; b=gN/LUOrgBTiW7tX+8rt6gSfEQoLYRqhdV7c7iY5ikDWU1njg4XYtZoylFQNh/7g6o q/e449o+28LmltBGKd+GbIZth+BHJzNo34Qk7ryYtl9nvTnayMoerLxrxotV92Kttq /IacTTxKnx7e7LyOTOC86upY+pkJfgwKglpYQy8c= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20210928063920epcas2p327a44b24703f1c1d4a19595e55d55174~o6RmL42BB0294202942epcas2p3j; Tue, 28 Sep 2021 06:39:20 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.40.188]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4HJVGb5k5Bz4x9QY; Tue, 28 Sep 2021 06:39:19 +0000 (GMT) X-AuditID: b6c32a46-63bff70000002658-c9-6152b8976e4e Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id 5E.BF.09816.798B2516; Tue, 28 Sep 2021 15:39:19 +0900 (KST) Mime-Version: 1.0 Subject: [PATCH] block-map: added error handling for bio_copy_kern() Reply-To: j-young.choi@samsung.com Sender: Jinyoung CHOI From: Jinyoung CHOI To: "axboe@kernel.dk" , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" X-Priority: 3 X-Content-Kind-Code: NORMAL X-CPGS-Detection: blocking_info_exchange X-Drm-Type: N,general X-Msg-Generator: Mail X-Msg-Type: PERSONAL X-Reply-Demand: N Message-ID: <20210928063919epcms2p12ef0dfc94e6756f7bf85945522720e8f@epcms2p1> Date: Tue, 28 Sep 2021 15:39:19 +0900 X-CMS-MailID: 20210928063919epcms2p12ef0dfc94e6756f7bf85945522720e8f X-Sendblock-Type: AUTO_CONFIDENTIAL X-CPGSPASS: Y X-CPGSPASS: Y CMS-TYPE: 102P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDKsWRmVeSWpSXmKPExsWy7bCmue70HUGJBs8WiVisvtvPZvHykKZF b/9WNou9t7QtLu+aw+bA6nH5bKlH35ZVjB6fN8kFMEfl2GSkJqakFimk5iXnp2TmpdsqeQfH O8ebmhkY6hpaWpgrKeQl5q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X-CMS-RootMailID: 20210928063420epcms2p8f0cad25e1b820169755962ff4555d3ac References: Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org When new pages are allocated to bio through alloc_page() in bio_copy_kern(), the pages must be freed in error handling after that. There is little chance of an error occurring in blk_rq_append_bio(), but in the code flow, pages additionally allocated to bio must be released. Signed-off-by: Jinyoung Choi --- block/blk-map.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/block/blk-map.c b/block/blk-map.c index 4526adde0156..584369a7837f 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -628,6 +628,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, int reading = rq_data_dir(rq) == READ; unsigned long addr = (unsigned long) kbuf; struct bio *bio; + int do_copy = 0; int ret; if (len > (queue_max_hw_sectors(q) << 9)) @@ -635,8 +636,9 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, if (!len || !kbuf) return -EINVAL; - if (!blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) || - blk_queue_may_bounce(q)) + do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf) || + blk_queue_may_bounce(q); + if (do_copy) bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading); else bio = bio_map_kern(q, kbuf, len, gfp_mask); @@ -648,8 +650,11 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, bio->bi_opf |= req_op(rq); ret = blk_rq_append_bio(rq, bio); - if (unlikely(ret)) + if (unlikely(ret)) { + if (do_copy) + bio_free_pages(bio); bio_put(bio); + } return ret; } EXPORT_SYMBOL(blk_rq_map_kern);