Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp71234pxh; Thu, 7 Apr 2022 14:18:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz94Qo5iP2IMS7/oZv/QJI5xjGUCcxuJ2FNXMruHtJMqHnXA87YVn3ZIklCGNvqdHlH1c+L X-Received: by 2002:a17:903:1252:b0:154:ca85:59a0 with SMTP id u18-20020a170903125200b00154ca8559a0mr16222970plh.169.1649366304628; Thu, 07 Apr 2022 14:18:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649366304; cv=none; d=google.com; s=arc-20160816; b=PtMfSVl/swnu+ZCelZBKJ5YVqY6hLxMafr8b2IvyO0II9iD6nLIhVt+73EOIv7AwDh Q6n3g25LvtxbUJojLQs65Q7d6PMGNtJ0jRZqT1uuzJOh2/rYtDjh5lSVAyvS5Ab7Sn6P r1xs7VbDtKH8JJv5UD42PaYqKYqhX4blA5RJWylt3xIkqqBRpwE5o4V7IJ2AHUotp7HR uuXodpzQYG3izBky50cRN4GYUimkv6ppkACsO8dl+gZXdlTvq0w+EGntIXg5DKjaK3MC mwEao5+KIuPFNB5JDDRX+GRSt8dRp2HmUElp4XUSSLmhvk9088uW7ejLLtmvwvBi/wV9 CVrA== 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=Ar/51NvGFFYPTA9QjJD1sM7luYgOwEuIBJSxBbtt0ME=; b=IwTDR10Q3aHhf4JbH0sDXx52FxwI4VAUeCcOyhCDSHUC4d1Vac0vcG9R+lt2ZJAuuI E9ZapbzdvZmi8bC7EjwdmUzfPKrbWYe2Bb+Aba8GU9RMNjA+g8jZmjufIds2eRYTT6P0 TghWoR1Gxl3QSJooUS/huK/frCQLFVGd+qOcwAwI0hgKNQv2qeGVutVHWidM5YNsuksh SLyLA5mfNrEuacPrKLyg+SHzrAYp1nyoWYFN+cla9nj8MgAwpavth5heYt4b/1FsV8iT C0D/2GWtOR2Y36oN1TiDeVxotoQRi7PHYTPIdwoCZKkcIQvrVS30B8+qywENoEJq6ub3 7CvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=UzpJxv7T; 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 e4-20020a636904000000b003860f95cfa9si18934848pgc.855.2022.04.07.14.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 14:18:24 -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=UzpJxv7T; 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 B483F474A21; Thu, 7 Apr 2022 13:10:07 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345902AbiDGRBI (ORCPT + 99 others); Thu, 7 Apr 2022 13:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240058AbiDGRBI (ORCPT ); Thu, 7 Apr 2022 13:01:08 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C93271B84EE; Thu, 7 Apr 2022 09:58:59 -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-out1.suse.de (Postfix) with ESMTPS id 870DF212C6; Thu, 7 Apr 2022 16:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1649350738; 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=Ar/51NvGFFYPTA9QjJD1sM7luYgOwEuIBJSxBbtt0ME=; b=UzpJxv7Tj26hQd3NUYVEo3W6a+bU61Zrxv1ckGgFiK8TiyCPghkx6q4+aos/I6mHbFDtX7 suokcGykJ7l7g/8VM+v9Uc19t2iC8QM+W1EBKgZrdcTAFHyP3a02O80aygwNMtEr5xSGkg JMCOtZPMYYFzLmWHGbLVQIVxJzfh+s0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1649350738; 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=Ar/51NvGFFYPTA9QjJD1sM7luYgOwEuIBJSxBbtt0ME=; b=XXW4fcNXbW1GimdrWCBs8ye9B3iSY/9QZCIXRQ44G22rArjbi5OfpoM/PBKiuWTZBH1WVf GRO3D19TUVphqtAA== 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 7A8C513485; Thu, 7 Apr 2022 16:58:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /D8eElEYT2KfGwAAMHmgww (envelope-from ); Thu, 07 Apr 2022 16:58:57 +0000 Message-ID: <89ad6f76-a947-edd9-2de3-84dbc4901835@suse.de> Date: Fri, 8 Apr 2022 00:58:55 +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] bcache: add a check for the return of kzalloc() Content-Language: en-US To: xkernel.wang@foxmail.com Cc: linux-bcache@vger.kernel.org, kent.overstreet@gmail.com, linux-kernel@vger.kernel.org References: From: Coly Li In-Reply-To: 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/25/22 11:27 AM, xkernel.wang@foxmail.com wrote: > 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. The error handling is incorrect indeed. And IIRC there is someone else already fixes it properly and the patch is not upstream yet. Thanks. Coly Li > 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)))