Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2215705pxb; Fri, 25 Mar 2022 13:12:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEWr1rE6kdIPkvzERb0+hz1W6Kh8D/Gfimduixd2BFkhRH8J2RmN23ol0JeOM1M2X3t1yH X-Received: by 2002:a17:90a:2b86:b0:1c7:6e7a:3e00 with SMTP id u6-20020a17090a2b8600b001c76e7a3e00mr23043875pjd.115.1648239141236; Fri, 25 Mar 2022 13:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648239141; cv=none; d=google.com; s=arc-20160816; b=u24LY0EEoUgWWD0OM/d/djh7BRJeeiwvoh4X44kU2i1Yu0h/41JOu4clq9xUFNnREp I63JijCL8IbRj8chjEo24r8X187M+b+iUdK8PQnP+NY3PZQbna47Q1SYsPSzviuv94uI ve/bnlPkzqDiolxiQrojPgle2Jm7V9HTvQZ3doqSuvvjh0GIpb81Qy1ZuUXV4VxtGwve CgfbAzkvJrmlYV7D0F5Dciey8o25UR3M8HnvdmHvvHaZrSbQpqaxah52iq7QxXKTAC08 enAKE2FzAle7051Pa9bK4shTRDUSgShNpNGfsrnTVc3+Tw62OSvzGsUpO+3E6pjddgYV amgg== 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:date :subject:cc:to:from:message-id:dkim-signature; bh=qpf8RfttfYwh4u1t5tUZIPgLdFSz2GuJZ8d8Lfe+YNY=; b=FYB+0g03UpOW8Jrmn4e3zFSDf+5IhXLgRe+5yaBWadIsBNTAjyByxuDotjSdDP4ZYh BXBJlCR2ZS1rh3fhQRgX8gU1roE4jfrpFospY9GqWyVM5ofHXs1QkltjXlwGDNEt7ztW n/PtLwePClljr1Ih9uzYHKGREPWinHmDOwwCbQ+AJTPJHc62dlVK2/d9Ob5wwF9HFWdq e4mU0GqglfX9HoUJfX4KgrJxlpLZaRiqxMDrr7UR/4KF2blbcUmbDWOwY0HcvoUQLrRT nU/zfGwCP/pgmpRDpUwBI1yt2JEQkakS8OveoxObogOIf/XxDmPvJyl9l7+0vr2pi0GP PE9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b="zKp/0cjj"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f2-20020a17090ace0200b001c67621041bsi6331905pju.110.2022.03.25.13.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 13:12:21 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b="zKp/0cjj"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3989A3BDC28; Fri, 25 Mar 2022 11:55:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349946AbiCYD37 (ORCPT + 99 others); Thu, 24 Mar 2022 23:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231800AbiCYD35 (ORCPT ); Thu, 24 Mar 2022 23:29:57 -0400 X-Greylist: delayed 59360 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 24 Mar 2022 20:28:17 PDT Received: from out162-62-58-216.mail.qq.com (out162-62-58-216.mail.qq.com [162.62.58.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33468167C0 for ; Thu, 24 Mar 2022 20:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1648178890; bh=qpf8RfttfYwh4u1t5tUZIPgLdFSz2GuJZ8d8Lfe+YNY=; h=From:To:Cc:Subject:Date; b=zKp/0cjjj0eFzmVDM+aHIBGSSICVCxE98t3xM7nzlwB80BwL0eQqHxN3zew/lFaPy 9AqQWnJTRyXBT8xoK7nxzeLtRL3ygosDV+IbL8O4vEyaaU/aykSYHz+DCsEd5KakCy wbIQ1c6knMXduTD5yld/pZivE8R+TUl12MZuEm10= Received: from localhost.localdomain ([218.197.153.188]) by newxmesmtplogicsvrszc9.qq.com (NewEsmtp) with SMTP id 702A0625; Fri, 25 Mar 2022 11:28:02 +0800 X-QQ-mid: xmsmtpt1648178882tfv2y9h5u Message-ID: X-QQ-XMAILINFO: NDgMZBR9sMmaCLb8eMJ94f9WWsBOYfM7ZcyG4o9zcfIuXx52HdCTWuIC99mx8T d0C0H1QgCusvlNmtsj0x5aM+Pm0bPHlXsiRhYs3ghpq7gshK2rcIkbNntSDPlE6wlLzrhukdF6G3 tjZhJW0m6H17B4V27jAiwltaSh6y6y9ZORXnTa0mBp6MX7/E9ksiu2IOPfIl0KS2+OMVkCeuFV5i paa5vehYt4420Lt2zV5sdn3ZHqignEWJE/4ojTVd3nTwItXssqXF31U4WJNwyLJi9CBY36/LBIUK p1Q1mYyr6f4xx/y8ksF95JtxXN5gfje4H3z+Ebl3yIri+EE+WHp/CicREzKWWBw9K5aiFhYvkCma 1U87MFryLRCGC/EbiOMLDqaS3mmLSVXxlB3qbjh3gZ+xI2KItZNFzNTogFBVscHKqspz3cmF71xh keLJVNlgdGf1/Vcy0aDs/l1XNlKWA9E4FqlK0+Wf8o9EVjDpewiM2D2EE4cRAWlJcIP0sFC+1e+r H/6LsEjkjrbX5A8c9KPH/J0NVurprKBo0zeC9gyMu9yx9LYVqczuAStuRsWX+fZvySdIUaIxxvgv umv8gyquYyvewiv07eXST/SidovzlvzjOri9NpHYWcXNNdhXsZzrJcp4wmmF7XW/DeQOJtZa8CcJ tb/+xmxGMoFyA4LSfa7bSVowix1Uj5WQRXACiBo6EYUyqf3RNOJxbNW6pph2tQnqf7l3fRR84s0Y MqgoS/K52Inz7kaV6gsVOi1UIx4NFpGqu7iWhVRrSm7aEPyReswrU7zy0YdhXbCbFjlg4O18AJlV TyMuLu8un/lG0szAqJGhAWHahnQQd9/I8Wt1NuO/GciGUhsfReLi3o0lhpWT1v4kAF4xHanzEOVX PK2O7j+1jxv/l86w48E5ClBcjU+tws72XymAulCUSqQXCol3oVwxhVcUa/lX8iKGedfWEQ4kxLJC WTHOWfzspSeGBRWFekAVFsjdZFzFS/Zdo+nIb51CKblrIGnst9Tw== From: xkernel.wang@foxmail.com To: colyli@suse.de, kent.overstreet@gmail.com Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH] bcache: add a check for the return of kzalloc() Date: Fri, 25 Mar 2022 11:27:36 +0800 X-OQ-MSGID: <20220325032736.3545-1-xkernel.wang@foxmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaoke Wang kzalloc() is a memory allocation function which can return NULL when some internal memory errors happen. So it is better to check it to prevent potential wrong memory access. Signed-off-by: Xiaoke Wang --- Note: I just roughly handled the error and this seems to affect the original functionality. If this cannot fail, maybe the tag `__GFP_NOFAIL` should be considered. drivers/md/bcache/request.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index 6d1de88..1dc9821 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -1107,14 +1107,16 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio, * which would call closure_get(&dc->disk.cl) */ ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO); - ddip->d = d; - /* Count on the bcache device */ - ddip->orig_bdev = orig_bdev; - ddip->start_time = start_time; - ddip->bi_end_io = bio->bi_end_io; - ddip->bi_private = bio->bi_private; - bio->bi_end_io = detached_dev_end_io; - bio->bi_private = ddip; + if (ddip) { + ddip->d = d; + /* Count on the bcache device */ + ddip->orig_bdev = orig_bdev; + ddip->start_time = start_time; + ddip->bi_end_io = bio->bi_end_io; + ddip->bi_private = bio->bi_private; + bio->bi_end_io = detached_dev_end_io; + bio->bi_private = ddip; + } if ((bio_op(bio) == REQ_OP_DISCARD) && !blk_queue_discard(bdev_get_queue(dc->bdev))) --