* [PATCH 01/2] bcache: add code comments for bch_btree_node_get() and __bch_btree_node_alloc()
@ 2023-11-18 16:40 Coly Li
2023-11-18 16:40 ` [PATCH 2/2] bcache: avoid NULL checking to c->root in run_cache_set() Coly Li
0 siblings, 1 reply; 2+ messages in thread
From: Coly Li @ 2023-11-18 16:40 UTC (permalink / raw)
To: linux-bcache; +Cc: Coly Li
This patch adds code comments to bch_btree_node_get() and
__bch_btree_node_alloc() that NULL pointer will not be returned and it
is unnecessary to check NULL pointer by the callers of these routines.
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/btree.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 79f1fa4a0d55..de3019972b35 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -1000,6 +1000,9 @@ static struct btree *mca_alloc(struct cache_set *c, struct btree_op *op,
*
* The btree node will have either a read or a write lock held, depending on
* level and op->lock.
+ *
+ * Note: Only error code or btree pointer will be returned, it is unncessary
+ * for callers to check NULL pointer.
*/
struct btree *bch_btree_node_get(struct cache_set *c, struct btree_op *op,
struct bkey *k, int level, bool write,
@@ -1111,6 +1114,10 @@ static void btree_node_free(struct btree *b)
mutex_unlock(&b->c->bucket_lock);
}
+/*
+ * Only error code or btree pointer will be returned, it is unncessary for
+ * callers to check NULL pointer.
+ */
struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op,
int level, bool wait,
struct btree *parent)
--
2.35.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] bcache: avoid NULL checking to c->root in run_cache_set()
2023-11-18 16:40 [PATCH 01/2] bcache: add code comments for bch_btree_node_get() and __bch_btree_node_alloc() Coly Li
@ 2023-11-18 16:40 ` Coly Li
0 siblings, 0 replies; 2+ messages in thread
From: Coly Li @ 2023-11-18 16:40 UTC (permalink / raw)
To: linux-bcache; +Cc: Coly Li
In run_cache_set() after c->root returned from bch_btree_node_get(), it
is checked by IS_ERR_OR_NULL(). Indeed it is unncessary to check NULL
because bch_btree_node_get() will not return NULL pointer to caller.
This patch replaces IS_ERR_OR_NULL() by IS_ERR() for the above reason.
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index c7ecc7058d77..bfe1685dbae5 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -2018,7 +2018,7 @@ static int run_cache_set(struct cache_set *c)
c->root = bch_btree_node_get(c, NULL, k,
j->btree_level,
true, NULL);
- if (IS_ERR_OR_NULL(c->root))
+ if (IS_ERR(c->root))
goto err;
list_del_init(&c->root->list);
--
2.35.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-18 16:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-18 16:40 [PATCH 01/2] bcache: add code comments for bch_btree_node_get() and __bch_btree_node_alloc() Coly Li
2023-11-18 16:40 ` [PATCH 2/2] bcache: avoid NULL checking to c->root in run_cache_set() Coly Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).