* [PATCH] ext4: Use IS_ERR_OR_NULL() helper function
@ 2025-07-30 6:38 Xichao Zhao
2025-07-30 6:49 ` Al Viro
0 siblings, 1 reply; 3+ messages in thread
From: Xichao Zhao @ 2025-07-30 6:38 UTC (permalink / raw)
To: tytso, adilger.kernel; +Cc: linux-ext4, linux-kernel, Xichao Zhao
Use the IS_ERR_OR_NULL() helper instead of open-coding a NULL and
an error pointer checks to simplify the code and improve readability.
Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
---
fs/ext4/namei.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index d83f91b62317..7dff0dc70d0c 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -723,7 +723,7 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
struct stats stats;
printk("%s%3u:%03u hash %8x/%8x ",levels?"":" ", i, block, hash, range);
bh = ext4_bread(NULL,dir, block, 0);
- if (!bh || IS_ERR(bh))
+ if (IS_ERR_OR_NULL(bh))
continue;
stats = levels?
dx_show_entries(hinfo, dir, ((struct dx_node *) bh->b_data)->entries, levels - 1):
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: Use IS_ERR_OR_NULL() helper function
2025-07-30 6:38 [PATCH] ext4: Use IS_ERR_OR_NULL() helper function Xichao Zhao
@ 2025-07-30 6:49 ` Al Viro
2025-07-30 9:42 ` Xichao Zhao
0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2025-07-30 6:49 UTC (permalink / raw)
To: Xichao Zhao; +Cc: tytso, adilger.kernel, linux-ext4, linux-kernel
On Wed, Jul 30, 2025 at 02:38:23PM +0800, Xichao Zhao wrote:
> Use the IS_ERR_OR_NULL() helper instead of open-coding a NULL and
> an error pointer checks to simplify the code and improve readability.
IS_ERR_OR_NULL() is almost always a bad idea. ext4_bread() *is* one
of the cases where NULL is a legitimate return values that is not an
error - it indicates a hole in a sparse file (BTW, not sure if it
can legitimately occur in a directory); the thing is, among the
functions that can return both NULL and ERR_PTR() the meaning assigned
to NULL varies a lot; so much that "ERR_PTR() or NULL" has no good
semantics.
Most of the uses are either sloppy code from somebody who couldn't be
arsed to find out whether it's pointer-or-NULL or pointer-or-ERR_PTR()
or misguided "defensive" crap. Any caller that is *not* of that sort
is drowning in a pile of garbage. Let's not breed that...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-30 9:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30 6:38 [PATCH] ext4: Use IS_ERR_OR_NULL() helper function Xichao Zhao
2025-07-30 6:49 ` Al Viro
2025-07-30 9:42 ` Xichao Zhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox