Coding style when using atomic_dec_and_test

Camila Alvarez Inostroza cam.alvarez.i at gmail.com
Sat Mar 30 20:52:29 EDT 2024


I understand that atomic_dec_and_test returns 1 when the result of the
operation is 0, and 0 otherwise.
I've seen two ways of handling the resulting operation, below are a couple
of examples:
(1) if (!atomic_dec_and_test(&rd->refcount))
           return;
      call_rcu(&rd->rcu, free_rootdomain);

(2)  if (atomic64_dec_and_test(&map->refcnt)) {
           /* bpf_map_free_id() must be called first */
           ...
        }

Is it prefered to use one option over the other? Or is it just personal
preference?

Thanks in advance!
Camila Alvarez



More information about the Kernelnewbies mailing list