* [PATCH] phy: realtek: usb: Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
@ 2023-08-31 14:05 Jinjie Ruan
2023-08-31 14:39 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Jinjie Ruan @ 2023-08-31 14:05 UTC (permalink / raw)
To: linux-phy, Vinod Koul, Kishon Vijay Abraham I, Stanley Chang,
Greg Kroah-Hartman
Cc: ruanjinjie
Since both debugfs_create_dir() and debugfs_create_file() return
ERR_PTR and never return NULL, So use IS_ERR() to check it
instead of checking NULL.
Fixes: 134e6d25f6bd ("phy: realtek: usb: Add driver for the Realtek SoC USB 2.0 PHY")
Fixes: adda6e82a7de ("phy: realtek: usb: Add driver for the Realtek SoC USB 3.0 PHY")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
drivers/phy/realtek/phy-rtk-usb2.c | 6 +++---
drivers/phy/realtek/phy-rtk-usb3.c | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/phy/realtek/phy-rtk-usb2.c b/drivers/phy/realtek/phy-rtk-usb2.c
index 5e7ee060b404..67ca78762c80 100644
--- a/drivers/phy/realtek/phy-rtk-usb2.c
+++ b/drivers/phy/realtek/phy-rtk-usb2.c
@@ -853,11 +853,11 @@ static inline void create_debug_files(struct rtk_phy *rtk_phy)
rtk_phy->debug_dir = debugfs_create_dir(dev_name(rtk_phy->dev),
phy_debug_root);
- if (!rtk_phy->debug_dir)
+ if (IS_ERR(rtk_phy->debug_dir))
return;
- if (!debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy,
- &rtk_usb2_parameter_fops))
+ if (IS_ERR(debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy,
+ &rtk_usb2_parameter_fops)))
goto file_error;
return;
diff --git a/drivers/phy/realtek/phy-rtk-usb3.c b/drivers/phy/realtek/phy-rtk-usb3.c
index 7881f908aade..488c749c4edc 100644
--- a/drivers/phy/realtek/phy-rtk-usb3.c
+++ b/drivers/phy/realtek/phy-rtk-usb3.c
@@ -416,11 +416,11 @@ static inline void create_debug_files(struct rtk_phy *rtk_phy)
return;
rtk_phy->debug_dir = debugfs_create_dir(dev_name(rtk_phy->dev), phy_debug_root);
- if (!rtk_phy->debug_dir)
+ if (IS_ERR(rtk_phy->debug_dir))
return;
- if (!debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy,
- &rtk_usb3_parameter_fops))
+ if (IS_ERR(debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy,
+ &rtk_usb3_parameter_fops)))
goto file_error;
return;
--
2.34.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] phy: realtek: usb: Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
2023-08-31 14:05 [PATCH] phy: realtek: usb: Fix the NULL vs IS_ERR() bug for debugfs_create_dir() Jinjie Ruan
@ 2023-08-31 14:39 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2023-08-31 14:39 UTC (permalink / raw)
To: Jinjie Ruan; +Cc: linux-phy, Vinod Koul, Kishon Vijay Abraham I, Stanley Chang
On Thu, Aug 31, 2023 at 10:05:59PM +0800, Jinjie Ruan wrote:
> Since both debugfs_create_dir() and debugfs_create_file() return
> ERR_PTR and never return NULL, So use IS_ERR() to check it
> instead of checking NULL.
>
> Fixes: 134e6d25f6bd ("phy: realtek: usb: Add driver for the Realtek SoC USB 2.0 PHY")
> Fixes: adda6e82a7de ("phy: realtek: usb: Add driver for the Realtek SoC USB 3.0 PHY")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
> ---
> drivers/phy/realtek/phy-rtk-usb2.c | 6 +++---
> drivers/phy/realtek/phy-rtk-usb3.c | 6 +++---
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/phy/realtek/phy-rtk-usb2.c b/drivers/phy/realtek/phy-rtk-usb2.c
> index 5e7ee060b404..67ca78762c80 100644
> --- a/drivers/phy/realtek/phy-rtk-usb2.c
> +++ b/drivers/phy/realtek/phy-rtk-usb2.c
> @@ -853,11 +853,11 @@ static inline void create_debug_files(struct rtk_phy *rtk_phy)
>
> rtk_phy->debug_dir = debugfs_create_dir(dev_name(rtk_phy->dev),
> phy_debug_root);
> - if (!rtk_phy->debug_dir)
> + if (IS_ERR(rtk_phy->debug_dir))
> return;
No, please just drop this check.
>
> - if (!debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy,
> - &rtk_usb2_parameter_fops))
> + if (IS_ERR(debugfs_create_file("parameter", 0444, rtk_phy->debug_dir, rtk_phy,
> + &rtk_usb2_parameter_fops)))
Again, no, please never check the return value of debugfs_create_file(),
it's not needed at all, and no kernel code should ever do something
different if debugfs returns an error.
debugfs calls should not be checked, they can just be safely passed back
into other debugfs calls, if needed. That is it. This api is supposed
to be simple and safe, please don't make it harder than it needs to be :)
thanks,
greg k-h
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-31 14:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-31 14:05 [PATCH] phy: realtek: usb: Fix the NULL vs IS_ERR() bug for debugfs_create_dir() Jinjie Ruan
2023-08-31 14:39 ` Greg Kroah-Hartman
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).