Skip to contentSkip to conversation

media: rockchip: rkisp1: remove some dead code

PATCH In review Dan Carpenter 2 participants 6 messages Nov 30, 2020 – Dec 1, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: rockchip: rkisp1: remove some dead code

The debugfs_create_dir() function never returns NULLs. It's not supposed to checked for errors in the normal case and there is no need to check in this function so let's just delete this dead code.

---
 drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -4
index 9af137e4967f..68da1eed753d 100644
@@ -430,10 +430,6 @@ static void rkisp1_debug_init(struct rkisp1_device *rkisp1)
 	struct rkisp1_debug *debug = &rkisp1->debug;
 
 	debug->debugfs_dir = debugfs_create_dir(RKISP1_DRIVER_NAME, NULL);
-	if (!debug->debugfs_dir) {
-		dev_dbg(rkisp1->dev, "failed to create debugfs directory\n");
-		return;
-	}
 	debugfs_create_ulong("data_loss", 0444, debug->debugfs_dir,
 			     &debug->data_loss);
 	debugfs_create_ulong("outform_size_err", 0444,  debug->debugfs_dir,
Signature · 1 line
2.29.2
#1 lore raw

Hi Dan,

Thank you for your patch.

Quoted 14 lines · Dan Carpenter

The debugfs_create_dir() function never returns NULLs. It's not supposed to checked for errors in the normal case and there is no need to check in this function so let's just delete this dead code.

---
 drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -0
index 9af137e4967f..68da1eed753d 100644

drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c static void rkisp1_debug_init(struct rkisp1_device *rkisp1) · line 436

Quoted 7 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -4
@@ -430,10 +430,6 @@ static void rkisp1_debug_init(struct rkisp1_device *rkisp1)
 	struct rkisp1_debug *debug = &rkisp1->debug;
 
 	debug->debugfs_dir = debugfs_create_dir(RKISP1_DRIVER_NAME, NULL);
-	if (!debug->debugfs_dir) {
-		dev_dbg(rkisp1->dev, "failed to create debugfs directory\n");
-		return;
-	}

I was taking a look at the debugfs_create_dir() code, and I saw it can return ERR_PTR(), so ideally we should check for errors with IS_ERR() / PTR_ERR().

Also from the docs:

* <snip> If an error occurs, ERR_PTR(-ERROR) will be
* returned.
*
* If debugfs is not enabled in the kernel, the value -%ENODEV will be
* returned.

drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c static void rkisp1_debug_init(struct rkisp1_device *rkisp1) · line 435

Quoted 4 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -0
 	debugfs_create_ulong("data_loss", 0444, debug->debugfs_dir,
 			     &debug->data_loss);
 	debugfs_create_ulong("outform_size_err", 0444,  debug->debugfs_dir,

nit: I would change the name of the commit just to make it clear what it does.
Example: Remove useless error check from debugfs_create_dir()

Thanks,
Helen

#2 lore raw
Quoted 21 lines · Helen Koike

Hi Dan,

Thank you for your patch.

Quoted 16 lines · Dan Carpenter

The debugfs_create_dir() function never returns NULLs. It's not supposed to checked for errors in the normal case and there is no need to check in this function so let's just delete this dead code.

---
 drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -0
index 9af137e4967f..68da1eed753d 100644
@@ -430,10 +430,6 @@ static void rkisp1_debug_init(struct rkisp1_device *rkisp1)
 	struct rkisp1_debug *debug = &rkisp1->debug;
 
Quoted 8 lines

drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c static void rkisp1_debug_init(struct rkisp1_device *rkisp1) · line 436

Quoted 5 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -4
 	debug->debugfs_dir = debugfs_create_dir(RKISP1_DRIVER_NAME, NULL);
-	if (!debug->debugfs_dir) {
-		dev_dbg(rkisp1->dev, "failed to create debugfs directory\n");
-		return;
-	}

I was taking a look at the debugfs_create_dir() code, and I saw it can return ERR_PTR(), so ideally we should check for errors with IS_ERR() / PTR_ERR().

Debugfs functions aren't meant to be error checked in the normal case. There are some drivers which dereference the dentry pointer so those need to check it but that's not very common and isn't the case here.

I'm really sure this must be documented somewhere but I can't find it at all. :P But look at commit 057e212eae72 ("media: usb: uvc: no need to check return value of debugfs_create functions") for example.

regards,
dan carpenter

#3 lore raw

Hi Dan,

Quoted 31 lines · Dan Carpenter
Quoted 21 lines · Helen Koike

Hi Dan,

Thank you for your patch.

Quoted 16 lines · Dan Carpenter

The debugfs_create_dir() function never returns NULLs. It's not supposed to checked for errors in the normal case and there is no need to check in this function so let's just delete this dead code.

---
 drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -0
index 9af137e4967f..68da1eed753d 100644
@@ -430,10 +430,6 @@ static void rkisp1_debug_init(struct rkisp1_device *rkisp1)
 	struct rkisp1_debug *debug = &rkisp1->debug;
 
Quoted 8 lines

drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c static void rkisp1_debug_init(struct rkisp1_device *rkisp1) · line 436

Quoted 5 lines
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -4
 	debug->debugfs_dir = debugfs_create_dir(RKISP1_DRIVER_NAME, NULL);
-	if (!debug->debugfs_dir) {
-		dev_dbg(rkisp1->dev, "failed to create debugfs directory\n");
-		return;
-	}

I was taking a look at the debugfs_create_dir() code, and I saw it can return ERR_PTR(), so ideally we should check for errors with IS_ERR() / PTR_ERR().

Quoted 3 lines

Debugfs functions aren't meant to be error checked in the normal case. There are some drivers which dereference the dentry pointer so those need to check it but that's not very common and isn't the case here.

right, I just saw the functions in inode.c already checks the parent with IS_ERR(). the debugfs_create_*() function calls start_creating() which already checks the parent.

ok, fair enough, I'll ack v2.

Regards,
Helen

Quoted 8 lines

I'm really sure this must be documented somewhere but I can't find it at all. :P But look at commit 057e212eae72 ("media: usb: uvc: no need to check return value of debugfs_create functions") for example.

regards,
dan carpenter

#4 lore raw

PATCH v2 1/1 media: rockchip: rkisp1: remove useless debugfs checks

In reply to Helen Koike

The debugfs_create_dir() function never returns NULLs so this code will never be executed. It's not intended that callers will check for debugfs errors in the normal case and it's not necessary in this driver, so we can just delete this code.

---
v2: Fix subject

 drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -4
index 9af137e4967f..68da1eed753d 100644
@@ -430,10 +430,6 @@ static void rkisp1_debug_init(struct rkisp1_device *rkisp1)
 	struct rkisp1_debug *debug = &rkisp1->debug;
 
 	debug->debugfs_dir = debugfs_create_dir(RKISP1_DRIVER_NAME, NULL);
-	if (!debug->debugfs_dir) {
-		dev_dbg(rkisp1->dev, "failed to create debugfs directory\n");
-		return;
-	}
 	debugfs_create_ulong("data_loss", 0444, debug->debugfs_dir,
 			     &debug->data_loss);
 	debugfs_create_ulong("outform_size_err", 0444,  debug->debugfs_dir,
Signature · 1 line
2.29.2
Acked-by on v2 1/1
#5 lore raw

Re: [PATCH v2] media: rockchip: rkisp1: remove useless debugfs checks

Quoted 6 lines · Dan Carpenter

The debugfs_create_dir() function never returns NULLs so this code will never be executed. It's not intended that callers will check for debugfs errors in the normal case and it's not necessary in this driver, so we can just delete this code.

Since the debugfs_create_*() functions already check the parent with IS_ERR(), this looks good to me.

Thanks
Helen

Quoted 22 lines

---
v2: Fix subject

 drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c +0 -4
index 9af137e4967f..68da1eed753d 100644
@@ -430,10 +430,6 @@ static void rkisp1_debug_init(struct rkisp1_device *rkisp1)
 	struct rkisp1_debug *debug = &rkisp1->debug;
 
 	debug->debugfs_dir = debugfs_create_dir(RKISP1_DRIVER_NAME, NULL);
-	if (!debug->debugfs_dir) {
-		dev_dbg(rkisp1->dev, "failed to create debugfs directory\n");
-		return;
-	}
 	debugfs_create_ulong("data_loss", 0444, debug->debugfs_dir,
 			     &debug->data_loss);
 	debugfs_create_ulong("outform_size_err", 0444,  debug->debugfs_dir,