* [PATCH 01/21] mtip32xx: Remove redundant null pointer checks in mtip_hw_debugfs_init()
@ 2024-09-03 14:43 Li Zetao
2024-09-03 14:47 ` Jens Axboe
0 siblings, 1 reply; 4+ messages in thread
From: Li Zetao @ 2024-09-03 14:43 UTC (permalink / raw)
To: axboe, hare, dlemoal, john.g.garry, martin.petersen; +Cc: lizetao1, linux-block
Since the debugfs_create_dir() never returns a null pointer, checking
the return value for a null pointer is redundant, and using IS_ERR is
safe enough.
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
drivers/block/mtip32xx/mtip32xx.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index c6ef0546ffc9..56f3bb30165e 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -2275,7 +2275,7 @@ static int mtip_hw_debugfs_init(struct driver_data *dd)
return -1;
dd->dfs_node = debugfs_create_dir(dd->disk->disk_name, dfs_parent);
- if (IS_ERR_OR_NULL(dd->dfs_node)) {
+ if (IS_ERR(dd->dfs_node)) {
dev_warn(&dd->pdev->dev,
"Error creating node %s under debugfs\n",
dd->disk->disk_name);
@@ -4043,7 +4043,7 @@ static int __init mtip_init(void)
mtip_major = error;
dfs_parent = debugfs_create_dir("rssd", NULL);
- if (IS_ERR_OR_NULL(dfs_parent)) {
+ if (IS_ERR(dfs_parent)) {
pr_warn("Error creating debugfs parent\n");
dfs_parent = NULL;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 01/21] mtip32xx: Remove redundant null pointer checks in mtip_hw_debugfs_init()
2024-09-03 14:43 [PATCH 01/21] mtip32xx: Remove redundant null pointer checks in mtip_hw_debugfs_init() Li Zetao
@ 2024-09-03 14:47 ` Jens Axboe
2024-09-04 1:18 ` Li Zetao
0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2024-09-03 14:47 UTC (permalink / raw)
To: Li Zetao, hare, dlemoal, john.g.garry, martin.petersen; +Cc: linux-block
On 9/3/24 8:43 AM, Li Zetao wrote:
> Since the debugfs_create_dir() never returns a null pointer, checking
> the return value for a null pointer is redundant, and using IS_ERR is
> safe enough.
Sigh, why are we seeing so many odd variants of this recently. If you'd
do a bit of searching upfront, you'd find that these should not be
checked at all rather than changing it from err+null to just an error
pointer check.
So no to this one, please do at least a tiny bit of research first
before blindly making a change based on what some static analyzer told
you.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 01/21] mtip32xx: Remove redundant null pointer checks in mtip_hw_debugfs_init()
2024-09-03 14:47 ` Jens Axboe
@ 2024-09-04 1:18 ` Li Zetao
2024-09-04 18:23 ` Jens Axboe
0 siblings, 1 reply; 4+ messages in thread
From: Li Zetao @ 2024-09-04 1:18 UTC (permalink / raw)
To: Jens Axboe, hare, dlemoal, john.g.garry, martin.petersen; +Cc: linux-block
Hi,
在 2024/9/3 22:47, Jens Axboe 写道:
> On 9/3/24 8:43 AM, Li Zetao wrote:
>> Since the debugfs_create_dir() never returns a null pointer, checking
>> the return value for a null pointer is redundant, and using IS_ERR is
>> safe enough.
>
> Sigh, why are we seeing so many odd variants of this recently. If you'd
> do a bit of searching upfront, you'd find that these should not be
> checked at all rather than changing it from err+null to just an error
> pointer check.
>
> So no to this one, please do at least a tiny bit of research first
> before blindly making a change based on what some static analyzer told
> you.
>
I have researched in the community before making the modification.
debugfs_create_file can handle illegal dentry, but my understanding is
that verifying debugfs_create_dir when it fails can avoid invalid calls
to debugfs_create_file.
Greg suggested that I remove this check, maybe I can modify it in v2?
Thanks,
Li Zetao.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 01/21] mtip32xx: Remove redundant null pointer checks in mtip_hw_debugfs_init()
2024-09-04 1:18 ` Li Zetao
@ 2024-09-04 18:23 ` Jens Axboe
0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2024-09-04 18:23 UTC (permalink / raw)
To: Li Zetao, hare, dlemoal, john.g.garry, martin.petersen; +Cc: linux-block
On 9/3/24 7:18 PM, Li Zetao wrote:
> Hi,
>
> ? 2024/9/3 22:47, Jens Axboe ??:
>> On 9/3/24 8:43 AM, Li Zetao wrote:
>>> Since the debugfs_create_dir() never returns a null pointer, checking
>>> the return value for a null pointer is redundant, and using IS_ERR is
>>> safe enough.
>>
>> Sigh, why are we seeing so many odd variants of this recently. If you'd
>> do a bit of searching upfront, you'd find that these should not be
>> checked at all rather than changing it from err+null to just an error
>> pointer check.
>>
>> So no to this one, please do at least a tiny bit of research first
>> before blindly making a change based on what some static analyzer told
>> you.
>>
> I have researched in the community before making the modification.
> debugfs_create_file can handle illegal dentry, but my understanding is
> that verifying debugfs_create_dir when it fails can avoid invalid
> calls to debugfs_create_file.
>
> Greg suggested that I remove this check, maybe I can modify it in v2?
debugfs should tolerate error pointers, hence all the error checking
should just go away rather than being modified. Something ala the below,
totally untested.
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index c6ef0546ffc9..11901f2812ad 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -2269,25 +2269,12 @@ static const struct file_operations mtip_flags_fops = {
.llseek = no_llseek,
};
-static int mtip_hw_debugfs_init(struct driver_data *dd)
+static void mtip_hw_debugfs_init(struct driver_data *dd)
{
- if (!dfs_parent)
- return -1;
-
dd->dfs_node = debugfs_create_dir(dd->disk->disk_name, dfs_parent);
- if (IS_ERR_OR_NULL(dd->dfs_node)) {
- dev_warn(&dd->pdev->dev,
- "Error creating node %s under debugfs\n",
- dd->disk->disk_name);
- dd->dfs_node = NULL;
- return -1;
- }
-
debugfs_create_file("flags", 0444, dd->dfs_node, dd, &mtip_flags_fops);
debugfs_create_file("registers", 0444, dd->dfs_node, dd,
&mtip_regs_fops);
-
- return 0;
}
static void mtip_hw_debugfs_exit(struct driver_data *dd)
@@ -4043,10 +4030,6 @@ static int __init mtip_init(void)
mtip_major = error;
dfs_parent = debugfs_create_dir("rssd", NULL);
- if (IS_ERR_OR_NULL(dfs_parent)) {
- pr_warn("Error creating debugfs parent\n");
- dfs_parent = NULL;
- }
/* Register our PCI operations. */
error = pci_register_driver(&mtip_pci_driver);
--
Jens Axboe
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-04 18:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03 14:43 [PATCH 01/21] mtip32xx: Remove redundant null pointer checks in mtip_hw_debugfs_init() Li Zetao
2024-09-03 14:47 ` Jens Axboe
2024-09-04 1:18 ` Li Zetao
2024-09-04 18:23 ` Jens Axboe
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).