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
+7 -16
View File
@@ -66,13 +66,9 @@ static int has_multiple_graphics_cards(void) {
return r;
FOREACH_DEVICE(e, dev) {
const char *s;
unsigned long c;
uint32_t c;
if (sd_device_get_sysattr_value(dev, "class", &s) < 0)
continue;
if (safe_atolu(s, &c) < 0)
if (device_get_sysattr_u32(dev, "class", &c) < 0)
continue;
if (c != PCI_CLASS_GRAPHICS_CARD)
@@ -180,7 +176,7 @@ static int same_device(sd_device *a, sd_device *b) {
static int validate_device(sd_device *device) {
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *enumerate = NULL;
const char *v, *sysname;
const char *sysname;
sd_device *parent;
int r;
@@ -205,10 +201,10 @@ static int validate_device(sd_device *device) {
if (r > 0)
return true; /* We assume LED device is always valid. */
r = sd_device_get_sysattr_value(device, "type", &v);
r = device_get_sysattr_streq(device, "type", "raw");
if (r < 0)
return log_device_debug_errno(device, r, "Failed to read 'type' sysattr: %m");
if (!streq(v, "raw"))
if (r == 0)
return true;
r = find_pci_or_platform_parent(device, &parent);
@@ -316,7 +312,7 @@ static int read_max_brightness(sd_device *device, unsigned *ret) {
r = device_get_sysattr_unsigned(device, "max_brightness", &max_brightness);
if (r < 0)
return log_device_warning_errno(device, r, "Failed to read/parse 'max_brightness' attribute: %m");
return log_device_warning_errno(device, r, "Failed to read 'max_brightness' attribute: %m");
/* If max_brightness is 0, then there is no actual backlight device. This happens on desktops
* with Asus mainboards that load the eeepc-wmi module. */
@@ -418,21 +414,16 @@ static int shall_clamp(sd_device *device, unsigned *ret) {
}
static int read_brightness(sd_device *device, unsigned max_brightness, unsigned *ret_brightness) {
const char *value;
unsigned brightness;
int r;
assert(device);
assert(ret_brightness);
r = sd_device_get_sysattr_value(device, "brightness", &value);
r = device_get_sysattr_unsigned(device, "brightness", &brightness);
if (r < 0)
return log_device_debug_errno(device, r, "Failed to read 'brightness' attribute: %m");
r = safe_atou(value, &brightness);
if (r < 0)
return log_device_debug_errno(device, r, "Failed to parse 'brightness' attribute: %s", value);
if (brightness > max_brightness)
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
"brightness=%u is larger than max_brightness=%u",