All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: megaraid_sas: Fix debugfs setup error handling
@ 2026-10-07 14:17 Lei Chen
  2026-10-07 14:28 ` sashiko-bot
  2026-10-08  2:34 ` [PATCH v2] scsi: megaraid_sas: Simplify debugfs setup Lei Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Lei Chen @ 2026-10-07 14:17 UTC (permalink / raw)
  To: kashyap.desai, sumit.saxena, shivasharan.srikanteshwara,
	chandrakanth.patil
  Cc: James.Bottomley, mkp, megaraidlinux.pdl, linux-scsi, linux-kernel,
	lei.chen

debugfs_create_dir() and debugfs_create_file() return error pointers on
failure, but megasas_setup_debugfs() only checks for NULL. As a result,
setup continues after directory creation fails, and a failure to create
raidmap_dump leaves the per-adapter directory behind.

Skip per-adapter setup if the driver debugfs root is unavailable, and
use IS_ERR_OR_NULL() to check directory and file creation results so
that the existing error paths also handle error pointers.

With the corrected error check, file creation failure removes the
per-adapter directory. Clear the stored directory pointer as well so
teardown does not attempt to remove the freed dentry again.

Fixes: ba53572bf02d ("scsi: megaraid_sas: Export RAID map through debugfs")
Signed-off-by: Lei Chen <lei.chen@smartx.com>
---
 drivers/scsi/megaraid/megaraid_sas_debugfs.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_debugfs.c b/drivers/scsi/megaraid/megaraid_sas_debugfs.c
index 81698cd83f5a..556e01fc25e8 100644
--- a/drivers/scsi/megaraid/megaraid_sas_debugfs.c
+++ b/drivers/scsi/megaraid/megaraid_sas_debugfs.c
@@ -126,13 +126,16 @@ megasas_setup_debugfs(struct megasas_instance *instance)
 
 	fusion = instance->ctrl_context;
 
