Skip to content

Commit 74f1bb5

Browse files
committed
backlight: use SYNTHETIC_ERRNO() macro
1 parent 7aee1e7 commit 74f1bb5

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/backlight/backlight.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ static int get_max_brightness(sd_device *device, unsigned *ret) {
224224
if (r < 0)
225225
return log_device_warning_errno(device, r, "Failed to parse 'max_brightness' \"%s\": %m", max_brightness_str);
226226

227-
if (max_brightness <= 0) {
228-
log_device_warning(device, "Maximum brightness is 0, ignoring device.");
229-
return -EINVAL;
230-
}
227+
if (max_brightness <= 0)
228+
return log_device_warning_errno(device, SYNTHETIC_ERRNO(EINVAL), "Maximum brightness is 0, ignoring device.");
231229

232230
*ret = max_brightness;
233231
return 0;
@@ -306,10 +304,8 @@ static int run(int argc, char *argv[]) {
306304
unsigned max_brightness;
307305
int r;
308306

309-
if (argc != 3) {
310-
log_error("This program requires two arguments.");
311-
return -EINVAL;
312-
}
307+
if (argc != 3)
308+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program requires two arguments.");
313309

314310
log_setup_service();
315311

@@ -320,19 +316,15 @@ static int run(int argc, char *argv[]) {
320316
return log_error_errno(r, "Failed to create backlight directory /var/lib/systemd/backlight: %m");
321317

322318
sysname = strchr(argv[2], ':');
323-
if (!sysname) {
324-
log_error("Requires a subsystem and sysname pair specifying a backlight device.");
325-
return -EINVAL;
326-
}
319+
if (!sysname)
320+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Requires a subsystem and sysname pair specifying a backlight device.");
327321

328322
ss = strndupa(argv[2], sysname - argv[2]);
329323

330324
sysname++;
331325

332-
if (!STR_IN_SET(ss, "backlight", "leds")) {
333-
log_error("Not a backlight or LED device: '%s:%s'", ss, sysname);
334-
return -EINVAL;
335-
}
326+
if (!STR_IN_SET(ss, "backlight", "leds"))
327+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not a backlight or LED device: '%s:%s'", ss, sysname);
336328

337329
r = sd_device_new_from_subsystem_sysname(&device, ss, sysname);
338330
if (r < 0)
@@ -424,10 +416,8 @@ static int run(int argc, char *argv[]) {
424416
if (r < 0)
425417
return log_device_error_errno(device, r, "Failed to write %s: %m", saved);
426418

427-
} else {
428-
log_error("Unknown verb %s.", argv[1]);
429-
return -EINVAL;
430-
}
419+
} else
420+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown verb %s.", argv[1]);
431421

432422
return 0;
433423
}

0 commit comments

Comments
 (0)