* [PATCH] drdb: fix debugfs_create_dir and debugfs_create_symlink error handling
@ 2023-05-14 12:39 mirimmad
2023-05-14 14:10 ` [PATCH v2] " mirimmad
0 siblings, 1 reply; 3+ messages in thread
From: mirimmad @ 2023-05-14 12:39 UTC (permalink / raw)
Cc: skhan, Immad Mir, Philipp Reisner, Lars Ellenberg,
Christoph Böhmwalder, Jens Axboe, drbd-dev, linux-block,
linux-kernel
From: Immad Mir <mirimmad17@gmail.com>
debugfs_create_dir and debugfs_create_symlink return ERR_PTR incase of
a failure which must be checked with the inline function IS_ERR. This
patch attempts to do the same.
Signed-off-by: Immad Mir <mirimmad17@gmail.com>
---
drivers/block/drbd/drbd_debugfs.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/block/drbd/drbd_debugfs.c b/drivers/block/drbd/drbd_debugfs.c
index 12460b584..1cec65563 100644
--- a/drivers/block/drbd/drbd_debugfs.c
+++ b/drivers/block/drbd/drbd_debugfs.c
@@ -781,6 +781,7 @@ void drbd_debugfs_device_add(struct drbd_device *device)
snprintf(vnr_buf, sizeof(vnr_buf), "%u", device->vnr);
dentry = debugfs_create_dir(vnr_buf, vols_dir);
+ if (IS_ERR(dentry)) goto fail;
device->debugfs_vol = dentry;
snprintf(minor_buf, sizeof(minor_buf), "%u", device->minor);
@@ -789,9 +790,12 @@ void drbd_debugfs_device_add(struct drbd_device *device)
if (!slink_name)
goto fail;
dentry = debugfs_create_symlink(minor_buf, drbd_debugfs_minors, slink_name);
+ if (!IS_ERR(dentry)) {
device->debugfs_minor = dentry;
kfree(slink_name);
slink_name = NULL;
+ } else
+ goto fail;
#define DCF(name) do { \
dentry = debugfs_create_file(#name, 0440, \
--
2.40.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2] drdb: fix debugfs_create_dir and debugfs_create_symlink error handling
2023-05-14 12:39 [PATCH] drdb: fix debugfs_create_dir and debugfs_create_symlink error handling mirimmad
@ 2023-05-14 14:10 ` mirimmad
2023-05-15 8:56 ` Christoph Böhmwalder
0 siblings, 1 reply; 3+ messages in thread
From: mirimmad @ 2023-05-14 14:10 UTC (permalink / raw)
Cc: axboe, christoph.boehmwalder, drbd-dev, lars.ellenberg,
linux-block, linux-kernel, mirimmad17, philipp.reisner, skhan
From: Immad Mir <mirimmad17@gmail.com>
debugfs_create_dir and debugfs_create_symlink return ERR_PTR incase of
a failure which must be checked with the inline function IS_ERR. This
patch attempts to do the same.
Signed-off-by: Immad Mir <mirimmad17@gmail.com>
---
Changes in v2:
- Fix indentation
- Fix potential memory leak
drivers/block/drbd/drbd_debugfs.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/block/drbd/drbd_debugfs.c b/drivers/block/drbd/drbd_debugfs.c
index 12460b584..ab431a3f2 100644
--- a/drivers/block/drbd/drbd_debugfs.c
+++ b/drivers/block/drbd/drbd_debugfs.c
@@ -781,6 +781,7 @@ void drbd_debugfs_device_add(struct drbd_device *device)
snprintf(vnr_buf, sizeof(vnr_buf), "%u", device->vnr);
dentry = debugfs_create_dir(vnr_buf, vols_dir);
+ if (IS_ERR(dentry)) goto fail;
device->debugfs_vol = dentry;
snprintf(minor_buf, sizeof(minor_buf), "%u", device->minor);
@@ -789,9 +790,15 @@ void drbd_debugfs_device_add(struct drbd_device *device)
if (!slink_name)
goto fail;
dentry = debugfs_create_symlink(minor_buf, drbd_debugfs_minors, slink_name);
- device->debugfs_minor = dentry;
- kfree(slink_name);
- slink_name = NULL;
+ if (!IS_ERR(dentry)) {
+ device->debugfs_minor = dentry;
+ kfree(slink_name);
+ slink_name = NULL;
+ } else {
+ kfree(slink_name);
+ slink_name = NULL;
+ goto fail;
+ }
#define DCF(name) do { \
dentry = debugfs_create_file(#name, 0440, \
--
2.40.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drdb: fix debugfs_create_dir and debugfs_create_symlink error handling
2023-05-14 14:10 ` [PATCH v2] " mirimmad
@ 2023-05-15 8:56 ` Christoph Böhmwalder
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Böhmwalder @ 2023-05-15 8:56 UTC (permalink / raw)
To: mirimmad
Cc: axboe, drbd-dev, lars.ellenberg, linux-block, linux-kernel,
mirimmad17, philipp.reisner, skhan
Am 14.05.23 um 16:10 schrieb mirimmad@outlook.com:
> From: Immad Mir <mirimmad17@gmail.com>
>
> debugfs_create_dir and debugfs_create_symlink return ERR_PTR incase of
> a failure which must be checked with the inline function IS_ERR. This
> patch attempts to do the same.
>
> Signed-off-by: Immad Mir <mirimmad17@gmail.com>
> ---
> Changes in v2:
> - Fix indentation
> - Fix potential memory leak
>
> drivers/block/drbd/drbd_debugfs.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/block/drbd/drbd_debugfs.c b/drivers/block/drbd/drbd_debugfs.c
> index 12460b584..ab431a3f2 100644
> --- a/drivers/block/drbd/drbd_debugfs.c
> +++ b/drivers/block/drbd/drbd_debugfs.c
> @@ -781,6 +781,7 @@ void drbd_debugfs_device_add(struct drbd_device *device)
>
> snprintf(vnr_buf, sizeof(vnr_buf), "%u", device->vnr);
> dentry = debugfs_create_dir(vnr_buf, vols_dir);
> + if (IS_ERR(dentry)) goto fail;
> device->debugfs_vol = dentry;
>
> snprintf(minor_buf, sizeof(minor_buf), "%u", device->minor);
> @@ -789,9 +790,15 @@ void drbd_debugfs_device_add(struct drbd_device *device)
> if (!slink_name)
> goto fail;
> dentry = debugfs_create_symlink(minor_buf, drbd_debugfs_minors, slink_name);
> - device->debugfs_minor = dentry;
> - kfree(slink_name);
> - slink_name = NULL;
> + if (!IS_ERR(dentry)) {
> + device->debugfs_minor = dentry;
> + kfree(slink_name);
> + slink_name = NULL;
> + } else {
> + kfree(slink_name);
> + slink_name = NULL;
> + goto fail;
> + }
>
> #define DCF(name) do { \
> dentry = debugfs_create_file(#name, 0440, \
> --
> 2.40.0
>
>
Hi, thanks for the patch.
Please see this commit:
commit d27e84a305980ac61df0a6841059d0eb09b8283d
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Tue Jun 18 17:45:49 2019 +0200
block: drbd: no need to check return value of debugfs_create functions
When calling debugfs functions, there is no need to ever check the
return value. The function can work or not, but the code logic should
never do something different based on this.
Also, it still looks like that whitespace is garbled.
NAK.
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA — Disaster Recovery — Software defined Storage
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-15 8:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-14 12:39 [PATCH] drdb: fix debugfs_create_dir and debugfs_create_symlink error handling mirimmad
2023-05-14 14:10 ` [PATCH v2] " mirimmad
2023-05-15 8:56 ` Christoph Böhmwalder
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).