1 Star 0 Fork 10

liuzhiqiang/sysfsutils

forked from src-openEuler/sysfsutils 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0001-Fix-issue-with-sysfs-name-comparisons.patch 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
From 744befa9faa3446ff6bf0627cadb6a3addae1dd1 Mon Sep 17 00:00:00 2001
From: Lee Duncan <lduncan@suse.com>
Date: Fri, 3 Jul 2020 11:14:20 -0700
Subject: [PATCH 1/9] Fix issue with sysfs name comparisons.
It turns out that cdev_name_equal() is used
by dlist_find_custom() to compare sysfs
entry names to ones already seen. But it was
comparing using the length of the shortest string
as a maximum, so when it compared, for example,
"eth1" and "eth10", it thought they were the same.
So now just return failure if the strings
aren't the same length, else go ahead and
compare them.
Signed-off-by: Lee Duncan <lduncan@suse.com>
---
lib/sysfs_class.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lib/sysfs_class.c b/lib/sysfs_class.c
index 4fe0b82..c696ff0 100644
--- a/lib/sysfs_class.c
+++ b/lib/sysfs_class.c
@@ -60,13 +60,30 @@ void sysfs_close_class(struct sysfs_class *cls)
}
}
+/*
+ * pass this function to dlist_find_custom()
+ * so it can compare device names
+ *
+ * return 1 if pathnames are equal, else 0
+ */
static int cdev_name_equal(void *a, void *b)
{
+ size_t length_a, length_b;
+ char *str_a, *str_b;
+
if (!a || !b)
return 0;
- if (strncmp((char *)a, ((struct sysfs_class_device *)b)->name,
- strlen((char *)a)) == 0)
+ str_a = (char *)a;
+ str_b = ((struct sysfs_class_device *)b)->name;
+
+ length_a = strnlen(str_a, SYSFS_NAME_LEN+1);
+ length_b = strnlen(str_b, SYSFS_NAME_LEN+1);
+
+ if (length_a != length_b)
+ return 0;
+
+ if (strncmp(str_a, str_b, SYSFS_NAME_LEN+1) == 0)
return 1;
return 0;
--
1.8.3.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuzhiqiang26/sysfsutils.git
git@gitee.com:liuzhiqiang26/sysfsutils.git
liuzhiqiang26
sysfsutils
sysfsutils
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385