Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
470498de
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
470498de
编写于
6月 03, 2016
作者:
J
Ján Tomko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove extra allocation in udevGetDeviceSysfsAttr
Most of the code paths free it right after converting it to an integer.
上级
10427db7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
69 deletion
+29
-69
src/node_device/node_device_udev.c
src/node_device/node_device_udev.c
+29
-69
未找到文件。
src/node_device/node_device_udev.c
浏览文件 @
470498de
...
...
@@ -129,38 +129,17 @@ static int udevGetUintProperty(struct udev_device *udev_device,
}
/* This function allocates memory from the heap for the property
* value. That memory must be later freed by some other code.
* Any control characters that cannot be printed in the XML are stripped
* from the string */
static
int
udevGetDeviceSysfsAttr
(
struct
udev_device
*
udev_device
,
const
char
*
attr_name
,
char
**
attr_value
)
static
const
char
*
udevGetDeviceSysfsAttr
(
struct
udev_device
*
udev_device
,
const
char
*
attr_name
)
{
const
char
*
udev_value
=
NULL
;
int
ret
=
PROPERTY_FOUND
;
udev_value
=
udev_device_get_sysattr_value
(
udev_device
,
attr_name
);
if
(
udev_value
==
NULL
)
{
VIR_DEBUG
(
"udev reports device '%s' does not have sysfs attr '%s'"
,
udev_device_get_sysname
(
udev_device
),
attr_name
);
ret
=
PROPERTY_MISSING
;
goto
out
;
}
const
char
*
ret
=
NULL
;
/* If this allocation is changed, the comment at the beginning
* of the function must also be changed. */
if
(
VIR_STRDUP
(
*
attr_value
,
udev_value
)
<
0
)
{
ret
=
PROPERTY_ERROR
;
goto
out
;
}
ret
=
udev_device_get_sysattr_value
(
udev_device
,
attr_name
);
VIR_DEBUG
(
"Found sysfs attribute '%s' value '%s' "
"for device with sysname '%s'"
,
attr_name
,
*
attr_value
,
attr_name
,
NULLSTR
(
ret
)
,
udev_device_get_sysname
(
udev_device
));
out:
return
ret
;
}
...
...
@@ -169,22 +148,15 @@ static int udevGetStringSysfsAttr(struct udev_device *udev_device,
const
char
*
attr_name
,
char
**
value
)
{
char
*
tmp
=
NULL
;
int
ret
=
PROPERTY_MISSING
;
ret
=
udevGetDeviceSysfsAttr
(
udev_device
,
attr_name
,
&
tmp
);
if
(
VIR_STRDUP
(
*
value
,
udevGetDeviceSysfsAttr
(
udev_device
,
attr_name
))
<
0
)
return
PROPERTY_ERROR
;
virStringStripControlChars
(
tmp
);
virStringStripControlChars
(
*
value
);
if
(
tmp
!=
NULL
&&
(
STREQ
(
tmp
,
""
)))
{
VIR_FREE
(
tmp
);
tmp
=
NULL
;
ret
=
PROPERTY_MISSING
;
}
*
value
=
tmp
;
if
(
*
value
!=
NULL
&&
(
STREQ
(
*
value
,
""
)))
VIR_FREE
(
*
value
);
return
ret
;
return
*
value
==
NULL
?
PROPERTY_MISSING
:
PROPERTY_FOUND
;
}
...
...
@@ -193,20 +165,16 @@ static int udevGetIntSysfsAttr(struct udev_device *udev_device,
int
*
value
,
int
base
)
{
char
*
udev_value
=
NULL
;
int
ret
=
PROPERTY_FOUND
;
const
char
*
str
=
NULL
;
ret
=
udevGetDeviceSysfsAttr
(
udev_device
,
attr_name
,
&
udev_valu
e
);
str
=
udevGetDeviceSysfsAttr
(
udev_device
,
attr_nam
e
);
if
(
ret
==
PROPERTY_FOUND
)
{
if
(
virStrToLong_i
(
udev_value
,
NULL
,
base
,
value
)
<
0
)
{
VIR_ERROR
(
_
(
"Failed to convert '%s' to int"
),
udev_value
);
ret
=
PROPERTY_ERROR
;
}
if
(
str
&&
virStrToLong_i
(
str
,
NULL
,
base
,
value
)
<
0
)
{
VIR_ERROR
(
_
(
"Failed to convert '%s' to int"
),
str
);
return
PROPERTY_ERROR
;
}
VIR_FREE
(
udev_value
);
return
ret
;
return
str
==
NULL
?
PROPERTY_MISSING
:
PROPERTY_FOUND
;
}
...
...
@@ -215,20 +183,16 @@ static int udevGetUintSysfsAttr(struct udev_device *udev_device,
unsigned
int
*
value
,
int
base
)
{
char
*
udev_value
=
NULL
;
int
ret
=
PROPERTY_FOUND
;
const
char
*
str
=
NULL
;
ret
=
udevGetDeviceSysfsAttr
(
udev_device
,
attr_name
,
&
udev_valu
e
);
str
=
udevGetDeviceSysfsAttr
(
udev_device
,
attr_nam
e
);
if
(
ret
==
PROPERTY_FOUND
)
{
if
(
virStrToLong_ui
(
udev_value
,
NULL
,
base
,
value
)
<
0
)
{
VIR_ERROR
(
_
(
"Failed to convert '%s' to unsigned int"
),
udev_value
);
ret
=
PROPERTY_ERROR
;
}
if
(
str
&&
virStrToLong_ui
(
str
,
NULL
,
base
,
value
)
<
0
)
{
VIR_ERROR
(
_
(
"Failed to convert '%s' to unsigned int"
),
str
);
return
PROPERTY_ERROR
;
}
VIR_FREE
(
udev_value
);
return
ret
;
return
str
==
NULL
?
PROPERTY_MISSING
:
PROPERTY_FOUND
;
}
...
...
@@ -236,20 +200,16 @@ static int udevGetUint64SysfsAttr(struct udev_device *udev_device,
const
char
*
attr_name
,
unsigned
long
long
*
value
)
{
char
*
udev_value
=
NULL
;
int
ret
=
PROPERTY_FOUND
;
const
char
*
str
=
NULL
;
ret
=
udevGetDeviceSysfsAttr
(
udev_device
,
attr_name
,
&
udev_valu
e
);
str
=
udevGetDeviceSysfsAttr
(
udev_device
,
attr_nam
e
);
if
(
ret
==
PROPERTY_FOUND
)
{
if
(
virStrToLong_ull
(
udev_value
,
NULL
,
0
,
value
)
<
0
)
{
VIR_ERROR
(
_
(
"Failed to convert '%s' to unsigned long long"
),
udev_value
);
ret
=
PROPERTY_ERROR
;
}
if
(
str
&&
virStrToLong_ull
(
str
,
NULL
,
0
,
value
)
<
0
)
{
VIR_ERROR
(
_
(
"Failed to convert '%s' to unsigned long long"
),
str
);
return
PROPERTY_ERROR
;
}
VIR_FREE
(
udev_value
);
return
ret
;
return
str
==
NULL
?
PROPERTY_MISSING
:
PROPERTY_FOUND
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录