Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp74445pxh; Thu, 7 Apr 2022 14:24:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcySSHxOMCouDxAklLX8zKMA5Lxdi8QpeJQCstcN5G2aeQdJtKFkFqJSTkaOQOkjc2XSAU X-Received: by 2002:a17:902:e949:b0:14b:1f32:e926 with SMTP id b9-20020a170902e94900b0014b1f32e926mr15829221pll.170.1649366677115; Thu, 07 Apr 2022 14:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649366677; cv=none; d=google.com; s=arc-20160816; b=ClBR9XPqtCs4AchTGIk7LjqYwItdVWiUJ5jQ0hOELt3e55hLg4wEkfSIMGkY97xoIb 5JX1DYPkNBgI7RGLRZo+pJm24hBwy9mTb73UKr0J8evKujlx/mBDaWqs2fpHGZZXhIH/ 58a4Hll6+i8tnRjdkQao/yIW7TjazSEaRIk0r7Kx4OtmIkfWape+9rfIsyds3Wm2sN42 g5ov/+F4ajZME6Q4j4/yNPb1VDl4FppZxcimIjpOmsRyEsksP/AqJTMx4xmI8v4XDLWb 2IDkiJ8NWjFaZWRTIINcLHkkVlns8dWQoNKf7cqxiqsvILJq5jfzLU6GFFqrhLVN/kxp 9JRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=z2Bed+Unj8/31PP3+tIX1i22uICkwYo9ioyedTJiWT8=; b=eCmu6rcwh13CLscjAjqE9fAwMAsA/IEdi5mBta3SNAnPGynh8wfqhaJ2fphX/ebGUa 2C5N7cy6CQn+y587D7se9sN2pdvKMElGyhueVxZ4clKIdD++81ApMXyx8yrkeZ/bTz5Z O6EFhLEDp7wDH2IbEjugoyzUMKapfbCO9qAKyEpuU1on3BoYV6zKmpM3hHkN0dbD6be3 avEz4/Bt9tD/VaDcFZnt3CqBYUC8tYDgswED5R429w0fKHk6ARommudKxPhOT1eOkOAo vopl1dC5CH3e/9uuHSDWVqrQLmFyZUasDZcdV6QmrzKF6r+t+kvKSXvWO0Q+jj6/bM/w 4XTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=WlaomzRy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id l12-20020a056a00140c00b004fa5a66305esi19860386pfu.36.2022.04.07.14.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 14:24:37 -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=@suse.de header.s=susede2_rsa header.b=WlaomzRy; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; 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=suse.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EEADE2F1419; Thu, 7 Apr 2022 13:16:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345909AbiDGRBm (ORCPT + 99 others); Thu, 7 Apr 2022 13:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345907AbiDGRBk (ORCPT ); Thu, 7 Apr 2022 13:01:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319161C8858; Thu, 7 Apr 2022 09:59:39 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D40631F85E; Thu, 7 Apr 2022 16:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1649350777; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z2Bed+Unj8/31PP3+tIX1i22uICkwYo9ioyedTJiWT8=; b=WlaomzRyVsIgdnjDN42Ge69qIdv4Xcv0hottLq9lRt1BUJTW7hVTkNCsx3MEEbL/5GspRM oh1bjnM3PoLt055R9wRWQV3SNwGzlvjaUk4f6lrgCsYDxPEDUTgd9WAyvhV1LsSEenx8bn 9VW1A38KAIBSsYlYMlZEHvdkZAqtjCo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1649350777; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z2Bed+Unj8/31PP3+tIX1i22uICkwYo9ioyedTJiWT8=; b=lx3mehWOWKnYn7pyR2cHSOOAhhjiuQQnozm1Ucy/jL1WgWceOJhu377M2mi/dlCho7cLTy hIdrWBTFJnEjI/AA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CB8FC13485; Thu, 7 Apr 2022 16:59:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IgnoJXgYT2L8GwAAMHmgww (envelope-from ); Thu, 07 Apr 2022 16:59:36 +0000 Message-ID: Date: Fri, 8 Apr 2022 00:59:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v1] bcache: Check for NULL return of kzalloc() Content-Language: en-US To: QintaoShen Cc: linux-bcache@vger.kernel.org, kent.overstreet@gmail.com, linux-kernel@vger.kernel.org References: <1648114074-10045-1-git-send-email-unSimple1993@163.com> From: Coly Li In-Reply-To: <1648114074-10045-1-git-send-email-unSimple1993@163.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 On 3/24/22 5:27 PM, QintaoShen wrote: > kzalloc() is a memory allocation function which may return a NULL pointer. > Therefore, it is better to check the return value of kzalloc() to avoid potential > NULL-pointer dereference. > > Signed-off-by: QintaoShen > --- > drivers/md/bcache/request.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c > index fdd0194..232ffe3 100644 > --- a/drivers/md/bcache/request.c > +++ b/drivers/md/bcache/request.c > @@ -1105,6 +1105,9 @@ 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); > + if (!ddpp) > + return ; This is wrong. If you test your patch, you may experience a system hang I guess. Coly Li > + > ddip->d = d; > /* Count on the bcache device */ > ddip->orig_bdev = orig_bdev;