binder: fix redefinition of seq_file attributes
authorCarlos Llamas <cmllamas@google.com>
Fri, 1 Jul 2022 18:20:41 +0000 (18:20 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Jul 2022 13:44:19 +0000 (15:44 +0200)
The patchset in [1] exported some definitions to binder_internal.h in
order to make the debugfs entries such as 'stats' and 'transaction_log'
available in a binderfs instance. However, the DEFINE_SHOW_ATTRIBUTE
macro expands into a static function/variable pair, which in turn get
redefined each time a source file includes this internal header.

This problem was made evident after a report from the kernel test robot
<lkp@intel.com> where several W=1 build warnings are seen in downstream
kernels. See the following example:

  include/../drivers/android/binder_internal.h:111:23: warning: 'binder_stats_fops' defined but not used [-Wunused-const-variable=]
     111 | DEFINE_SHOW_ATTRIBUTE(binder_stats);
         |                       ^~~~~~~~~~~~
  include/linux/seq_file.h:174:37: note: in definition of macro 'DEFINE_SHOW_ATTRIBUTE'
     174 | static const struct file_operations __name ## _fops = {                 \
         |                                     ^~~~~~

This patch fixes the above issues by moving back the definitions into
binder.c and instead creates an array of the debugfs entries which is
more convenient to share with binderfs and iterate through.

  [1] https://lore.kernel.org/all/20190903161655.107408-1-hridya@google.com/

Fixes: 0e13e452dafc ("binder: Add stats, state and transactions files")
Fixes: 03e2e07e3814 ("binder: Make transaction_log available in binderfs")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20220701182041.2134313-1-cmllamas@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binder.c
drivers/android/binder_internal.h
drivers/android/binderfs.c

index d4f84f25c30b0d053f911babdee4877d3a838e52..c964d7c8c3841386225d317ca34a8118c7a8a880 100644 (file)
@@ -197,8 +197,32 @@ static inline void binder_stats_created(enum binder_stat_types type)
        atomic_inc(&binder_stats.obj_created[type]);
 }
 
-struct binder_transaction_log binder_transaction_log;
-struct binder_transaction_log binder_transaction_log_failed;
+struct binder_transaction_log_entry {
+       int debug_id;
+       int debug_id_done;
+       int call_type;
+       int from_proc;
+       int from_thread;
+       int target_handle;
+       int to_proc;
+       int to_thread;
+       int to_node;
+       int data_size;
+       int offsets_size;
+       int return_error_line;
+       uint32_t return_error;
+       uint32_t return_error_param;
+       char context_name[BINDERFS_MAX_NAME + 1];
+};
+
+struct binder_transaction_log {
+       atomic_t cur;
+       bool full;
+       struct binder_transaction_log_entry entry[32];
+};
+
+static struct binder_transaction_log binder_transaction_log;
+static struct binder_transaction_log binder_transaction_log_failed;
 
 static struct binder_transaction_log_entry *binder_transaction_log_add(
        struct binder_transaction_log *log)
@@ -6276,8 +6300,7 @@ static void print_binder_proc_stats(struct seq_file *m,
        print_binder_stats(m, "  ", &proc->stats);
 }
 
-
-int binder_state_show(struct seq_file *m, void *unused)
+static int state_show(struct seq_file *m, void *unused)
 {
        struct binder_proc *proc;
        struct binder_node *node;
@@ -6316,7 +6339,7 @@ int binder_state_show(struct seq_file *m, void *unused)
        return 0;
 }
 
-int binder_stats_show(struct seq_file *m, void *unused)
+static int stats_show(struct seq_file *m, void *unused)
 {
        struct binder_proc *proc;
 
@@ -6332,7 +6355,7 @@ int binder_stats_show(struct seq_file *m, void *unused)
        return 0;
 }
 
-int binder_transactions_show(struct seq_file *m, void *unused)
+static int transactions_show(struct seq_file *m, void *unused)
 {
        struct binder_proc *proc;
 
@@ -6388,7 +6411,7 @@ static void print_binder_transaction_log_entry(struct seq_file *m,
                        "\n" : " (incomplete)\n");
 }
 
