Skip to content

Commit eb143f8

Browse files
Martin Fuzzeygregkh
authored andcommitted
binder: fix log spam for existing debugfs file creation.
Since commit 43e23b6 ("debugfs: log errors when something goes wrong") debugfs logs attempts to create existing files. However binder attempts to create multiple debugfs files with the same name when a single PID has multiple contexts, this leads to log spamming during an Android boot (17 such messages during boot on my system). Fix this by checking if we already know the PID and only create the debugfs entry for the first context per PID. Do the same thing for binderfs for symmetry. Signed-off-by: Martin Fuzzey <[email protected]> Acked-by: Todd Kjos <[email protected]> Fixes: 43e23b6 ("debugfs: log errors when something goes wrong") Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 10d3e38 commit eb143f8

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

drivers/android/binder.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5199,10 +5199,11 @@ static int binder_mmap(struct file *filp, struct vm_area_struct *vma)
51995199

52005200
static int binder_open(struct inode *nodp, struct file *filp)
52015201
{
5202-
struct binder_proc *proc;
5202+
struct binder_proc *proc, *itr;
52035203
struct binder_device *binder_dev;
52045204
struct binderfs_info *info;
52055205
struct dentry *binder_binderfs_dir_entry_proc = NULL;
5206+
bool existing_pid = false;
52065207

52075208
binder_debug(BINDER_DEBUG_OPEN_CLOSE, "%s: %d:%d\n", __func__,
52085209
current->group_leader->pid, current->pid);
@@ -5235,39 +5236,41 @@ static int binder_open(struct inode *nodp, struct file *filp)
52355236
filp->private_data = proc;
52365237

52375238
mutex_lock(&binder_procs_lock);
5239+
hlist_for_each_entry(itr, &binder_procs, proc_node) {
5240+
if (itr->pid == proc->pid) {
5241+
existing_pid = true;
5242+
break;
5243+
}
5244+
}
52385245
hlist_add_head(&proc->proc_node, &binder_procs);
52395246
mutex_unlock(&binder_procs_lock);
52405247

5241-
if (binder_debugfs_dir_entry_proc) {
5248+
if (binder_debugfs_dir_entry_proc && !existing_pid) {
52425249
char strbuf[11];
52435250

52445251
snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
52455252
/*
5246-
* proc debug entries are shared between contexts, so
5247-
* this will fail if the process tries to open the driver
5248-
* again with a different context. The priting code will
5249-
* anyway print all contexts that a given PID has, so this
5250-
* is not a problem.
5253+
* proc debug entries are shared between contexts.
5254+
* Only create for the first PID to avoid debugfs log spamming
5255+
* The printing code will anyway print all contexts for a given
5256+
* PID so this is not a problem.
52515257
*/
52525258
proc->debugfs_entry = debugfs_create_file(strbuf, 0444,
52535259
binder_debugfs_dir_entry_proc,
52545260
(void *)(unsigned long)proc->pid,
52555261
&proc_fops);
52565262
}
52575263

5258-
if (binder_binderfs_dir_entry_proc) {
5264+
if (binder_binderfs_dir_entry_proc && !existing_pid) {
52595265
char strbuf[11];
52605266
struct dentry *binderfs_entry;
52615267

52625268
snprintf(strbuf, sizeof(strbuf), "%u", proc->pid);
52635269
/*
52645270
* Similar to debugfs, the process specific log file is shared
5265-
* between contexts. If the file has already been created for a
5266-
* process, the following binderfs_create_file() call will
5267-
* fail with error code EEXIST if another context of the same
5268-
* process invoked binder_open(). This is ok since same as
5269-
* debugfs, the log file will contain information on all
5270-
* contexts of a given PID.
5271+
* between contexts. Only create for the first PID.
5272+
* This is ok since same as debugfs, the log file will contain
5273+
* information on all contexts of a given PID.
52715274
*/
52725275
binderfs_entry = binderfs_create_file(binder_binderfs_dir_entry_proc,
52735276
strbuf, &proc_fops, (void *)(unsigned long)proc->pid);
@@ -5277,10 +5280,8 @@ static int binder_open(struct inode *nodp, struct file *filp)
52775280
int error;
52785281

52795282
error = PTR_ERR(binderfs_entry);
5280-
if (error != -EEXIST) {
5281-
pr_warn("Unable to create file %s in binderfs (error %d)\n",
5282-
strbuf, error);
5283-
}
5283+
pr_warn("Unable to create file %s in binderfs (error %d)\n",
5284+
strbuf, error);
52845285
}
52855286
}
52865287

0 commit comments

Comments
 (0)