Skip to contentSkip to conversation

writeback: fix incorrect return value type of bdi_dirty_limit

PATCH Superseded Namjae Jeon 3 participants 6 messages Aug 18, 2012 – Aug 20, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/3 writeback: fix incorrect return value type of bdi_dirty_limit

unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)

Above function return type is unsigned long, but return value is kept in "u64 bdi_dirty".
It can return incorrect value by type casting.

---
 mm/page-writeback.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page-writeback.c +1 -1
index 49133b6..73a7a06 100644
@@ -546,7 +546,7 @@ static unsigned long hard_dirty_limit(unsigned long thresh)
  */
 unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
 {
-	u64 bdi_dirty;
+	unsigned long bdi_dirty;
 	long numerator, denominator;
 
 	/*
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 5 lines · Namjae Jeon

unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)

Above function return type is unsigned long, but return value is kept in "u64 bdi_dirty".
It can return incorrect value by type casting.

I don't see how the cast can return wrong value. The u64 is necessary for the intermediate calculations.

Thanks,
Fengguang

Quoted 20 lines
---
 mm/page-writeback.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page-writeback.c +1 -1
index 49133b6..73a7a06 100644
@@ -546,7 +546,7 @@ static unsigned long hard_dirty_limit(unsigned long thresh)
  */
 unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
 {
-	u64 bdi_dirty;
+	unsigned long bdi_dirty;
 	long numerator, denominator;
 
 	/*
Signature · 1 line
1.7.9.5
#2 lore raw

Il 19/08/2012 04:17, Fengguang Wu ha scritto:

Quoted 7 lines · Namjae Jeon
Quoted 5 lines

unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)

Above function return type is unsigned long, but return value is kept in "u64 bdi_dirty".
It can return incorrect value by type casting.

Quoted 6 lines

I don't see how the cast can return wrong value. The u64 is necessary for the intermediate calculations.

Thanks,
Fengguang

We are sure u64 is 8byte long, but unsigned long is 4byte long on 32-bit machine, so if bdi_dirty can assume values bigger than 2^32 there is an implicit truncate of its value, isn't it?

Marco

#3 lore raw

Il 19/08/2012 12:23, Marco Stornelli ha scritto:

Quoted 16 lines

Il 19/08/2012 04:17, Fengguang Wu ha scritto:

Quoted 8 lines · Namjae Jeon
Quoted 6 lines

unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)

Above function return type is unsigned long, but return value is kept in "u64 bdi_dirty".
It can return incorrect value by type casting.

Quoted 6 lines

I don't see how the cast can return wrong value. The u64 is necessary for the intermediate calculations.

Thanks,
Fengguang

Quoted 5 lines

We are sure u64 is 8byte long, but unsigned long is 4byte long on 32-bit machine, so if bdi_dirty can assume values bigger than 2^32 there is an implicit truncate of its value, isn't it?

Marco

Sorry but I didn't see the code, it seems not possible so the wrong situation can't happen. Maybe we can simply add a comment, nothing more.

Marco

#4 lore raw
In reply to Marco Stornelli

2012/8/19, Marco Stornelli <[email protected]>:

Quoted 12 lines

Il 19/08/2012 04:17, Fengguang Wu ha scritto:

Quoted 11 lines · Namjae Jeon
Quoted 6 lines

unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)

Above function return type is unsigned long, but return value is kept in "u64 bdi_dirty".
It can return incorrect value by type casting.

I don't see how the cast can return wrong value. The u64 is necessary for the intermediate calculations.

Quoted 7 lines
Quoted 3 lines

Thanks,
Fengguang

We are sure u64 is 8byte long, but unsigned long is 4byte long on 32-bit machine, so if bdi_dirty can assume values bigger than 2^32 there is an implicit truncate of its value, isn't it?

Yes, right.
Thanks.

Quoted 3 lines

Marco

#5 lore raw
In reply to Fengguang Wu

2012/8/19, Fengguang Wu <[email protected]>:

Quoted 8 lines · Namjae Jeon
Quoted 6 lines

unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)

Above function return type is unsigned long, but return value is kept in "u64 bdi_dirty".
It can return incorrect value by type casting.

Quoted 5 lines

I don't see how the cast can return wrong value. The u64 is necessary for the intermediate calculations.

Thanks,
Fengguang

Hi Wu.
I understand.
Thanks for your reply.

Quoted 24 lines
Quoted 23 lines
---
 mm/page-writeback.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page-writeback.c +1 -1
index 49133b6..73a7a06 100644
@@ -546,7 +546,7 @@ static unsigned long hard_dirty_limit(unsigned long
 thresh)
  */
 unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long
 dirty)
 {
-	u64 bdi_dirty;
+	unsigned long bdi_dirty;
 	long numerator, denominator;

/*
--
1.7.9.5