lib: Split codetag_lock_module_list()
Subsystems (2)
PATCH 1/1 lib: Split codetag_lock_module_list()
Letting a function argument indicate whether a lock or unlock operation should be performed is incompatible with compile-time analysis of locking operations by sparse and Clang. Hence, split codetag_lock_module_list() into two functions: a function that locks cttype->mod_lock and another function that unlocks cttype->mod_lock. No functionality has been changed. See also commit 916cc5167cc6 ("lib: code tagging framework").
--- include/linux/codetag.h | 3 ++- lib/alloc_tag.c | 8 ++++---- lib/codetag.c | 12 +++++++----- 3 files changed, 13 insertions(+), 10 deletions(-)
include/linux/codetag.h +2 -1
@@ -74,8 +74,9 @@ struct codetag_iterator { .flags = 0, \ } -void codetag_lock_module_list (struct codetag_type *cttype,bool lock); +void codetag_lock_module_list (struct codetag_type *cttype);bool codetag_trylock_module_list (struct codetag_type *cttype); +void codetag_unlock_module_list (struct codetag_type *cttype);struct codetag_iterator codetag_get_ct_iter (struct codetag_type *cttype);struct codetag *codetag_next_ct (struct codetag_iterator *iter);
lib/alloc_tag.c +4 -4
@@ -52,7 +52,7 @@ static void *allocinfo_start(struct seq_file *m, loff_t *pos)loff_t node = *pos; priv = (struct allocinfo_private *)m->private; -codetag_lock_module_list (alloc_tag_cttype, true); +codetag_lock_module_list (alloc_tag_cttype);if (node ==0 ) { priv->print_header = true; priv->iter =codetag_get_ct_iter (alloc_tag_cttype);
@@ -75,7 +75,7 @@ static void *allocinfo_next(struct seq_file *m, void *arg, loff_t *pos)static void allocinfo_stop (struct seq_file *m,void *arg) { -codetag_lock_module_list (alloc_tag_cttype, false); +codetag_unlock_module_list (alloc_tag_cttype); }static void print_allocinfo_header (struct seq_buf *buf)
@@ -134,7 +134,7 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_slreturn 0 ;if (can_sleep) -codetag_lock_module_list (alloc_tag_cttype, true); +codetag_lock_module_list (alloc_tag_cttype);else if (!codetag_trylock_module_list (alloc_tag_cttype))return 0 ;
@@ -159,7 +159,7 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_sl } } -codetag_lock_module_list (alloc_tag_cttype, false); +codetag_unlock_module_list (alloc_tag_cttype);return nr; }
lib/codetag.c +7 -5
@@ -35,12 +35,9 @@ struct codetag_module {static DEFINE_MUTEX (codetag_lock);static LIST_HEAD (codetag_types); -void codetag_lock_module_list (struct codetag_type *cttype,bool lock) +void codetag_lock_module_list (struct codetag_type *cttype) { -if (lock) -down_read (&cttype->mod_lock); -else -up_read (&cttype->mod_lock); +down_read (&cttype->mod_lock); }bool codetag_trylock_module_list (struct codetag_type *cttype)
@@ -48,6 +45,11 @@ bool codetag_trylock_module_list(struct codetag_type *cttype)return down_read_trylock (&cttype->mod_lock) !=0 ; } +void codetag_unlock_module_list (struct codetag_type *cttype) +{ +up_read (&cttype->mod_lock); +} +struct codetag_iterator codetag_get_ct_iter (struct codetag_type *cttype) {struct codetag_iterator iter = {
Andrew Morton
maintainerQuoted 3 lines · On Tue, 24 Mar 2026 14:42:25 -0700 Bart Van Assche <[email protected]> wrote:
Letting a function argument indicate whether a lock or unlock operation should be performed is incompatible with compile-time analysis of locking operations by sparse and Clang.
And it makes Linus mad.
Quoted 5 lines
Hence, split
codetag_lock_module_list()into two functions: a function that lockscttype->mod_lockand another function that unlockscttype->mod_lock. No functionality has been changed. See also commit916cc5167cc6("lib: code tagging framework").
Thanks. I'd prefer to park this for the next cycle. The amount of material I'm sitting on is excessive and I'm trying to give reviews&testers time to catch up.
Quoted 11 lines · Bart Van Assche
Letting a function argument indicate whether a lock or unlock operation should be performed is incompatible with compile-time analysis of locking operations by sparse and Clang. Hence, split
codetag_lock_module_list()into two functions: a function that lockscttype->mod_lockand another function that unlockscttype->mod_lock. No functionality has been changed. See also commit916cc5167cc6("lib: code tagging framework").Cc Suren Baghdasaryan <[email protected]>Signed-off-by Bart Van Assche <[email protected]>
Thanks! Don't remember why I used a parameter instead of a separate function. Might have been a brain fart or some reason in an earlier version of the patch... Anyway, does not matter now.
Quoted 92 lines
--- include/linux/codetag.h | 3 ++- lib/alloc_tag.c | 8 ++++---- lib/codetag.c | 12 +++++++----- 3 files changed, 13 insertions(+), 10 deletions(-)include/linux/codetag.h +2
-1@@ -74,8 +74,9 @@ struct codetag_iterator { .flags = 0, \ } -void codetag_lock_module_list (struct codetag_type *cttype,bool lock); +void codetag_lock_module_list (struct codetag_type *cttype);bool codetag_trylock_module_list (struct codetag_type *cttype); +void codetag_unlock_module_list (struct codetag_type *cttype);struct codetag_iterator codetag_get_ct_iter (struct codetag_type *cttype);struct codetag *codetag_next_ct (struct codetag_iterator *iter);lib/alloc_tag.c +4
-4@@ -52,7 +52,7 @@ static void *allocinfo_start(struct seq_file *m, loff_t *pos)loff_t node = *pos; priv = (struct allocinfo_private *)m->private; -codetag_lock_module_list (alloc_tag_cttype, true); +codetag_lock_module_list (alloc_tag_cttype);if (node ==0 ) { priv->print_header = true; priv->iter =codetag_get_ct_iter (alloc_tag_cttype);@@ -75,7 +75,7 @@ static void *allocinfo_next(struct seq_file *m, void *arg, loff_t *pos)static void allocinfo_stop (struct seq_file *m,void *arg) { -codetag_lock_module_list (alloc_tag_cttype, false); +codetag_unlock_module_list (alloc_tag_cttype); }static void print_allocinfo_header (struct seq_buf *buf)@@ -134,7 +134,7 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_slreturn 0 ;if (can_sleep) -codetag_lock_module_list (alloc_tag_cttype, true); +codetag_lock_module_list (alloc_tag_cttype);else if (!codetag_trylock_module_list (alloc_tag_cttype))return 0 ;@@ -159,7 +159,7 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_sl } } -codetag_lock_module_list (alloc_tag_cttype, false); +codetag_unlock_module_list (alloc_tag_cttype);return nr; }lib/codetag.c +7
-5@@ -35,12 +35,9 @@ struct codetag_module {static DEFINE_MUTEX (codetag_lock);static LIST_HEAD (codetag_types); -void codetag_lock_module_list (struct codetag_type *cttype,bool lock) +void codetag_lock_module_list (struct codetag_type *cttype) { -if (lock) -down_read (&cttype->mod_lock); -else -up_read (&cttype->mod_lock); +down_read (&cttype->mod_lock); }bool codetag_trylock_module_list (struct codetag_type *cttype)@@ -48,6 +45,11 @@ bool codetag_trylock_module_list(struct codetag_type *cttype)return down_read_trylock (&cttype->mod_lock) !=0 ; } +void codetag_unlock_module_list (struct codetag_type *cttype) +{ +up_read (&cttype->mod_lock); +} +struct codetag_iterator codetag_get_ct_iter (struct codetag_type *cttype) {struct codetag_iterator iter = {