* [PATCH] nbd: Fix return value check for debugfs_create_*()
@ 2016-02-05 13:48 weiyj_lk
2016-02-12 14:57 ` Markus Pargmann
0 siblings, 1 reply; 2+ messages in thread
From: weiyj_lk @ 2016-02-05 13:48 UTC (permalink / raw)
To: Markus Pargmann, Jens Axboe; +Cc: Wei Yongjun, nbd-general, linux-kernel
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] nbd: Fix return value check for debugfs_create_*()
2016-02-05 13:48 [PATCH] nbd: Fix return value check for debugfs_create_*() weiyj_lk
@ 2016-02-12 14:57 ` Markus Pargmann
0 siblings, 0 replies; 2+ messages in thread
From: Markus Pargmann @ 2016-02-12 14:57 UTC (permalink / raw)
To: weiyj_lk; +Cc: Jens Axboe, Wei Yongjun, nbd-general, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 4162 bytes --]
Hi,
On Friday, February 05, 2016 09:48:21 PM weiyj_lk@163.com wrote:
> 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.
I tried to fix this already but it didn't reach 4.5. It is queued for
4.6. Please have a look at
http://git.pengutronix.de/?p=mpa/linux-nbd.git;a=commitdiff;h=27ea43fe2a32f63bb6f442dafc2133232b8af4a6;hp=92e963f50fc74041b5e9e744c330dca48e04f08d
whether this works for you as well. The difference is that I removed all
error checks for the debugfs files. The code looks nicer but of course
there are no error messages if it went wrong.
Thanks,
Markus
>
> 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;
>
>
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-12 14:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-05 13:48 [PATCH] nbd: Fix return value check for debugfs_create_*() weiyj_lk
2016-02-12 14:57 ` Markus Pargmann
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®