summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-23 12:13:56 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-23 12:31:20 +0100
commita33bc79b993c8be4a224f35b4626ffa20967cff3 (patch)
tree15261542de2a9936d9ea695891eb5320fb1b8fac /src
parentFIDO2 device removal instructions (#21426) (diff)
downloadsystemd-a33bc79b993c8be4a224f35b4626ffa20967cff3.tar.xz
systemd-a33bc79b993c8be4a224f35b4626ffa20967cff3.zip
udev/cdrom_id: use a macro to initialize context
c was initialized unconditionally, but one has to look at the function body to understand this. Let's make the whole thing shorter and more direct.
Diffstat (limited to 'src')
-rw-r--r--src/udev/cdrom_id/cdrom_id.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c
index a2185350d3..cdb66bb3b7 100644
--- a/src/udev/cdrom_id/cdrom_id.c
+++ b/src/udev/cdrom_id/cdrom_id.c
@@ -102,6 +102,12 @@ typedef struct Context {
uint64_t media_session_last_offset;
} Context;
+#define CONTEXT_EMPTY { \
+ .fd = -1, \
+ .media_feature = _FEATURE_INVALID, \
+ .media_state = _MEDIA_STATE_INVALID, \
+ }
+
static void context_clear(Context *c) {
if (!c)
return;
@@ -110,16 +116,6 @@ static void context_clear(Context *c) {
free(c->drive_features);
}
-static void context_init(Context *c) {
- assert(c);
-
- *c = (Context) {
- .fd = -1,
- .media_feature = _FEATURE_INVALID,
- .media_state = _MEDIA_STATE_INVALID,
- };
-}
-
static bool drive_has_feature(const Context *c, Feature f) {
assert(c);
@@ -954,7 +950,7 @@ static int parse_argv(int argc, char *argv[]) {
}
static int run(int argc, char *argv[]) {
- _cleanup_(context_clear) Context c;
+ _cleanup_(context_clear) Context c = CONTEXT_EMPTY;
int r;
log_set_target(LOG_TARGET_AUTO);
@@ -962,8 +958,6 @@ static int run(int argc, char *argv[]) {
log_parse_environment();
log_open();
- context_init(&c);
-
r = parse_argv(argc, argv);
if (r <= 0)
return r;