Re: [PATCH]btrfs: avoid comparing with NULL pointer

From: Liuwenyi
Date: Wed Jan 27 2010 - 09:20:07 EST


ä 2010å01æ27æ 16:00, Yan, Zheng åé:
2010/1/27 Liuwenyi<qingshenlwy@xxxxxxxxx>:
In this patch, I adjust the seqence of if-conditions.
It will assess the page->private situation.
First, we make sure the page->private is not null.
And then, we can do some with this page->private.

---
Signed-off-by: Liuwenyi<qingshenlwy@xxxxxxxxx>
Cc: Chris Mason<chris.mason@xxxxxxxxxx>
Cc: Yan Zheng<zheng.yan@xxxxxxxxxx>
Cc: Josef Bacik<jbacik@xxxxxxxxxx>
Cc: Jens Axboe<jens.axboe@xxxxxxxxxx>
Cc: linux-btrfs@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx

---
fs/btrfs/disk-io.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 009e3bd..a300dca 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1407,11 +1407,11 @@ static int bio_ready_for_csum(struct bio *bio)

bio_for_each_segment(bvec, bio, i) {
page = bvec->bv_page;
- if (page->private == EXTENT_PAGE_PRIVATE) {
+ if (!page->private) {
length += bvec->bv_len;
continue;
}
- if (!page->private) {
+ if (page->private == EXTENT_PAGE_PRIVATE) {
length += bvec->bv_len;
continue;
}
--
Why do you want to do this? The code is perfect safe even
page->private is NULL. Furthermore, your patch is malformed.

Yan, Zheng
Yes, I agree with you, this code is safe.
But I think we should check whether the pointer is available first.
It is unnecessary judge the "(page->private == EXTENT_PAGE_PRIVATE)"
while page->private is null.


---
Best Regards,
Liuwenyi
2010-1-27

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/