From patchwork Fri Apr 29 05:58:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinyoung Choi X-Patchwork-Id: 12831469 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2258AC433EF for ; Fri, 29 Apr 2022 05:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354336AbiD2GCV (ORCPT ); Fri, 29 Apr 2022 02:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354335AbiD2GCU (ORCPT ); Fri, 29 Apr 2022 02:02:20 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52174B18AA for ; Thu, 28 Apr 2022 22:59:02 -0700 (PDT) Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20220429055858epoutp0290984741fc6df83ee8a284de3cb881e2~qSIJwcmoG2818428184epoutp02J for ; Fri, 29 Apr 2022 05:58:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20220429055858epoutp0290984741fc6df83ee8a284de3cb881e2~qSIJwcmoG2818428184epoutp02J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651211938; bh=7VNqedSgdU0I1pkagRB5zQzJa9VgyyV3FEglDrDcLpU=; h=Subject:Reply-To:From:To:CC:Date:References:From; b=sBXN48SyXpYLCAWu3fAceiJvLeris7/SuwyDCU2LDidx9J1pmHjte1rqAXvCIrICf h0G0Fgkvo1kxdiqle2nNXyuvzb8K92JaVScJx0swkoIUeYEi9FHuLgN9nYQNeE4stm VZ3jOe+n5h5apxM7EzS13jbqgTRpxo9amUSpalqQ= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p2.samsung.com (KnoxPortal) with ESMTP id 20220429055857epcas2p27b4e3b79a24ff7ae70863ef86dd8f8cc~qSIJHYWxF0125601256epcas2p2t; Fri, 29 Apr 2022 05:58:57 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.36.88]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4KqMHg2Vs5z4x9QV; Fri, 29 Apr 2022 05:58:55 +0000 (GMT) X-AuditID: b6c32a46-f8bff70000002624-7a-626b7e9f94b0 Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id 7F.54.09764.F9E7B626; Fri, 29 Apr 2022 14:58:55 +0900 (KST) Mime-Version: 1.0 Subject: [RESEND PATCH v2] 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" CC: "hch@infradead.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: <20220429055854epcms2p7e5045065a4732fb59b0fb1345c348a45@epcms2p7> Date: Fri, 29 Apr 2022 14:58:54 +0900 X-CMS-MailID: 20220429055854epcms2p7e5045065a4732fb59b0fb1345c348a45 X-Sendblock-Type: AUTO_CONFIDENTIAL X-CPGSPASS: Y X-CPGSPASS: Y CMS-TYPE: 102P X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPKsWRmVeSWpSXmKPExsWy7bCmhe78uuwkg+UvuSxW3+1ns3h5SNPi RstjZotHt58xWpyesIjJord/K5vF3lvaFpd3zWFz4PDYvELL4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+Nj0d8hY/pOz4lluKMREMt5qLi RADE6GqkEgQAAA== DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220429055854epcms2p7e5045065a4732fb59b0fb1345c348a45 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. V2: - replace int with bool Reviewed-by: Christoph Hellwig Signed-off-by: Jinyoung Choi --- block/blk-map.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index df8b066cd548..613990fa87e1 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -637,6 +637,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; + bool do_copy; int ret; if (len > (queue_max_hw_sectors(q) << 9)) @@ -644,8 +645,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); @@ -658,6 +660,8 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, ret = blk_rq_append_bio(rq, bio); if (unlikely(ret)) { + if (do_copy) + bio_free_pages(bio); bio_uninit(bio); kfree(bio); }