virtio: console: fix error handling for debugfs_create_dir()
Subsystems (4)
PATCH 1/1 virtio: console: fix error handling for debugfs_create_dir()
debugfs_create_dir() returns ERR_PTR(-ENODEV) if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.
drivers/char/virtio_console.c +1 -1
@@ -2215,7 +2215,7 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { +if (IS_ERR_OR_NULL (pdrvdata.debugfs_dir)) {pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" ,PTR_ERR (pdrvdata.debugfs_dir)); }
Quoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>
Today seems to be the 'fix virtio-console day'.
Thanks,
Amit
Arnd Bergmann
maintainerQuoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>
This looks wrong. debugfs_create_dir intentionally returns non-NULL so failing to create the directory does not trigger an error condition if debugfs is disabled.
Arnd
Quoted 13 lines
drivers/char/virtio_console.c +1
-1@@ -2215,7 +2215,7 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { +if (IS_ERR_OR_NULL (pdrvdata.debugfs_dir)) {pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" ,PTR_ERR (pdrvdata.debugfs_dir)); }
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>This looks wrong.
debugfs_create_dirintentionally returns non-NULL so failing to create the directory does not trigger an error condition if debugfs is disabled.
Yeah. You're right. But the original code is still wrong and will oops if debugfs is disabled. We should set the pointer to NULL if we get a ERR_PTR().
I will send a v2 patch.
regards,
dan carpenter
Arnd Bergmann
maintainerQuoted 13 lines · Dan Carpenter
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>This looks wrong.
debugfs_create_dirintentionally returns non-NULL so failing to create the directory does not trigger an error condition if debugfs is disabled.
Quoted 5 lines
Yeah. You're right. But the original code is still wrong and will oops if debugfs is disabled. We should set the pointer to NULL if we get a
ERR_PTR().I will send a v2 patch.
I don't see where that oops would happen. In the code I'm looking at, all uses of ->debugfs_dir only ever get passed into other debugfs functions that are stubbed out to empty inline functions.
It's not the most obvious interface design, but this all seems intentional and correct to me.
Arnd
PATCH v2 1/1 virtio: console: cleanup an error message
In reply to Arnd BergmannThe PTR_ERR(NULL) here is not useful.
---
v2: completely different
drivers/char/virtio_console.c +2 -4
@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );INIT_LIST_HEAD (&pdrvdata.consoles);INIT_LIST_HEAD (&pdrvdata.portdevs);
Greg Kroah-Hartman
maintainerRe: [patch v2] virtio: console: cleanup an error message
drivers/char/virtio_console.c
Quoted 10 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely differentdrivers/char/virtio_console.c +0
-0
Rusty handles virtio stuff, please cc: him on these.
thanks,
greg k-h
Re: [patch v2] virtio: console: cleanup an error message
In reply to Dan CarpenterQuoted 11 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely differentdrivers/char/virtio_console.c +0
-0
drivers/char/virtio_console.c static int __init init(void) · line 2219
Quoted 9 lines
drivers/char/virtio_console.c +2
-4@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );
When debugfs is enabled and creating the dir fails, we'll print this warning message.
When debugfs is disabled, we'll get an error return, and not print any message.
Seems OK to me.
Rusty, please pick this up.
Amit
Greg Kroah-Hartman
maintainerRe: [patch v2] virtio: console: cleanup an error message
Quoted 25 lines · Amit Shah
Quoted 11 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely differentdrivers/char/virtio_console.c +0
-0drivers/char/virtio_console.c static int __init init(void) · line 2219
Quoted 9 lines
drivers/char/virtio_console.c +2
-4@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );When debugfs is enabled and creating the dir fails, we'll print this warning message.
Quoted 2 lines
When debugfs is disabled, we'll get an error return, and not print any message.
Not true, you will still print the message if debugfs is disabled, as .debugfs_dir will not be NULL.
Why even print anything at all? It's debugfs, you shouldn't really care that much about it :)
thanks,
greg k-h
Greg Kroah-Hartman
maintainerRe: [patch v2] virtio: console: cleanup an error message
In reply to Dan CarpenterQuoted 25 lines · Amit Shah
Quoted 11 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely differentdrivers/char/virtio_console.c +0
-0drivers/char/virtio_console.c static int __init init(void) · line 2219
Quoted 9 lines
drivers/char/virtio_console.c +2
-4@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );When debugfs is enabled and creating the dir fails, we'll print this warning message.
Quoted 2 lines
When debugfs is disabled, we'll get an error return, and not print any message.
Not true, you will still print the message if debugfs is disabled, as .debugfs_dir will not be NULL.
Why even print anything at all? It's debugfs, you shouldn't really care that much about it :)
thanks,
greg k-h
Re: [patch v2] virtio: console: cleanup an error message
Quoted 26 lines · Greg Kroah-Hartman
Quoted 25 lines · Amit Shah
Quoted 11 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely differentdrivers/char/virtio_console.c +0
-0drivers/char/virtio_console.c static int __init init(void) · line 2219
Quoted 9 lines
drivers/char/virtio_console.c +2
-4@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );When debugfs is enabled and creating the dir fails, we'll print this warning message.
Quoted 9 lines
Quoted 2 lines
When debugfs is disabled, we'll get an error return, and not print any message.
Not true, you will still print the message if debugfs is disabled, as .debugfs_dir will not be NULL.
Why even print anything at all? It's debugfs, you shouldn't really care that much about it :)
Yes yes. That's what this code does. It only checks for NULL. The debugfs was a little confusing at first but I get it now.
regards,
dan carpenter
Greg Kroah-Hartman
maintainerRe: [patch v2] virtio: console: cleanup an error message
Quoted 33 lines · Dan Carpenter
Quoted 32 lines · Greg Kroah-Hartman
Quoted 25 lines · Amit Shah
Quoted 11 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely differentdrivers/char/virtio_console.c +0
-0drivers/char/virtio_console.c static int __init init(void) · line 2219
Quoted 9 lines
drivers/char/virtio_console.c +2
-4@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );When debugfs is enabled and creating the dir fails, we'll print this warning message.
Quoted 2 lines
When debugfs is disabled, we'll get an error return, and not print any message.
Not true, you will still print the message if debugfs is disabled, as .debugfs_dir will not be NULL.
Quoted 6 lines
Quoted 3 lines
Why even print anything at all? It's debugfs, you shouldn't really care that much about it :)
Yes yes. That's what this code does. It only checks for NULL. The debugfs was a little confusing at first but I get it now.
Ugh, you are right, that's what I get for writing email before my morning coffee...
Greg Kroah-Hartman
maintainerRe: [patch v2] virtio: console: cleanup an error message
In reply to Dan CarpenterQuoted 33 lines · Dan Carpenter
Quoted 32 lines · Greg Kroah-Hartman
Quoted 25 lines · Amit Shah
Quoted 11 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely differentdrivers/char/virtio_console.c +0
-0drivers/char/virtio_console.c static int __init init(void) · line 2219
Quoted 9 lines
drivers/char/virtio_console.c +2
-4@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );When debugfs is enabled and creating the dir fails, we'll print this warning message.
Quoted 2 lines
When debugfs is disabled, we'll get an error return, and not print any message.
Not true, you will still print the message if debugfs is disabled, as .debugfs_dir will not be NULL.
Quoted 6 lines
Quoted 3 lines
Why even print anything at all? It's debugfs, you shouldn't really care that much about it :)
Yes yes. That's what this code does. It only checks for NULL. The debugfs was a little confusing at first but I get it now.
Ugh, you are right, that's what I get for writing email before my morning coffee...
Rusty Russell
AppliedRe: [patch v2] virtio: console: cleanup an error message
In reply to Dan CarpenterQuoted 5 lines · Dan Carpenter
The
PTR_ERR(NULL)here is not useful.Signed-off-by Dan Carpenter <[email protected]>---
v2: completely different
Applied.
Thanks,
Rusty.
Quoted 21 lines
drivers/char/virtio_console.c +2
-4@@ -2215,10 +2215,8 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { -pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" , -PTR_ERR (pdrvdata.debugfs_dir)); - } +if (!pdrvdata.debugfs_dir) +pr_warning ("Error creating debugfs dir for virtio-ports\n" );INIT_LIST_HEAD (&pdrvdata.consoles);INIT_LIST_HEAD (&pdrvdata.portdevs);_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Arnd Bergmann
maintainerQuoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>
This looks wrong. debugfs_create_dir intentionally returns non-NULL so failing to create the directory does not trigger an error condition if debugfs is disabled.
Arnd
Quoted 13 lines
drivers/char/virtio_console.c +1
-1@@ -2215,7 +2215,7 @@ static int __init init(void) } pdrvdata.debugfs_dir =debugfs_create_dir ("virtio-ports" ,NULL ); -if (!pdrvdata.debugfs_dir) { +if (IS_ERR_OR_NULL (pdrvdata.debugfs_dir)) {pr_warning ("Error %ld creating debugfs dir for virtio-ports\n" ,PTR_ERR (pdrvdata.debugfs_dir)); }
Arnd Bergmann
maintainerQuoted 13 lines · Dan Carpenter
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>This looks wrong.
debugfs_create_dirintentionally returns non-NULL so failing to create the directory does not trigger an error condition if debugfs is disabled.
Quoted 5 lines
Yeah. You're right. But the original code is still wrong and will oops if debugfs is disabled. We should set the pointer to NULL if we get a
ERR_PTR().I will send a v2 patch.
I don't see where that oops would happen. In the code I'm looking at, all uses of ->debugfs_dir only ever get passed into other debugfs functions that are stubbed out to empty inline functions.
It's not the most obvious interface design, but this all seems intentional and correct to me.
Arnd
Greg Kroah-Hartman
maintainerQuoted 18 lines · Arnd Bergmann
Quoted 17 lines · Dan Carpenter
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>This looks wrong.
debugfs_create_dirintentionally returns non-NULL so failing to create the directory does not trigger an error condition if debugfs is disabled.Yeah. You're right. But the original code is still wrong and will oops if debugfs is disabled. We should set the pointer to NULL if we get a
ERR_PTR().
Quoted 8 lines
Quoted 1 line
I will send a v2 patch.
I don't see where that oops would happen. In the code I'm looking at, all uses of ->debugfs_dir only ever get passed into other debugfs functions that are stubbed out to empty inline functions.
It's not the most obvious interface design, but this all seems intentional and correct to me.
It was the best interface design I could create, making it very easy for drivers to use and not really worry at all if debugfs was failing or not, or if it was even present in the system or not. That was the design goal I had for it when I wrote it.
thanks,
greg k-h
Quoted 6 lines
I don't see where that oops would happen. In the code I'm looking at, all uses of ->debugfs_dir only ever get passed into other debugfs functions that are stubbed out to empty inline functions.
It's not the most obvious interface design, but this all seems intentional and correct to me.
Ah. Ok. You're right.
regards,
dan carpenter
Greg Kroah-Hartman
maintainerQuoted 18 lines · Arnd Bergmann
Quoted 17 lines · Dan Carpenter
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Dan Carpenter
debugfs_create_dir()returnsERR_PTR(-ENODEV)if debugfs is disabled. Also my static checker doesn't like it when we print the error code, but it's always just NULL.Signed-off-by Dan Carpenter <[email protected]>This looks wrong.
debugfs_create_dirintentionally returns non-NULL so failing to create the directory does not trigger an error condition if debugfs is disabled.Yeah. You're right. But the original code is still wrong and will oops if debugfs is disabled. We should set the pointer to NULL if we get a
ERR_PTR().
Quoted 8 lines
Quoted 1 line
I will send a v2 patch.
I don't see where that oops would happen. In the code I'm looking at, all uses of ->debugfs_dir only ever get passed into other debugfs functions that are stubbed out to empty inline functions.
It's not the most obvious interface design, but this all seems intentional and correct to me.
It was the best interface design I could create, making it very easy for drivers to use and not really worry at all if debugfs was failing or not, or if it was even present in the system or not. That was the design goal I had for it when I wrote it.
thanks,
greg k-h