Skip to contentSkip to conversation

Mark res_counter_charge(_locked) with __must_check

PATCH In review Pavel Emelyanov 2 participants 5 messages May 8, 2008 – May 12, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Mark res_counter_charge(_locked) with __must_check

Ignoring theirs return value may result in counter underflow in the future - when the value charged will be uncharged (or in "leaks" - when the value is not uncharged).

This also prevents from using charging routines to decrement the counter value (i.e. uncharge it) ;)

(Current code works OK with res_counter, however :) )

---

include/linux/res_counter.h +4 -2
index 6d9e1fc..125660e 100644
@@ -95,8 +95,10 @@ void res_counter_init(struct res_counter *counter);
  * counter->limit _locked call expects the counter->lock to be taken
  */
 
-int res_counter_charge_locked(struct res_counter *counter, unsigned long val);
-int res_counter_charge(struct res_counter *counter, unsigned long val);
+int __must_check res_counter_charge_locked(struct res_counter *counter,
+		unsigned long val);
+int __must_check res_counter_charge(struct res_counter *counter,
+		unsigned long val);
 
 /*
  * uncharge - tell that some portion of the resource is released
#1 lore raw
Quoted 11 lines · On Thu, 08 May 2008 13:05:44 +0400 Pavel Emelyanov <[email protected]> wrote:

Ignoring theirs return value may result in counter underflow in the future - when the value charged will be uncharged (or in "leaks" - when the value is not uncharged).

This also prevents from using charging routines to decrement the counter value (i.e. uncharge it) ;)

(Current code works OK with res_counter, however :) )

nice check :)

BTW, res_counter_charge_locked() should be extern function ?

Thanks,
-Kame

#2 lore raw
Quoted 7 lines · KAMEZAWA Hiroyuki
Quoted 4 lines · On Thu, 08 May 2008 13:05:44 +0400 Pavel Emelyanov <[email protected]> wrote:

Ignoring theirs return value may result in counter underflow in the future - when the value charged will be uncharged (or in "leaks" - when the value is not uncharged).

Quoted 8 lines
Quoted 7 lines

This also prevents from using charging routines to decrement the counter value (i.e. uncharge it) ;)

(Current code works OK with res_counter, however :) )

nice check :)

Thanks!

Quoted 1 line

BTW, res_counter_charge_locked() should be extern function ?

What do you mean? It is extern as well as the res_counter_charge and uncharge ones are, but functions may have forward declarations w/o extern keyword AFAIK ;)

Quoted 4 lines

Thanks,
-Kame

#3 lore raw
Quoted 6 lines · On Thu, 08 May 2008 13:40:53 +0400 Pavel Emelyanov <[email protected]> wrote:
Quoted 1 line

BTW, res_counter_charge_locked() should be extern function ?

What do you mean? It is extern as well as the res_counter_charge and uncharge ones are, but functions may have forward declarations w/o extern keyword AFAIK ;)

Ah,
Is res_counter_charge_locked() is called from files other than res_counter.c ? Does we need declaration in header file ?

Thanks,
-Kame

#4 lore raw
Quoted 10 lines · KAMEZAWA Hiroyuki
Quoted 5 lines · On Thu, 08 May 2008 13:40:53 +0400 Pavel Emelyanov <[email protected]> wrote:
Quoted 1 line

BTW, res_counter_charge_locked() should be extern function ?

What do you mean? It is extern as well as the res_counter_charge and uncharge ones are, but functions may have forward declarations w/o extern keyword AFAIK ;)

Ah,
Is res_counter_charge_locked() is called from files other than res_counter.c ?

I checked - everything was OK.

Quoted 1 line

Does we need declaration in header file ?

But this patch _is_ for declaration in header :)

Quoted 4 lines

Thanks,
-Kame