From: weiyj_lk@163.com
To: Markus Pargmann <mpa@pengutronix.de>, Jens Axboe <axboe@fb.com>
Cc: Wei Yongjun <yongjun_wei@trendmicro.com.cn>,
nbd-general@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: [PATCH] nbd: Fix return value check for debugfs_create_*()
Date: Fri, 5 Feb 2016 21:48:21 +0800 [thread overview]
Message-ID: <1454680101-17853-1-git-send-email-weiyj_lk@163.com> (raw)
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
In case of error, the function debugfs_create_*() returns NULL
pointer not ERR_PTR() if debugfs is enabled. The IS_ERR() test
in the return value check should be replaced with NULL test.
Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
drivers/block/nbd.c | 50 ++++++++++++++++++++++++--------------------------
1 file changed, 24 insertions(+), 26 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index e4c5cc1..02bc697 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -895,49 +895,47 @@ static int nbd_dev_dbg_init(struct nbd_device *nbd)
struct dentry *f;
dir = debugfs_create_dir(nbd_name(nbd), nbd_dbg_dir);
- if (IS_ERR_OR_NULL(dir)) {
- dev_err(nbd_to_dev(nbd), "Failed to create debugfs dir for '%s' (%ld)\n",
- nbd_name(nbd), PTR_ERR(dir));
- return PTR_ERR(dir);
+ if (!dir) {
+ dev_err(nbd_to_dev(nbd), "Failed to create debugfs dir for '%s'\n",
+ nbd_name(nbd));
+ return -ENOMEM;
}
nbd->dbg_dir = dir;
f = debugfs_create_file("tasks", 0444, dir, nbd, &nbd_dbg_tasks_ops);
- if (IS_ERR_OR_NULL(f)) {
- dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'tasks', %ld\n",
- PTR_ERR(f));
- return PTR_ERR(f);
+ if (!f) {
+ dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'tasks'\n");
+ goto fail;
}
f = debugfs_create_u64("size_bytes", 0444, dir, &nbd->bytesize);
- if (IS_ERR_OR_NULL(f)) {
- dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'size_bytes', %ld\n",
- PTR_ERR(f));
- return PTR_ERR(f);
+ if (!f) {
+ dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'size_bytes'\n");
+ goto fail;
}
f = debugfs_create_u32("timeout", 0444, dir, &nbd->xmit_timeout);
- if (IS_ERR_OR_NULL(f)) {
- dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'timeout', %ld\n",
- PTR_ERR(f));
- return PTR_ERR(f);
+ if (!f) {
+ dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'timeout'\n");
+ goto fail;
}
f = debugfs_create_u32("blocksize", 0444, dir, &nbd->blksize);
- if (IS_ERR_OR_NULL(f)) {
- dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'blocksize', %ld\n",
- PTR_ERR(f));
- return PTR_ERR(f);
+ if (!f) {
+ dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'blocksize'\n");
+ goto fail;
}
f = debugfs_create_file("flags", 0444, dir, &nbd, &nbd_dbg_flags_ops);
- if (IS_ERR_OR_NULL(f)) {
- dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'flags', %ld\n",
- PTR_ERR(f));
- return PTR_ERR(f);
+ if (!f) {
+ dev_err(nbd_to_dev(nbd), "Failed to create debugfs file 'flags'\n");
+ goto fail;
}
return 0;
+fail:
+ debugfs_remove_recursive(nbd->dbg_dir);
+ return -ENOMEM;
}
static void nbd_dev_dbg_close(struct nbd_device *nbd)
@@ -950,8 +948,8 @@ static int nbd_dbg_init(void)
struct dentry *dbg_dir;
dbg_dir = debugfs_create_dir("nbd", NULL);
- if (IS_ERR(dbg_dir))
- return PTR_ERR(dbg_dir);
+ if (!dbg_dir)
+ return -ENOMEM;
nbd_dbg_dir = dbg_dir;
next reply other threads:[~2016-02-05 13:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 13:48 weiyj_lk [this message]
2016-02-12 14:57 ` Markus Pargmann
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=1454680101-17853-1-git-send-email-weiyj_lk@163.com \
--to=weiyj_lk@163.com \
--cc=axboe@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpa@pengutronix.de \
--cc=nbd-general@lists.sourceforge.net \
--cc=yongjun_wei@trendmicro.com.cn \
/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
all inboxes | Powered by JetHome®