-int binder_transaction_log_show(struct seq_file *m, void *unused)
+static int transaction_log_show(struct seq_file *m, void *unused)
 {
        struct binder_transaction_log *log = m->private;
        unsigned int log_cur = atomic_read(&log->cur);
@@ -6420,6 +6443,45 @@ const struct file_operations binder_fops = {
        .release = binder_release,
 };
 
+DEFINE_SHOW_ATTRIBUTE(state);
+DEFINE_SHOW_ATTRIBUTE(stats);
+DEFINE_SHOW_ATTRIBUTE(transactions);
+DEFINE_SHOW_ATTRIBUTE(transaction_log);
+
+const struct binder_debugfs_entry binder_debugfs_entries[] = {
+       {
+               .name = "state",
+               .mode = 0444,
+               .fops = &state_fops,
+               .data = NULL,
+       },
+       {
+               .name = "stats",
+               .mode = 0444,
+               .fops = &stats_fops,
+               .data = NULL,
+       },
+       {
+               .name = "transactions",
+               .mode = 0444,
+               .fops = &transactions_fops,
+               .data = NULL,
+       },
+       {
+               .name = "transaction_log",
+               .mode = 0444,
+               .fops = &transaction_log_fops,
+               .data = &binder_transaction_log,
+       },
+       {
+               .name = "failed_transaction_log",
+               .mode = 0444,
+               .fops = &transaction_log_fops,
+               .data = &binder_transaction_log_failed,
+       },
+       {} /* terminator */
+};
+
 static int __init init_binder_device(const char *name)
 {
        int ret;
@@ -6465,36 +6527,18 @@ static int __init binder_init(void)
        atomic_set(&binder_transaction_log_failed.cur, ~0U);
 
        binder_debugfs_dir_entry_root = debugfs_create_dir("binder", NULL);
-       if (binder_debugfs_dir_entry_root)
+       if (binder_debugfs_dir_entry_root) {
+               const struct binder_debugfs_entry *db_entry;
+
+               binder_for_each_debugfs_entry(db_entry)
+                       debugfs_create_file(db_entry->name,
+                                           db_entry->mode,
+                                           binder_debugfs_dir_entry_root,
+                                           db_entry->data,
+                                           db_entry->fops);
+
                binder_debugfs_dir_entry_proc = debugfs_create_dir("proc",
                                                 binder_debugfs_dir_entry_root);
-
-       if (binder_debugfs_dir_entry_root) {
-               debugfs_create_file("state",
-                                   0444,
-                                   binder_debugfs_dir_entry_root,
-                                   NULL,
-                                   &binder_state_fops);
-               debugfs_create_file("stats",
-                                   0444,
-                                   binder_debugfs_dir_entry_root,
-                                   NULL,
-                                   &binder_stats_fops);
-               debugfs_create_file("transactions",
-                                   0444,
-                                   binder_debugfs_dir_entry_root,
-                                   NULL,
-                                   &binder_transactions_fops);
-               debugfs_create_file("transaction_log",
-                                   0444,
-                                   binder_debugfs_dir_entry_root,
-                                   &binder_transaction_log,
-                                   &binder_transaction_log_fops);
-               debugfs_create_file("failed_transaction_log",
-                                   0444,
-                                   binder_debugfs_dir_entry_root,
-                                   &binder_transaction_log_failed,
-                                   &binder_transaction_log_fops);
        }
 
        if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
index 8dc0bccf851395be9e3ac205dd1225a6c89067d3..abe19d88c6ecc636fae4029e688b01b2dcea9bb9 100644 (file)
@@ -107,41 +107,19 @@ static inline int __init init_binderfs(void)
 }
 #endif
 
-int binder_stats_show(struct seq_file *m, void *unused);
-DEFINE_SHOW_ATTRIBUTE(binder_stats);
-
-int binder_state_show(struct seq_file *m, void *unused);
-DEFINE_SHOW_ATTRIBUTE(binder_state);
-
-int binder_transactions_show(struct seq_file *m, void *unused);
-DEFINE_SHOW_ATTRIBUTE(binder_transactions);
-
-int binder_transaction_log_show(struct seq_file *m, void *unused);
-DEFINE_SHOW_ATTRIBUTE(binder_transaction_log);
-
-struct binder_transaction_log_entry {
-       int debug_id;
-       int debug_id_done;
-       int call_type;
-       int from_proc;
-       int from_thread;
-       int target_handle;
-       int to_proc;
-       int to_thread;
-       int to_node;
-       int data_size;
-       int offsets_size;
-       int return_error_line;
-       uint32_t return_error;
-       uint32_t return_error_param;
-       char context_name[BINDERFS_MAX_NAME + 1];
+struct binder_debugfs_entry {
+       const char *name;
+       umode_t mode;
+       const struct file_operations *fops;
+       void *data;
 };
 
-struct binder_transaction_log {
-       atomic_t cur;
-       bool full;
-       struct binder_transaction_log_entry entry[32];
-};
+extern const struct binder_debugfs_entry binder_debugfs_entries[];
+
+#define binder_for_each_debugfs_entry(entry)   \
+       for ((entry) = binder_debugfs_entries;  \
+            (entry)->name;                     \
+            (entry)++)
 
 enum binder_stat_types {
        BINDER_STAT_PROC,
@@ -580,6 +558,4 @@ struct binder_object {
        };
 };
 
-extern struct binder_transaction_log binder_transaction_log;
-extern struct binder_transaction_log binder_transaction_log_failed;
 #endif /* _LINUX_BINDER_INTERNAL_H */
index 6c5e94f6cb3a41301ac6c2101916e84597333b8f..588d753a7a19975a447a33c6f6d128cf54269319 100644 (file)
@@ -629,6 +629,7 @@ static int init_binder_features(struct super_block *sb)
 static int init_binder_logs(struct super_block *sb)
 {
        struct dentry *binder_logs_root_dir, *dentry, *proc_log_dir;
+       const struct binder_debugfs_entry *db_entry;
        struct binderfs_info *info;
        int ret = 0;
 
@@ -639,43 +640,15 @@ static int init_binder_logs(struct super_block *sb)
                goto out;
        }
 
-       dentry = binderfs_create_file(binder_logs_root_dir, "stats",
-                                     &binder_stats_fops, NULL);
-       if (IS_ERR(dentry)) {
-               ret = PTR_ERR(dentry);
-               goto out;
-       }
-
-       dentry = binderfs_create_file(binder_logs_root_dir, "state",
-                                     &binder_state_fops, NULL);
-       if (IS_ERR(dentry)) {
-               ret = PTR_ERR(dentry);
-               goto out;
-       }
-
-       dentry = binderfs_create_file(binder_logs_root_dir, "transactions",
-                                     &binder_transactions_fops, NULL);
-       if (IS_ERR(dentry)) {
-               ret = PTR_ERR(dentry);
-               goto out;
-       }
-
-       dentry = binderfs_create_file(binder_logs_root_dir,
-                                     "transaction_log",
-                                     &binder_transaction_log_fops,
-                                     &binder_transaction_log);
-       if (IS_ERR(dentry)) {
-               ret = PTR_ERR(dentry);
-               goto out;
-       }
-
-       dentry = binderfs_create_file(binder_logs_root_dir,
-                                     "failed_transaction_log",
-                                     &binder_transaction_log_fops,
-                                     &binder_transaction_log_failed);
-       if (IS_ERR(dentry)) {
-               ret = PTR_ERR(dentry);
-               goto out;
+       binder_for_each_debugfs_entry(db_entry) {
+               dentry = binderfs_create_file(binder_logs_root_dir,
+                                             db_entry->name,
+                                             db_entry->fops,
+                                             db_entry->data);
+               if (IS_ERR(dentry)) {
+                       ret = PTR_ERR(dentry);
+                       goto out;
+               }
        }
 
        proc_log_dir = binderfs_create_dir(binder_logs_root_dir, "proc");