bcache: Remove some unnecessary NULL point check for the return value of __bch_btree_node_alloc-related pointer
Message ID | 20230203022759.576832-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp604063wrn; Thu, 2 Feb 2023 18:43:50 -0800 (PST) X-Google-Smtp-Source: AK7set+zvshvDrC87pdNbGcZdi5syt27p+0gO6mEGYTzRwCRS2C5SKw/i74xPp/VqPgzh5tP/Ab0 X-Received: by 2002:a17:906:fc20:b0:860:5723:a5e5 with SMTP id ov32-20020a170906fc2000b008605723a5e5mr8865554ejb.69.1675392229960; Thu, 02 Feb 2023 18:43:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675392229; cv=none; d=google.com; s=arc-20160816; b=pmoQN81BJp9oK9H/82fsVznJ5F7CmEQeHx9YXWPeQzKEd5UXKkm8vOBfh8AdLMlNDd gJxo4oGFWw7J5u2AwsCLRTSln0cP/PCVQuJLhAxb8jRL9k8YjN7UI2FsXLOKv24xeRMa cq8bbpa/jrl2680jlhQeo3SydX29APpPSfU9xMs6k/SYQoKuZ6hJ7isJ6xz0c40qjdNh 5Bwcu4msjCr8/VyKFCS3myFKOu3pT3X5mZGKP7iZIPSvq/aydGvg8004D6hGwQ00hW3B Kp6zo7Y4HvY4o9M6rjgFIPq+Zf/nu8aU8lKYMR5MbjVy1VgNCoFyjqySWMx6zB6wSHBs 8Ojw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Ezq48SMfSzSfU6vEdNHKpwfR4sSbk6riVgvGC0cf2ec=; b=exDfO+1fp58+q9Eh1F5n4RYDfg+8F0OIn/2a4iWIGW2JBCwYo51YAqjSzwkYc1H8NH f5H3U4ADe67R+DkIPh3QEQRVu2voXZ7/z2q6QK8DOOM5voeAGB28bPVjdR9qVIInoIJn Z5pV4pHvbjVScQKZG9/Oo4ruU7IH2LL2EXm//x5PilQCsJZtQzrCE9UUZgNqbHUztCYi Rxf9duzpYvZ3CKW/fFDyWa9ZhGZdQqGldaiKjor5QPspXa3uIPe7iKbS3vTvA1bHx4Ca pmIosQ2yMjA5WokoSRUzeqqYnwj8IiWgLjYrkCHknHgqRexcyZdjH2yMEOQcCS3u4Zbg yBYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="Nj4sq7h/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gk13-20020a17090790cd00b007adb388df38si1271989ejb.706.2023.02.02.18.43.23; Thu, 02 Feb 2023 18:43:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="Nj4sq7h/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231814AbjBCC2O (ORCPT <rfc822;il.mystafa@gmail.com> + 99 others); Thu, 2 Feb 2023 21:28:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbjBCC2M (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 2 Feb 2023 21:28:12 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 64E8C36471; Thu, 2 Feb 2023 18:28:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Ezq48 SMfSzSfU6vEdNHKpwfR4sSbk6riVgvGC0cf2ec=; b=Nj4sq7h/LlJ/oGmvFBB3q w/DVWM+HekdCCSnK5XqEeDd/aBUVYLMuxtFF7dH7kp2q1lxVkZOGROsNX41dxDp2 eEyDfFIIHZtgA6PMH0ZHI5ZhV87j2PWht2Fm/SiildhQG2wI4itM8B+Vpn1W8FyB UcBiizNP2Tw+KKB1H8Rrp4= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wDn5Kwwcdxj1juOCg--.53946S2; Fri, 03 Feb 2023 10:28:00 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: colyli@suse.de Cc: stable@vger.kernel.org, hackerzheng666@gmail.com, kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, alex000young@gmail.com, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH] bcache: Remove some unnecessary NULL point check for the return value of __bch_btree_node_alloc-related pointer Date: Fri, 3 Feb 2023 10:27:59 +0800 Message-Id: <20230203022759.576832-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wDn5Kwwcdxj1juOCg--.53946S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww4UGry5ArWfXrW5Gr15Arb_yoW8Zw1UpF W29ry3A34kWr4UCr98C3W0vFyrZw12vFWUGr93u3WfZr9rZr1rCFWj9ryUZrWUurWxWF42 vr40yw1UXr4UtF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziI385UUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXBILU1Xl5gKj0gAAsz X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756776083074957677?= X-GMAIL-MSGID: =?utf-8?q?1756776083074957677?= |
Series |
bcache: Remove some unnecessary NULL point check for the return value of __bch_btree_node_alloc-related pointer
|
|
Commit Message
Zheng Wang
Feb. 3, 2023, 2:27 a.m. UTC
Due to the previously fix of __bch_btree_node_alloc, the return value will
never be a NULL pointer. So IS_ERR is enough to handle the failure
situation. Fix it by replacing IS_ERR_OR_NULL check to IS_ERR check.
Fixes: cafe56359144 ("bcache: A block layer cache")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/md/bcache/btree.c | 6 +++---
drivers/md/bcache/super.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
Comments
Hello, After writing the patch, I found there may be more places to replace IS_ERR_OR_NULL to IS_ERR. If the alloc of node will never be NULL, the additional NULL check of nodes after allocation may also be useless. This patch just fixes the check around the alloc. I'm not sure about other places for my limited understanding of the code in bcache. Thanks, Zheng Wang Zheng Wang <zyytlz.wz@163.com> 于2023年2月3日周五 10:28写道: > > Due to the previously fix of __bch_btree_node_alloc, the return value will > never be a NULL pointer. So IS_ERR is enough to handle the failure > situation. Fix it by replacing IS_ERR_OR_NULL check to IS_ERR check. > > Fixes: cafe56359144 ("bcache: A block layer cache") > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > drivers/md/bcache/btree.c | 6 +++--- > drivers/md/bcache/super.c | 2 +- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c > index 147c493a989a..417cd7c436c4 100644 > --- a/drivers/md/bcache/btree.c > +++ b/drivers/md/bcache/btree.c > @@ -1138,7 +1138,7 @@ static struct btree *btree_node_alloc_replacement(struct btree *b, > { > struct btree *n = bch_btree_node_alloc(b->c, op, b->level, b->parent); > > - if (!IS_ERR_OR_NULL(n)) { > + if (!IS_ERR(n)) { > mutex_lock(&n->write_lock); > bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort); > bkey_copy_key(&n->key, &b->key); > @@ -1352,7 +1352,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, > > for (i = 0; i < nodes; i++) { > new_nodes[i] = btree_node_alloc_replacement(r[i].b, NULL); > - if (IS_ERR_OR_NULL(new_nodes[i])) > + if (IS_ERR(new_nodes[i])) > goto out_nocoalesce; > } > > @@ -1669,7 +1669,7 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op, > if (should_rewrite) { > n = btree_node_alloc_replacement(b, NULL); > > - if (!IS_ERR_OR_NULL(n)) { > + if (!IS_ERR(n)) { > bch_btree_node_write_sync(n); > > bch_btree_set_root(n); > diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c > index ba3909bb6bea..92de714fe75e 100644 > --- a/drivers/md/bcache/super.c > +++ b/drivers/md/bcache/super.c > @@ -2088,7 +2088,7 @@ static int run_cache_set(struct cache_set *c) > > err = "cannot allocate new btree root"; > c->root = __bch_btree_node_alloc(c, NULL, 0, true, NULL); > - if (IS_ERR_OR_NULL(c->root)) > + if (IS_ERR(c->root)) > goto err; > > mutex_lock(&c->root->write_lock); > -- > 2.25.1 >
> 2023年2月3日 10:43,Zheng Hacker <hackerzheng666@gmail.com> 写道: > > Hello, > > After writing the patch, I found there may be more places to replace > IS_ERR_OR_NULL to IS_ERR. > If the alloc of node will never be NULL, the additional NULL check of > nodes after allocation may also > be useless. This patch just fixes the check around the alloc. I'm not > sure about other places for my > limited understanding of the code in bcache. This was why I suggested you to post an extra cleanup patch like this. You may just add more changes as you mentioned into this patch and post another updated version. Thanks. Coly Li > > Thanks, > Zheng Wang > > Zheng Wang <zyytlz.wz@163.com> 于2023年2月3日周五 10:28写道: >> >> Due to the previously fix of __bch_btree_node_alloc, the return value will >> never be a NULL pointer. So IS_ERR is enough to handle the failure >> situation. Fix it by replacing IS_ERR_OR_NULL check to IS_ERR check. >> >> Fixes: cafe56359144 ("bcache: A block layer cache") >> Signed-off-by: Zheng Wang <zyytlz.wz@163.com> >> --- >> drivers/md/bcache/btree.c | 6 +++--- >> drivers/md/bcache/super.c | 2 +- >> 2 files changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c >> index 147c493a989a..417cd7c436c4 100644 >> --- a/drivers/md/bcache/btree.c >> +++ b/drivers/md/bcache/btree.c >> @@ -1138,7 +1138,7 @@ static struct btree *btree_node_alloc_replacement(struct btree *b, >> { >> struct btree *n = bch_btree_node_alloc(b->c, op, b->level, b->parent); >> >> - if (!IS_ERR_OR_NULL(n)) { >> + if (!IS_ERR(n)) { >> mutex_lock(&n->write_lock); >> bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort); >> bkey_copy_key(&n->key, &b->key); >> @@ -1352,7 +1352,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, >> >> for (i = 0; i < nodes; i++) { >> new_nodes[i] = btree_node_alloc_replacement(r[i].b, NULL); >> - if (IS_ERR_OR_NULL(new_nodes[i])) >> + if (IS_ERR(new_nodes[i])) >> goto out_nocoalesce; >> } >> >> @@ -1669,7 +1669,7 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op, >> if (should_rewrite) { >> n = btree_node_alloc_replacement(b, NULL); >> >> - if (!IS_ERR_OR_NULL(n)) { >> + if (!IS_ERR(n)) { >> bch_btree_node_write_sync(n); >> >> bch_btree_set_root(n); >> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c >> index ba3909bb6bea..92de714fe75e 100644 >> --- a/drivers/md/bcache/super.c >> +++ b/drivers/md/bcache/super.c >> @@ -2088,7 +2088,7 @@ static int run_cache_set(struct cache_set *c) >> >> err = "cannot allocate new btree root"; >> c->root = __bch_btree_node_alloc(c, NULL, 0, true, NULL); >> - if (IS_ERR_OR_NULL(c->root)) >> + if (IS_ERR(c->root)) >> goto err; >> >> mutex_lock(&c->root->write_lock); >> -- >> 2.25.1 >>
Coly Li <colyli@suse.de> 于2023年2月3日周五 10:46写道: > > > > > 2023年2月3日 10:43,Zheng Hacker <hackerzheng666@gmail.com> 写道: > > > > Hello, > > > > After writing the patch, I found there may be more places to replace > > IS_ERR_OR_NULL to IS_ERR. > > If the alloc of node will never be NULL, the additional NULL check of > > nodes after allocation may also > > be useless. This patch just fixes the check around the alloc. I'm not > > sure about other places for my > > limited understanding of the code in bcache. > > This was why I suggested you to post an extra cleanup patch like this. > > You may just add more changes as you mentioned into this patch and post another updated version. > Get it. Will do right now. Thanks, Zheng Wang
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 147c493a989a..417cd7c436c4 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -1138,7 +1138,7 @@ static struct btree *btree_node_alloc_replacement(struct btree *b, { struct btree *n = bch_btree_node_alloc(b->c, op, b->level, b->parent); - if (!IS_ERR_OR_NULL(n)) { + if (!IS_ERR(n)) { mutex_lock(&n->write_lock); bch_btree_sort_into(&b->keys, &n->keys, &b->c->sort); bkey_copy_key(&n->key, &b->key); @@ -1352,7 +1352,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, for (i = 0; i < nodes; i++) { new_nodes[i] = btree_node_alloc_replacement(r[i].b, NULL); - if (IS_ERR_OR_NULL(new_nodes[i])) + if (IS_ERR(new_nodes[i])) goto out_nocoalesce; } @@ -1669,7 +1669,7 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op, if (should_rewrite) { n = btree_node_alloc_replacement(b, NULL); - if (!IS_ERR_OR_NULL(n)) { + if (!IS_ERR(n)) { bch_btree_node_write_sync(n); bch_btree_set_root(n); diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index ba3909bb6bea..92de714fe75e 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2088,7 +2088,7 @@ static int run_cache_set(struct cache_set *c) err = "cannot allocate new btree root"; c->root = __bch_btree_node_alloc(c, NULL, 0, true, NULL); - if (IS_ERR_OR_NULL(c->root)) + if (IS_ERR(c->root)) goto err; mutex_lock(&c->root->write_lock);