Fix: atomic_add_unless() returns true/false rather than prior value
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 8 Mar 2017 16:50:38 +0000 (11:50 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 8 Mar 2017 16:55:28 +0000 (11:55 -0500)
The previous implementation assumed that `atomic_add_unless` returned
the prior value of the atomic counter when in fact it returned if the
addition was performed (true) or not performed (false).
Since `atomic_add_unless` can not return INT_MAX, the `lttng_kref_get`
always returned that the call was successful.

This issue had a low likelihood of being triggered since the two refcounts
of the counters used with this call are both bounded by the maximum
number of file descriptors on the system.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
wrapper/kref.h

index eedefbfe87e96ab47ac79ac0c4a36565c03a47ae..f30a9aed515db306a1803ff5e4bcc2612a75801b 100644 (file)
  */
 static inline int lttng_kref_get(struct kref *kref)
 {
-       if (atomic_add_unless(&kref->refcount, 1, INT_MAX) != INT_MAX) {
-               return 1;
-       } else {
-               return 0;
-       }
+       return atomic_add_unless(&kref->refcount, 1, INT_MAX);
 }
 
 #endif /* _LTTNG_WRAPPER_KREF_H */
This page took 0.029549 seconds and 4 git commands to generate.