Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

binder: fix log spam for existing debugfs file creation.

Since commit 43e23b6c0b01 ("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 <martin.fuzzey@flowbird.group>
Acked-by: Todd Kjos <tkjos@google.com>
Fixes: 43e23b6c0b01 ("debugfs: log errors when something goes wrong")
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/1578671054-5982-1-git-send-email-martin.fuzzey@flowbird.group
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Martin Fuzzey and committed by
Greg Kroah-Hartman
eb143f87 10d3e38c

+19 -18
+19 -18
drivers/android/binder.c
··· 5199 5199 5200 5200 static int binder_open(struct inode *nodp, struct file *filp) 5201 5201 { 5202 - struct binder_proc *proc; 5202 + struct binder_proc *proc, *itr; 5203 5203 struct binder_device *binder_dev; 5204 5204 struct binderfs_info *info; 5205 5205 struct dentry *binder_binderfs_dir_entry_proc = NULL; 5206 + bool existing_pid = false; 5206 5207 5207 5208 binder_debug(BINDER_DEBUG_OPEN_CLOSE, "%s: %d:%d\n", __func__, 5208 5209 current->group_leader->pid, current->pid); ··· 5236 5235 filp->private_data = proc; 5237 5236 5238 5237 mutex_lock(&binder_procs_lock); 5238 + hlist_for_each_entry(itr, &binder_procs, proc_node) { 5239 + if (itr->pid == proc->pid) { 5240 + existing_pid = true; 5241 + break; 5242 + } 5243 + } 5239 5244 hlist_add_head(&proc->proc_node, &binder_procs); 5240 5245 mutex_unlock(&binder_procs_lock); 5241 5246 5242 - if (binder_debugfs_dir_entry_proc) { 5247 + if (binder_debugfs_dir_entry_proc && !existing_pid) { 5243 5248 char strbuf[11]; 5244 5249 5245 5250 snprintf(strbuf, sizeof(strbuf), "%u", proc->pid); 5246 5251 /* 5247 - * proc debug entries are shared between contexts, so 5248 - * this will fail if the process tries to open the driver 5249 - * again with a different context. The priting code will 5250 - * anyway print all contexts that a given PID has, so this 5251 - * is not a problem. 5252 + * proc debug entries are shared between contexts. 5253 + * Only create for the first PID to avoid debugfs log spamming 5254 + * The printing code will anyway print all contexts for a given 5255 + * PID so this is not a problem. 5252 5256 */ 5253 5257 proc->debugfs_entry = debugfs_create_file(strbuf, 0444, 5254 5258 binder_debugfs_dir_entry_proc, ··· 5261 5255 &proc_fops); 5262 5256 } 5263 5257 5264 - if (binder_binderfs_dir_entry_proc) { 5258 + if (binder_binderfs_dir_entry_proc && !existing_pid) { 5265 5259 char strbuf[11]; 5266 5260 struct dentry *binderfs_entry; 5267 5261 5268 5262 snprintf(strbuf, sizeof(strbuf), "%u", proc->pid); 5269 5263 /* 5270 5264 * Similar to debugfs, the process specific log file is shared 5271 - * between contexts. If the file has already been created for a 5272 - * process, the following binderfs_create_file() call will 5273 - * fail with error code EEXIST if another context of the same 5274 - * process invoked binder_open(). This is ok since same as 5275 - * debugfs, the log file will contain information on all 5276 - * contexts of a given PID. 5265 + * between contexts. Only create for the first PID. 5266 + * This is ok since same as debugfs, the log file will contain 5267 + * information on all contexts of a given PID. 5277 5268 */ 5278 5269 binderfs_entry = binderfs_create_file(binder_binderfs_dir_entry_proc, 5279 5270 strbuf, &proc_fops, (void *)(unsigned long)proc->pid); ··· 5280 5277 int error; 5281 5278 5282 5279 error = PTR_ERR(binderfs_entry); 5283 - if (error != -EEXIST) { 5284 - pr_warn("Unable to create file %s in binderfs (error %d)\n", 5285 - strbuf, error); 5286 - } 5280 + pr_warn("Unable to create file %s in binderfs (error %d)\n", 5281 + strbuf, error); 5287 5282 } 5288 5283 } 5289 5284