+	if (IS_ERR_OR_NULL(megasas_debugfs_root))
+		return;
+
 	if (fusion) {
 		snprintf(name, sizeof(name),
 			 "scsi_host%d", instance->host->host_no);
 		if (!instance->debugfs_root) {
 			instance->debugfs_root =
 				debugfs_create_dir(name, megasas_debugfs_root);
-			if (!instance->debugfs_root) {
+			if (IS_ERR_OR_NULL(instance->debugfs_root)) {
 				dev_err(&instance->pdev->dev,
 					"Cannot create per adapter debugfs directory\n");
 				return;
@@ -144,10 +147,11 @@ megasas_setup_debugfs(struct megasas_instance *instance)
 			debugfs_create_file(name, S_IRUGO,
 					    instance->debugfs_root, instance,
 					    &megasas_debugfs_raidmap_fops);
-		if (!instance->raidmap_dump) {
+		if (IS_ERR_OR_NULL(instance->raidmap_dump)) {
 			dev_err(&instance->pdev->dev,
 				"Cannot create raidmap debugfs file\n");
 			debugfs_remove(instance->debugfs_root);
+			instance->debugfs_root = NULL;
 			return;
 		}
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: megaraid_sas: Fix debugfs setup error handling
  2026-10-07 14:17 [PATCH] scsi: megaraid_sas: Fix debugfs setup error handling Lei Chen
@ 2026-10-07 14:28 ` sashiko-bot
  2026-10-08  2:34 ` [PATCH v2] scsi: megaraid_sas: Simplify debugfs setup Lei Chen
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-07 14:28 UTC (permalink / raw)
  To: Lei Chen; +Cc: linux-scsi

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] scsi: megaraid_sas: debugfs API violation by checking return values and logging errors
--

commit 3a04787b7089e752e49721091a64cf2824d3811c
Author: Lei Chen <lei.chen@smartx.com>

scsi: megaraid_sas: Fix debugfs setup error handling

This commit updates the debugfs setup in megaraid_sas to handle error
pointers by adding IS_ERR_OR_NULL checks. It also ensures that the
per-adapter directory is cleaned up and its pointer cleared if the raidmap
file creation fails.

> diff --git a/drivers/scsi/megaraid/megaraid_sas_debugfs.c b/drivers/scsi/megaraid/megaraid_sas_debugfs.c
> index 81698cd83f5ae..556e01fc25e8e 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_debugfs.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_debugfs.c
> @@ -126,13 +126,16 @@ megasas_setup_debugfs(struct megasas_instance *instance)

[ ... ]

>  		if (!instance->debugfs_root) {
>  			instance->debugfs_root =
>  				debugfs_create_dir(name, megasas_debugfs_root);
> -			if (!instance->debugfs_root) {
> +			if (IS_ERR_OR_NULL(instance->debugfs_root)) {
>  				dev_err(&instance->pdev->dev,
>  					"Cannot create per adapter debugfs directory\n");

[Severity: Low]
Does this violate the debugfs API guidelines?

The debugfs guidelines recommend that drivers should not check the return
values of debugfs_create_*() functions.

If debugfs fails, such as due to memory constraints or runtime parameters,
these IS_ERR_OR_NULL() checks in megasas_setup_debugfs() will evaluate to
true and print a dev_err to the kernel log, creating spurious error logs
and adding unnecessary error-handling complexity.

>  				return;
> @@ -144,10 +147,11 @@ megasas_setup_debugfs(struct megasas_instance *instance)
>  			debugfs_create_file(name, S_IRUGO,
>  					    instance->debugfs_root, instance,
>  					    &megasas_debugfs_raidmap_fops);
> -		if (!instance->raidmap_dump) {
> +		if (IS_ERR_OR_NULL(instance->raidmap_dump)) {
>  			dev_err(&instance->pdev->dev,
>  				"Cannot create raidmap debugfs file\n");

[Severity: Low]
Could this be simplified by removing the error check entirely?

Similar to the directory creation above, checking the return value of
debugfs_create_file() here in megasas_setup_debugfs() is generally
discouraged. Removing these checks completely might align better with the
subsystem guidelines.

>  			debugfs_remove(instance->debugfs_root);
> +			instance->debugfs_root = NULL;
>  			return;
>  		}
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007141753.416672-1-lei.chen@smartx.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] scsi: megaraid_sas: Simplify debugfs setup
  2026-10-07 14:17 [PATCH] scsi: megaraid_sas: Fix debugfs setup error handling Lei Chen
  2026-10-07 14:28 ` sashiko-bot
@ 2026-10-08  2:34 ` Lei Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Lei Chen @ 2026-10-08  2:34 UTC (permalink / raw)
  To: kashyap.desai, sumit.saxena, shivasharan.srikanteshwara,
	chandrakanth.patil
  Cc: megaraidlinux.pdl, James.Bottomley, mkp, linux-scsi, linux-kernel,
	lei.chen

The debugfs creation helpers return error pointers on failure, so the
existing NULL checks do not handle creation failures. There is no need
to add error handling here: debugfs accepts error pointers as parents
and debugfs_remove_recursive() safely handles error pointers and NULL.

Remove the ineffective checks, error messages and file-creation rollback.
Leave any successfully created directory for the existing teardown path
to remove, even if creating raidmap_dump fails.

The setup function is called only once per instance from probe, so create
the per-adapter directory without checking whether it already exists.

Signed-off-by: Lei Chen <lei.chen@smartx.com>
---
Changes in v2:
- Remove debugfs error checks and logging instead of adding
  IS_ERR_OR_NULL() checks, following review feedback.
- Leave directory cleanup to the existing teardown path.
- Remove the redundant directory existence check, since setup is called
  only once per instance from probe.
- Reframe the patch as a cleanup and drop the Fixes tag.

Link to v1:
https://lore.kernel.org/all/20261007141753.416672-1-lei.chen@smartx.com/

 drivers/scsi/megaraid/megaraid_sas_debugfs.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/megaraid/megaraid_sas_debugfs.c b/drivers/scsi/megaraid/megaraid_sas_debugfs.c
index 81698cd83f5a..2fdb4c6bd3d9 100644
--- a/drivers/scsi/megaraid/megaraid_sas_debugfs.c
+++ b/drivers/scsi/megaraid/megaraid_sas_debugfs.c
@@ -102,8 +102,6 @@ static const struct file_operations megasas_debugfs_raidmap_fops = {
 void megasas_init_debugfs(void)
 {
 	megasas_debugfs_root = debugfs_create_dir("megaraid_sas", NULL);
-	if (!megasas_debugfs_root)
-		pr_info("Cannot create debugfs root\n");
 }
 
 /*
@@ -129,27 +127,14 @@ megasas_setup_debugfs(struct megasas_instance *instance)
 	if (fusion) {
 		snprintf(name, sizeof(name),
 			 "scsi_host%d", instance->host->host_no);
-		if (!instance->debugfs_root) {
-			instance->debugfs_root =
-				debugfs_create_dir(name, megasas_debugfs_root);
-			if (!instance->debugfs_root) {
-				dev_err(&instance->pdev->dev,
-					"Cannot create per adapter debugfs directory\n");
-				return;
-			}
-		}
+		instance->debugfs_root =
+			debugfs_create_dir(name, megasas_debugfs_root);
 
 		snprintf(name, sizeof(name), "raidmap_dump");
 		instance->raidmap_dump =
 			debugfs_create_file(name, S_IRUGO,
 					    instance->debugfs_root, instance,
 					    &megasas_debugfs_raidmap_fops);
-		if (!instance->raidmap_dump) {
-			dev_err(&instance->pdev->dev,
-				"Cannot create raidmap debugfs file\n");
-			debugfs_remove(instance->debugfs_root);
-			return;
-		}
 	}
 
 }
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-08  2:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-07 14:17 [PATCH] scsi: megaraid_sas: Fix debugfs setup error handling Lei Chen
2026-10-07 14:28 ` sashiko-bot
2026-10-08  2:34 ` [PATCH v2] scsi: megaraid_sas: Simplify debugfs setup Lei Chen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.