From: Chengyu Song <csong84@gatech.edu>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 1/1] dlm: incorrect check for debugfs returns
Date: Mon, 23 Mar 2015 21:43:38 -0400 [thread overview]
Message-ID: <1427161418-19200-1-git-send-email-csong84@gatech.edu> (raw)
debugfs_create_dir and debugfs_create_file may return -ENODEV when debugfs
is not configured, so the return value should be checked against ERROR_VALUE
as well, otherwise the later dereference of the dentry pointer would crash
the kernel.
Signed-off-by: Chengyu Song <csong84@gatech.edu>
---
fs/dlm/debug_fs.c | 70 +++++++++++++++++++++++++++++++------------------------
1 file changed, 39 insertions(+), 31 deletions(-)
diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index eea6491..65666c8 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -709,78 +709,86 @@ void dlm_delete_debug_file(struct dlm_ls *ls)
int dlm_create_debug_file(struct dlm_ls *ls)
{
char name[DLM_LOCKSPACE_LEN+8];
+ struct dentry *dent;
/* format 1 */
- ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name,
- S_IFREG | S_IRUGO,
- dlm_root,
- ls,
- &format1_fops);
- if (!ls->ls_debug_rsb_dentry)
+ dent = debugfs_create_file(ls->ls_name,
+ S_IFREG | S_IRUGO,
+ dlm_root,
+ ls,
+ &format1_fops);
+ if (IS_ERR_OR_NULL(dent))
goto fail;
+ ls->ls_debug_rsb_dentry = dent;
/* format 2 */
memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name);
- ls->ls_debug_locks_dentry = debugfs_create_file(name,
- S_IFREG | S_IRUGO,
- dlm_root,
- ls,
- &format2_fops);
- if (!ls->ls_debug_locks_dentry)
+ dent = debugfs_create_file(name,
+ S_IFREG | S_IRUGO,
+ dlm_root,
+ ls,
+ &format2_fops);
+ if (IS_ERR_OR_NULL(dent))
goto fail;
+ ls->ls_debug_locks_dentry = dent;
/* format 3 */
memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name);
- ls->ls_debug_all_dentry = debugfs_create_file(name,
- S_IFREG | S_IRUGO,
- dlm_root,
- ls,
- &format3_fops);
- if (!ls->ls_debug_all_dentry)
+ dent = debugfs_create_file(name,
+ S_IFREG | S_IRUGO,
+ dlm_root,
+ ls,
+ &format3_fops);
+ if (IS_ERR_OR_NULL(dent))
goto fail;
+ ls->ls_debug_all_dentry = dent;
/* format 4 */
memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_toss", ls->ls_name);
- ls->ls_debug_toss_dentry = debugfs_create_file(name,
- S_IFREG | S_IRUGO,
- dlm_root,
- ls,
- &format4_fops);
- if (!ls->ls_debug_toss_dentry)
+ dent = debugfs_create_file(name,
+ S_IFREG | S_IRUGO,
+ dlm_root,
+ ls,
+ &format4_fops);
+ if (IS_ERR_OR_NULL(dent))
goto fail;
+ ls->ls_debug_toss_dentry = dent;
memset(name, 0, sizeof(name));
snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name);
- ls->ls_debug_waiters_dentry = debugfs_create_file(name,
- S_IFREG | S_IRUGO,
- dlm_root,
- ls,
- &waiters_fops);
- if (!ls->ls_debug_waiters_dentry)
+ dent = debugfs_create_file(name,
+ S_IFREG | S_IRUGO,
+ dlm_root,
+ ls,
+ &waiters_fops);
+ if (IS_ERR_OR_NULL(dent))
goto fail;
+ ls->ls_debug_waiters_dentry = dent;
return 0;
fail:
dlm_delete_debug_file(ls);
- return -ENOMEM;
+ return dent ? PTR_ERR(dent) : -ENOMEM;
}
int __init dlm_register_debugfs(void)
{
mutex_init(&debug_buf_lock);
dlm_root = debugfs_create_dir("dlm", NULL);
+ if (IS_ERR(dlm_root))
+ return PTR_ERR(dlm_root);
return dlm_root ? 0 : -ENOMEM;
}
--
2.1.0
reply other threads:[~2015-03-24 1:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1427161418-19200-1-git-send-email-csong84@gatech.edu \
--to=csong84@gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).