From patchwork Fri Feb 3 03:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Wang X-Patchwork-Id: 52277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp620415wrn; Thu, 2 Feb 2023 19:33:06 -0800 (PST) X-Google-Smtp-Source: AK7set9P2RX4huXgTHrmdX2ejBerTh18lioczjNuxe6ke4ETUtYVXkrWA/kqnsOB4r0x/PmKYSF2 X-Received: by 2002:a05:6402:54b:b0:499:b4ce:b26e with SMTP id i11-20020a056402054b00b00499b4ceb26emr9439960edx.40.1675395186239; Thu, 02 Feb 2023 19:33:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675395186; cv=none; d=google.com; s=arc-20160816; b=HKDd3vBHY0eSmn3lfx7EwJXSqX6rdgRtcRtoa5VFg4OTtAS+C6gPfv1RrulyhIZpeh Xzm4d4A2N8C8eVbASD0Cj7NQw+M4Il0UC6EbdXmp89oKleyVpG9h1adkOEjYumPNk7c1 /mvO3xWd0C6H5DP+GwbmP3fP6XWb/ZcexeCtWygApaACWYhsUxI6W+ma+Jwm5yYkBMyN dmU9U9FssPTpPnsFA6TmPvetuWqp4qH7DwXbMDcQnzLZy4TUi2soPgWzjG1XFMyUNDxT UbShfUaIeEH1cq3QYjoBkPkizBAfHFE6RG7SWUv4VsmaFwkmurOo0q+bP5YankwUSD4U dBHQ== 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=NcEgx6AbcT9pJumUCsgIg3kMZkUia2+9w4tAhaARoIg=; b=A9Ff3ihJNjwawbQ5QxGixfObOdX1qAMzZT9Jwe8tw9ljy/JwERfWhBqw0oHkmzzTTh A2XjHbWzXRZ/Dz37wMF+HV1QsWbEC6+nzGsk9WjfPN7NdgWSZYS5hQb7ikgiXltNlitz AYujLkNCfh7hG9xlRVdj7Im7Oluq9SZFHMGcEhWeQL20Lc8RhIH7IbGs/dQv1pDC2gh8 mQ+bHmTdK9/OGKssUaMmvpernuO41dLRCBIKelzgaa30/PuPmPr/UbN78UwywuPc4Acb rQxJD9HW1icPwNTI+LN4WPFQyI+GhoUFQU65oHCnXhUyOWC4jdsaV9jixfE5/U8NDJc3 c4eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=GlwDnFkY; 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 b5-20020a0564021f0500b0049ea0e7ae42si1234482edb.393.2023.02.02.19.32.40; Thu, 02 Feb 2023 19:33:06 -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=GlwDnFkY; 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 S232054AbjBCD2F (ORCPT + 99 others); Thu, 2 Feb 2023 22:28:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbjBCD2E (ORCPT ); Thu, 2 Feb 2023 22:28:04 -0500 Received: from m12.mail.163.com (m12.mail.163.com [123.126.96.234]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CDDA9677A0; Thu, 2 Feb 2023 19:27:56 -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=NcEgx 6AbcT9pJumUCsgIg3kMZkUia2+9w4tAhaARoIg=; b=GlwDnFkYTTBJJN897BHnU kgu/Uc3YE1iLmrzCyWLbnygIr1HutPkJysuwXS3/TtUXBeqPG6inoSlWahxhHxyU OGvzqVYYkMcsLJzt8ONSl/RakmjIS0groekwMIoWm3DOsetW51XYGm6HfZQmDp21 R8bfaQlT321XAb1Aikhov8= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by smtp18 (Coremail) with SMTP id JNxpCgAHMZQ2f9xj+gyqCg--.54348S2; Fri, 03 Feb 2023 11:27:50 +0800 (CST) From: Zheng Wang 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 Subject: [PATCH v2] bcache: Remove some unnecessary NULL point check for the return value of __bch_btree_node_alloc-related pointer Date: Fri, 3 Feb 2023 11:27:50 +0800 Message-Id: <20230203032750.578589-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: JNxpCgAHMZQ2f9xj+gyqCg--.54348S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw13CFykur45uFW3tw1rXrb_yoW5AFW3pr W29r9Iyr97Xr4UCr9Yg3WvvFyfXw12vFWUGr93u3WxZry7AFyrCay0934jvrWUuFWxWF4U Zr40yw1UXr4UtF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziaiiDUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQhcLU1aEEPEVVwAAs8 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756779182974843114?= X-GMAIL-MSGID: =?utf-8?q?1756779182974843114?= 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 --- v2: - Replace more checks --- drivers/md/bcache/btree.c | 10 +++++----- drivers/md/bcache/super.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 147c493a989a..7c21e54468bf 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); @@ -1340,7 +1340,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, memset(new_nodes, 0, sizeof(new_nodes)); closure_init_stack(&cl); - while (nodes < GC_MERGE_NODES && !IS_ERR_OR_NULL(r[nodes].b)) + while (nodes < GC_MERGE_NODES && !IS_ERR(r[nodes].b)) keys += r[nodes++].keys; blocks = btree_default_blocks(b->c) * 2 / 3; @@ -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; } @@ -1487,7 +1487,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op, bch_keylist_free(&keylist); for (i = 0; i < nodes; i++) - if (!IS_ERR_OR_NULL(new_nodes[i])) { + if (!IS_ERR(new_nodes[i])) { btree_node_free(new_nodes[i]); rw_unlock(true, new_nodes[i]); } @@ -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..7660962e7b8b 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1724,7 +1724,7 @@ static void cache_set_flush(struct closure *cl) if (!IS_ERR_OR_NULL(c->gc_thread)) kthread_stop(c->gc_thread); - if (!IS_ERR_OR_NULL(c->root)) + if (!IS_ERR(c->root)) list_add(&c->root->list, &c->btree_cache); /* @@ -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);