Skip to contentSkip to conversation

btrfs: avoid comparing with NULL pointer

PATCH In review Liuwenyi 2 participants 3 messages Jan 27, 2010 Btrfs file system

lore
Share & tools
lore

Liuwenyi

author
#0 lore raw

PATCH 1/1 btrfs: avoid comparing with NULL pointer

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.

---

---
fs/btrfs/disk-io.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +0 -0
index 009e3bd..a300dca 100644
@@ -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;
}

Signature · 7 lines
1.6.6


---
Best Regards,
Liuwenyi
2010-01-277
#1 lore raw

2010/1/27 Liuwenyi <[email protected]>:

Quoted 27 lines

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.

---

---
fs/btrfs/disk-io.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +0 -1
index 009e3bd..a300dca 100644
@@ -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) {

fs/btrfs/disk-io.c static int bio_ready_for_csum(struct bio *bio)

Quoted 10 lines
fs/btrfs/disk-io.c +2 -2
+ 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

author
#2 lore raw

=E4=BA=8E 2010=E5=B9=B401=E6=9C=8827=E6=97=A5 16:00, Yan, Zheng =E5=86=99= =E9=81=93:

Quoted 20 lines

2010/1/27 Liuwenyi<[email protected]>:
=20

Quoted 18 lines

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.

---

---
fs/btrfs/disk-io.c | 4 ++--

1 files changed, 2 insertions(+), 2 deletions(-)
Quoted 5 lines

fs/btrfs/disk-io.c static int bio_ready_for_csum(struct bio *bi=

Quoted 5 lines
fs/btrfs/disk-io.c +0 -0
index 009e3bd..a300dca 100644
@@ -1407,11 +1407,11 @@ static int bio_ready_for_csum(struct bio *bi=

o)

Quoted 15 lines
Quoted 5 lines
fs/btrfs/disk-io.c +1 -1
 bio_for_each_segment(bvec, bio, i) {
 page =3D bvec->bv_page;
- if (page->private =3D=3D EXTENT_PAGE_PRIVATE) {
+ if (!page->private) {

fs/btrfs/disk-io.c static int bio_ready_for_csum(struct bio *bi=

Quoted 10 lines
fs/btrfs/disk-io.c +1 -2
 length +=3D bvec->bv_len;
 continue;
 }
- if (!page->private) {
+ if (page->private =3D=3D EXTENT_PAGE_PRIVATE) {
 length +=3D bvec->bv_len;
 continue;
 }
--
    =20
Quoted 5 lines

Why do you want to do this? The code is perfect safe even page->private is NULL. Furthermore, your patch is malformed.

Yan, Zheng
=20

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 =3D=3D EXTENT_PAGE_PRIVATE)= "
while page->private is null.

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