tree-wide: use device_get_sysattr_unsigned() and friends

This commit is contained in:
Yu Watanabe
2026-05-18 02:55:56 +09:00
parent 6ad682d70f
commit 6f72bb7bc9
10 changed files with 47 additions and 104 deletions
+4 -5
View File
@@ -75,11 +75,10 @@ static bool battery_is_discharging(sd_device *d) {
assert(d);
r = sd_device_get_sysattr_value(d, "scope", &val);
if (r < 0) {
if (r != -ENOENT)
log_device_debug_errno(d, r, "Failed to read 'scope' sysfs attribute, ignoring: %m");
} else if (streq(val, "Device")) {
r = device_get_sysattr_streq(d, "scope", "Device");
if (r < 0 && r != -ENOENT)
log_device_debug_errno(d, r, "Failed to read 'scope' sysfs attribute, ignoring: %m");
if (r > 0) {
log_device_debug(d, "The power supply is a device battery, ignoring device.");
return false;
}
+4 -25
View File
@@ -5,6 +5,7 @@
#include "alloc-util.h"
#include "conf-parser.h"
#include "device-private.h"
#include "device-util.h"
#include "ether-addr-util.h"
#include "netif-sriov.h"
@@ -267,28 +268,11 @@ int sr_iov_set_netlink_message(SRIOV *sr_iov, SRIOVAttribute attr, sd_netlink_me
}
int sr_iov_get_num_vfs(sd_device *device, uint32_t *ret) {
const char *str;
uint32_t n;
int r;
assert(device);
assert(ret);
r = sd_device_get_sysattr_value(device, "device/sriov_numvfs", &str);
if (r < 0)
return r;
r = safe_atou32(str, &n);
if (r < 0)
return r;
*ret = n;
return 0;
return device_get_sysattr_u32(device, "device/sriov_numvfs", ret);
}
int sr_iov_set_num_vfs(sd_device *device, uint32_t num_vfs, OrderedHashmap *sr_iov_by_section) {
char val[DECIMAL_STR_MAX(uint32_t)];
const char *str;
int r;
assert(device);
@@ -327,14 +311,9 @@ int sr_iov_set_num_vfs(sd_device *device, uint32_t num_vfs, OrderedHashmap *sr_i
* maximum allowed number of VFs from the sriov_totalvfs sysattr. Note that the sysattr
* currently exists only for PCI drivers. Hence, ignore -ENOENT.
* TODO: netdevsim provides the information in debugfs. */
r = sd_device_get_sysattr_value(device, "device/sriov_totalvfs", &str);
uint32_t max_num_vfs;
r = device_get_sysattr_u32(device, "device/sriov_totalvfs", &max_num_vfs);
if (r >= 0) {
uint32_t max_num_vfs;
r = safe_atou32(str, &max_num_vfs);
if (r < 0)
return log_device_debug_errno(device, r, "Failed to parse device/sriov_totalvfs sysfs attribute '%s': %m", str);
if (num_vfs > max_num_vfs)
return log_device_debug_errno(device, SYNTHETIC_ERRNO(ERANGE),
"Specified number of virtual functions is out of range. "