[PATCH] of: kobj: fix unreasonable pr_warn() in safe_name()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: chenqiwu <chenqiwu@xxxxxxxxxx>

safe_name() tries to find a non-existing name of kernfs_node
by sysfs_get_dirent() no more than 16 times.

There are three possible results when while loop breaks:
1. i = 0, name = orig_name, name is safe to use.
2. i > 0 && i < 16, name != orig_name, name is safe to use.
3. i == 16, name != orig_name, name is unsafe to use.

However, the original code consider 2nd result as unsafe with
a unnecessary warning message by pr_warn(). This patch can fix
the problem.

Signed-off-by: chenqiwu <chenqiwu@xxxxxxxxxx>
---
 drivers/of/kobj.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c
index c72eef9..b32cf55 100644
--- a/drivers/of/kobj.c
+++ b/drivers/of/kobj.c
@@ -52,11 +52,14 @@ static const char *safe_name(struct kobject *kobj, const char *orig_name)
 	}
 
 	if (name == orig_name) {
-		name = kstrdup(orig_name, GFP_KERNEL);
-	} else {
+		name = kstrdup_const(orig_name, GFP_KERNEL);
+		return name;
+	}
+
+	if (i == 16)
 		pr_warn("Duplicate name in %s, renamed to \"%s\"\n",
 			kobject_name(kobj), name);
-	}
+
 	return name;
 }
 
-- 
1.9.1




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux