From: Daan De Meyer Date: Wed, 12 Jul 2023 06:52:12 +0000 (+0200) Subject: device-util: Declare iterator variables inline X-Git-Tag: v254-rc2~36^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1af83728f49c0b7487368d54cab90c8c87ac3f6;p=thirdparty%2Fsystemd.git device-util: Declare iterator variables inline --- diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index e66477f3288..a3842088799 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -47,7 +47,6 @@ static int help(void) { static int has_multiple_graphics_cards(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *dev; bool found = false; int r; @@ -173,7 +172,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, *subsystem; - sd_device *parent, *other; + sd_device *parent; int r; assert(device); diff --git a/src/core/device.c b/src/core/device.c index 60ab59c53b6..fd87b40306e 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -800,7 +800,7 @@ static int device_setup_devlink_unit_one(Manager *m, const char *devlink, Set ** static int device_setup_extra_units(Manager *m, sd_device *dev, Set **ready_units, Set **not_ready_units) { _cleanup_strv_free_ char **aliases = NULL; - const char *devlink, *syspath, *devname = NULL; + const char *syspath, *devname = NULL; Device *l; int r; @@ -1017,7 +1017,6 @@ static void device_shutdown(Manager *m) { static void device_enumerate(Manager *m) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *dev; int r; assert(m); diff --git a/src/core/swap.c b/src/core/swap.c index 73cf320bfd2..6fc5782bc8c 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -491,7 +491,7 @@ fail: static void swap_process_new(Manager *m, const char *device, int prio, bool set_flags) { _cleanup_(sd_device_unrefp) sd_device *d = NULL; - const char *dn, *devlink; + const char *dn; struct stat st, st_link; int r; @@ -1405,7 +1405,7 @@ fail: int swap_process_device_new(Manager *m, sd_device *dev) { _cleanup_free_ char *e = NULL; - const char *dn, *devlink; + const char *dn; Unit *u; int r; diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index 253e732404b..893fa4f0340 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -1699,7 +1699,6 @@ static int action_detach(const char *path) { } else if (S_ISREG(st.st_mode)) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; /* If a regular file is specified, search for a loopback block device that is backed by it */ diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 9db8b9ee068..addea113b47 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1337,7 +1337,6 @@ static int manager_watch_devices(Manager *m) { static int manager_enumerate_devices(Manager *m) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; int r; assert(m); diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c index 83082c4e94f..de94dc6041c 100644 --- a/src/journal/journald-kmsg.c +++ b/src/journal/journald-kmsg.c @@ -237,12 +237,12 @@ void dev_kmsg_record(Server *s, char *p, size_t l) { } j = 0; - FOREACH_DEVICE_DEVLINK(d, g) { + FOREACH_DEVICE_DEVLINK(d, link) { if (j >= N_IOVEC_UDEV_FIELDS) break; - b = strjoin("_UDEV_DEVLINK=", g); + b = strjoin("_UDEV_DEVLINK=", link); if (b) { iovec[n++] = IOVEC_MAKE_STRING(b); z++; diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index f3f59e2ac3f..e072d976d38 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -471,9 +471,7 @@ static bool match_property(sd_device_enumerator *enumerator, sd_device *device) if (hashmap_isempty(enumerator->match_property)) return true; - HASHMAP_FOREACH_KEY(value_patterns, property_pattern, enumerator->match_property) { - const char *property, *value; - + HASHMAP_FOREACH_KEY(value_patterns, property_pattern, enumerator->match_property) FOREACH_DEVICE_PROPERTY(device, property, value) { if (fnmatch(property_pattern, property, 0) != 0) continue; @@ -481,7 +479,6 @@ static bool match_property(sd_device_enumerator *enumerator, sd_device *device) if (strv_fnmatch(value_patterns, value)) return true; } - } return false; } diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index a23b5e78470..10d455888f6 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -681,8 +681,8 @@ int device_monitor_send_device( /* add tag bloom filter */ tag_bloom_bits = 0; - FOREACH_DEVICE_TAG(device, val) - tag_bloom_bits |= string_bloom64(val); + FOREACH_DEVICE_TAG(device, tag) + tag_bloom_bits |= string_bloom64(tag); if (tag_bloom_bits > 0) { nlh.filter_tag_bloom_hi = htobe32(tag_bloom_bits >> 32); diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 52cf9f2ab8c..0edabfbfbb4 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -525,7 +525,6 @@ int device_new_from_nulstr(sd_device **ret, char *nulstr, size_t len) { static int device_update_properties_bufs(sd_device *device) { _cleanup_free_ char **buf_strv = NULL, *buf_nulstr = NULL; size_t nulstr_len = 0, num = 0; - const char *val, *prop; assert(device); @@ -728,7 +727,6 @@ static int device_tag(sd_device *device, const char *tag, bool add) { } int device_tag_index(sd_device *device, sd_device *device_old, bool add) { - const char *tag; int r = 0, k; if (add && device_old) @@ -819,11 +817,9 @@ int device_update_db(sd_device *device) { } if (has_info) { - const char *property, *value, *tag; + const char *property, *value, *ct; if (major(device->devnum) > 0) { - const char *devlink; - FOREACH_DEVICE_DEVLINK(device, devlink) fprintf(f, "S:%s\n", devlink + STRLEN("/dev/")); @@ -840,8 +836,8 @@ int device_update_db(sd_device *device) { FOREACH_DEVICE_TAG(device, tag) fprintf(f, "G:%s\n", tag); /* Any tag */ - SET_FOREACH(tag, device->current_tags) - fprintf(f, "Q:%s\n", tag); /* Current tag */ + SET_FOREACH(ct, device->current_tags) + fprintf(f, "Q:%s\n", ct); /* Current tag */ /* Always write the latest database version here, instead of the value stored in * device->database_version, as which may be 0. */ diff --git a/src/libsystemd/sd-device/device-util.h b/src/libsystemd/sd-device/device-util.h index a1b5e91edf6..0316a600332 100644 --- a/src/libsystemd/sd-device/device-util.h +++ b/src/libsystemd/sd-device/device-util.h @@ -14,32 +14,32 @@ unref_and_replace_full(a, b, sd_device_ref, sd_device_unref) #define FOREACH_DEVICE_PROPERTY(device, key, value) \ - for (key = sd_device_get_property_first(device, &(value)); \ + for (const char *value, *key = sd_device_get_property_first(device, &(value)); \ key; \ key = sd_device_get_property_next(device, &(value))) #define FOREACH_DEVICE_TAG(device, tag) \ - for (tag = sd_device_get_tag_first(device); \ + for (const char *tag = sd_device_get_tag_first(device); \ tag; \ tag = sd_device_get_tag_next(device)) #define FOREACH_DEVICE_CURRENT_TAG(device, tag) \ - for (tag = sd_device_get_current_tag_first(device); \ + for (const char *tag = sd_device_get_current_tag_first(device); \ tag; \ tag = sd_device_get_current_tag_next(device)) #define FOREACH_DEVICE_SYSATTR(device, attr) \ - for (attr = sd_device_get_sysattr_first(device); \ + for (const char *attr = sd_device_get_sysattr_first(device); \ attr; \ attr = sd_device_get_sysattr_next(device)) #define FOREACH_DEVICE_DEVLINK(device, devlink) \ - for (devlink = sd_device_get_devlink_first(device); \ + for (const char *devlink = sd_device_get_devlink_first(device); \ devlink; \ devlink = sd_device_get_devlink_next(device)) #define _FOREACH_DEVICE_CHILD(device, child, suffix_ptr) \ - for (child = sd_device_get_child_first(device, suffix_ptr); \ + for (sd_device *child = sd_device_get_child_first(device, suffix_ptr); \ child; \ child = sd_device_get_child_next(device, suffix_ptr)) @@ -50,12 +50,12 @@ _FOREACH_DEVICE_CHILD(device, child, &suffix) #define FOREACH_DEVICE(enumerator, device) \ - for (device = sd_device_enumerator_get_device_first(enumerator); \ + for (sd_device *device = sd_device_enumerator_get_device_first(enumerator); \ device; \ device = sd_device_enumerator_get_device_next(enumerator)) #define FOREACH_SUBSYSTEM(enumerator, device) \ - for (device = sd_device_enumerator_get_subsystem_first(enumerator); \ + for (sd_device *device = sd_device_enumerator_get_subsystem_first(enumerator); \ device; \ device = sd_device_enumerator_get_subsystem_next(enumerator)) diff --git a/src/libsystemd/sd-device/test-sd-device-monitor.c b/src/libsystemd/sd-device/test-sd-device-monitor.c index 4654ef709d1..e124e0021c3 100644 --- a/src/libsystemd/sd-device/test-sd-device-monitor.c +++ b/src/libsystemd/sd-device/test-sd-device-monitor.c @@ -53,7 +53,7 @@ static void test_receive_device_fail(void) { static void test_send_receive_one(sd_device *device, bool subsystem_filter, bool tag_filter, bool use_bpf) { _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL; - const char *syspath, *subsystem, *tag, *devtype = NULL; + const char *syspath, *subsystem, *devtype = NULL; log_device_info(device, "/* %s(subsystem_filter=%s, tag_filter=%s, use_bpf=%s) */", __func__, true_false(subsystem_filter), true_false(tag_filter), true_false(use_bpf)); @@ -90,7 +90,6 @@ static void test_subsystem_filter(sd_device *device) { _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL; _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; const char *syspath, *subsystem; - sd_device *d; log_device_info(device, "/* %s */", __func__); @@ -131,7 +130,6 @@ static void test_tag_filter(sd_device *device) { _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL; _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; const char *syspath; - sd_device *d; log_device_info(device, "/* %s */", __func__); @@ -170,7 +168,6 @@ static void test_sysattr_filter(sd_device *device, const char *sysattr) { _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL; _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; const char *syspath, *sysattr_value; - sd_device *d; log_device_info(device, "/* %s(%s) */", __func__, sysattr); @@ -216,7 +213,7 @@ static void test_parent_filter(sd_device *device) { _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL; _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; const char *syspath, *parent_syspath; - sd_device *parent, *d; + sd_device *parent; int r; log_device_info(device, "/* %s */", __func__); diff --git a/src/libsystemd/sd-device/test-sd-device-thread.c b/src/libsystemd/sd-device/test-sd-device-thread.c index 644f3c2aeee..c99d179b335 100644 --- a/src/libsystemd/sd-device/test-sd-device-thread.c +++ b/src/libsystemd/sd-device/test-sd-device-thread.c @@ -27,7 +27,6 @@ static void* thread(void *p) { int main(int argc, char *argv[]) { sd_device *loopback; pthread_t t; - const char *key, *value; int r; r = sd_device_new_from_syspath(&loopback, "/sys/class/net/lo"); diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index fb3ae9f329c..43376a20360 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -194,7 +194,6 @@ static void test_sd_device_one(sd_device *d) { TEST(sd_device_enumerator_devices) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; assert_se(sd_device_enumerator_new(&e) >= 0); assert_se(sd_device_enumerator_allow_uninitialized(e) >= 0); @@ -211,7 +210,6 @@ TEST(sd_device_enumerator_devices) { TEST(sd_device_enumerator_subsystems) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; assert_se(sd_device_enumerator_new(&e) >= 0); assert_se(sd_device_enumerator_allow_uninitialized(e) >= 0); @@ -227,7 +225,7 @@ static void test_sd_device_enumerator_filter_subsystem_one( _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; unsigned n_new_dev = 0, n_removed_dev = 0; - sd_device *d; + sd_device *dev; assert_se(sd_device_enumerator_new(&e) >= 0); assert_se(sd_device_enumerator_add_match_subsystem(e, subsystem, true) >= 0); @@ -248,14 +246,14 @@ static void test_sd_device_enumerator_filter_subsystem_one( assert_se(!sd_device_unref(t)); } - HASHMAP_FOREACH(d, h) { + HASHMAP_FOREACH(dev, h) { const char *syspath; - assert_se(sd_device_get_syspath(d, &syspath) >= 0); + assert_se(sd_device_get_syspath(dev, &syspath) >= 0); log_warning("Device removed: subsystem:%s syspath:%s", subsystem, syspath); n_removed_dev++; - assert_se(!sd_device_unref(d)); + assert_se(!sd_device_unref(dev)); } hashmap_free(h); @@ -268,7 +266,6 @@ static bool test_sd_device_enumerator_filter_subsystem_trial(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_hashmap_free_ Hashmap *subsystems = NULL; unsigned n_new_dev = 0, n_removed_dev = 0; - sd_device *d; Hashmap *h; char *s; @@ -405,7 +402,6 @@ TEST(sd_device_enumerator_add_match_property) { static void check_parent_match(sd_device_enumerator *e, sd_device *dev) { const char *syspath; bool found = false; - sd_device *d; assert_se(sd_device_get_syspath(dev, &syspath) >= 0); @@ -429,7 +425,6 @@ static void check_parent_match(sd_device_enumerator *e, sd_device *dev) { TEST(sd_device_enumerator_add_match_parent) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *dev; int r; assert_se(sd_device_enumerator_new(&e) >= 0); @@ -475,7 +470,6 @@ TEST(sd_device_enumerator_add_match_parent) { TEST(sd_device_get_child) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *dev; int r; assert_se(sd_device_enumerator_new(&e) >= 0); @@ -490,7 +484,7 @@ TEST(sd_device_get_child) { FOREACH_DEVICE(e, dev) { const char *syspath, *parent_syspath, *expected_suffix, *suffix; - sd_device *parent, *child; + sd_device *parent; bool found = false; assert_se(sd_device_get_syspath(dev, &syspath) >= 0); @@ -580,7 +574,6 @@ TEST(sd_device_new_from_nulstr) { TEST(sd_device_new_from_path) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL; - sd_device *dev; int r; assert_se(mkdtemp_malloc("/tmp/test-sd-device.XXXXXXX", &tmpdir) >= 0); diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 8091ff1d618..7b9f54c976b 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -635,8 +635,6 @@ _public_ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev if (device_get_devlinks_generation(udev_device->device) != udev_device->devlinks_generation || !udev_device->devlinks_read) { - const char *devlink; - udev_list_cleanup(udev_device->devlinks); FOREACH_DEVICE_DEVLINK(udev_device->device, devlink) @@ -667,8 +665,6 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud if (device_get_properties_generation(udev_device->device) != udev_device->properties_generation || !udev_device->properties_read) { - const char *key, *value; - udev_list_cleanup(udev_device->properties); FOREACH_DEVICE_PROPERTY(udev_device->device, key, value) @@ -787,8 +783,6 @@ _public_ struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_ assert_return_errno(udev_device, NULL, EINVAL); if (!udev_device->sysattrs_read) { - const char *sysattr; - udev_list_cleanup(udev_device->sysattrs); FOREACH_DEVICE_SYSATTR(udev_device->device, sysattr) @@ -842,8 +836,6 @@ _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_dev if (device_get_tags_generation(udev_device->device) != udev_device->all_tags_generation || !udev_device->all_tags_read) { - const char *tag; - udev_list_cleanup(udev_device->all_tags); FOREACH_DEVICE_TAG(udev_device->device, tag) @@ -862,8 +854,6 @@ _public_ struct udev_list_entry *udev_device_get_current_tags_list_entry(struct if (device_get_tags_generation(udev_device->device) != udev_device->current_tags_generation || !udev_device->current_tags_read) { - const char *tag; - udev_list_cleanup(udev_device->current_tags); FOREACH_DEVICE_CURRENT_TAG(udev_device->device, tag) diff --git a/src/login/logind-core.c b/src/login/logind-core.c index df67e5509bb..af86e92c016 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -565,7 +565,6 @@ static bool manager_is_docked(Manager *m) { static int manager_count_external_displays(Manager *m) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; int r, n = 0; r = sd_device_enumerator_new(&e); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 0d4ab28b4d4..b3a36d0d058 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1296,7 +1296,7 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu return sd_bus_reply_method_return(message, NULL); } -static int trigger_device(Manager *m, sd_device *d) { +static int trigger_device(Manager *m, sd_device *parent) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; int r; @@ -1310,8 +1310,8 @@ static int trigger_device(Manager *m, sd_device *d) { if (r < 0) return r; - if (d) { - r = sd_device_enumerator_add_match_parent(e, d); + if (parent) { + r = sd_device_enumerator_add_match_parent(e, parent); if (r < 0) return r; } diff --git a/src/login/logind.c b/src/login/logind.c index 8323bcc0cb2..f30f7f93704 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -190,7 +190,6 @@ static Manager* manager_free(Manager *m) { static int manager_enumerate_devices(Manager *m) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; int r; assert(m); @@ -219,7 +218,6 @@ static int manager_enumerate_devices(Manager *m) { static int manager_enumerate_buttons(Manager *m) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; int r; assert(m); diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index dd07e16c725..89bf7fd80d2 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -779,7 +779,6 @@ static int find_mount_points(const char *what, char ***list) { static int find_loop_device(const char *backing_file, sd_device **ret) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *dev; int r; assert(backing_file); @@ -1366,7 +1365,6 @@ enum { static int list_devices(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_(table_unrefp) Table *table = NULL; - sd_device *d; unsigned c; int r; diff --git a/src/network/networkd-sriov.c b/src/network/networkd-sriov.c index 77ada236025..1f205b7468e 100644 --- a/src/network/networkd-sriov.c +++ b/src/network/networkd-sriov.c @@ -230,7 +230,7 @@ static int link_set_sr_iov_phys_port(Link *link) { static int link_set_sr_iov_virt_ports(Link *link) { const char *dev_port, *name; - sd_device *pci_dev, *child; + sd_device *pci_dev; int r; assert(link); diff --git a/src/shared/battery-util.c b/src/shared/battery-util.c index 43d72f9db75..71ee89a5498 100644 --- a/src/shared/battery-util.c +++ b/src/shared/battery-util.c @@ -12,7 +12,7 @@ static int device_is_power_sink(sd_device *device) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; bool found_source = false, found_sink = false; - sd_device *parent, *d; + sd_device *parent; int r; assert(device); @@ -109,7 +109,6 @@ static bool battery_is_discharging(sd_device *d) { int on_ac_power(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; bool found_ac_online = false, found_discharging_battery = false; - sd_device *d; int r; r = sd_device_enumerator_new(&e); @@ -234,7 +233,6 @@ int battery_read_capacity_percentage(sd_device *dev) { int battery_is_discharging_and_low(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; bool unsure = false, found_low = false; - sd_device *dev; int r; /* We have not used battery capacity_level since value is set to full diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index 3d03eedcf03..c6ccab081e3 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -107,7 +107,6 @@ int block_device_get_whole_disk(sd_device *dev, sd_device **ret) { static int block_device_get_originating(sd_device *dev, sd_device **ret) { _cleanup_(sd_device_unrefp) sd_device *first_found = NULL; const char *suffix; - sd_device *child; dev_t devnum = 0; /* avoid false maybe-uninitialized warning */ /* For the specified block device tries to chase it through the layers, in case LUKS-style DM @@ -665,7 +664,6 @@ int block_device_remove_all_partitions(sd_device *dev, int fd) { _cleanup_(sd_device_unrefp) sd_device *dev_unref = NULL; _cleanup_close_ int fd_close = -EBADF; bool has_partitions = false; - sd_device *part; int r, k = 0; assert(dev || fd >= 0); diff --git a/src/shared/devnode-acl.c b/src/shared/devnode-acl.c index 5911c2f84d6..92a2aff3dc2 100644 --- a/src/shared/devnode-acl.c +++ b/src/shared/devnode-acl.c @@ -143,7 +143,6 @@ int devnode_acl_all(const char *seat, _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_set_free_ Set *nodes = NULL; _cleanup_closedir_ DIR *dir = NULL; - sd_device *d; char *n; int r; diff --git a/src/shared/sleep-util.c b/src/shared/sleep-util.c index 1027ecce05c..d7277399fba 100644 --- a/src/shared/sleep-util.c +++ b/src/shared/sleep-util.c @@ -143,7 +143,6 @@ int get_capacity_by_name(Hashmap *capacities_by_name, const char *name) { int fetch_batteries_capacity_by_name(Hashmap **ret) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_hashmap_free_ Hashmap *batteries_capacity_by_name = NULL; - sd_device *dev; int r; assert(ret); @@ -334,7 +333,6 @@ int estimate_battery_discharge_rate_per_hour( usec_t after_timestamp) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *dev; bool trunc = true; int r; @@ -394,7 +392,6 @@ int estimate_battery_discharge_rate_per_hour( int get_total_suspend_interval(Hashmap *last_capacity, usec_t *ret) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; usec_t total_suspend_interval = 0; - sd_device *dev; int r; assert(last_capacity); @@ -450,7 +447,6 @@ int get_total_suspend_interval(Hashmap *last_capacity, usec_t *ret) { /* Return true if all batteries have acpi_btp support */ int battery_trip_point_alarm_exists(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *dev; int r; r = battery_enumerator_new(&e); diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 088eb0fe9ab..3e81234dc1f 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -165,8 +165,8 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, if (data->devlink) { const char *devlink; - FOREACH_DEVICE_DEVLINK(device, devlink) - if (path_equal(devlink, data->devlink)) + FOREACH_DEVICE_DEVLINK(device, link) + if (path_equal(link, data->devlink)) goto found; if (sd_device_get_devname(device, &devlink) >= 0 && path_equal(devlink, data->devlink)) diff --git a/src/shutdown/detach-dm.c b/src/shutdown/detach-dm.c index 71be74377d5..8b8f72d678b 100644 --- a/src/shutdown/detach-dm.c +++ b/src/shutdown/detach-dm.c @@ -42,7 +42,6 @@ static void device_mapper_list_free(DeviceMapper **head) { static int dm_list_get(DeviceMapper **head) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; int r; assert(head); diff --git a/src/shutdown/detach-loopback.c b/src/shutdown/detach-loopback.c index f45960856bc..267509f7d02 100644 --- a/src/shutdown/detach-loopback.c +++ b/src/shutdown/detach-loopback.c @@ -44,7 +44,6 @@ static void loopback_device_list_free(LoopbackDevice **head) { static int loopback_list_get(LoopbackDevice **head) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; int r; assert(head); diff --git a/src/shutdown/detach-md.c b/src/shutdown/detach-md.c index ae592f6f31d..2dbb866902d 100644 --- a/src/shutdown/detach-md.c +++ b/src/shutdown/detach-md.c @@ -44,7 +44,6 @@ static void raid_device_list_free(RaidDevice **head) { static int md_list_get(RaidDevice **head) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - sd_device *d; int r; assert(head); diff --git a/src/udev/udev-builtin-keyboard.c b/src/udev/udev-builtin-keyboard.c index da67c2be1c8..3903bc463f3 100644 --- a/src/udev/udev-builtin-keyboard.c +++ b/src/udev/udev-builtin-keyboard.c @@ -164,7 +164,7 @@ static int builtin_keyboard(UdevEvent *event, int argc, char *argv[], bool test) unsigned release[1024]; unsigned release_count = 0; _cleanup_close_ int fd = -EBADF; - const char *node, *key, *value; + const char *node; int has_abs = -1, r; r = sd_device_get_devname(dev, &node); diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 000839cac95..0028fb39f4f 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -110,7 +110,6 @@ static sd_device *skip_virtio(sd_device *dev) { static int get_virtfn_info(sd_device *pcidev, sd_device **ret_physfn_pcidev, char **ret_suffix) { _cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL; const char *syspath, *name; - sd_device *child; int r; assert(pcidev); @@ -619,7 +618,7 @@ static int names_platform(sd_device *dev, NetNames *names, bool test) { static int dev_devicetree_onboard(sd_device *dev, NetNames *names) { _cleanup_(sd_device_unrefp) sd_device *aliases_dev = NULL, *ofnode_dev = NULL, *devicetree_dev = NULL; - const char *alias, *ofnode_path, *ofnode_syspath, *devicetree_syspath; + const char *ofnode_path, *ofnode_syspath, *devicetree_syspath; sd_device *parent; int r; diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 296c0e344c1..31547b76794 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -411,11 +411,11 @@ static ssize_t udev_event_subst_format( } break; case FORMAT_SUBST_LINKS: - FOREACH_DEVICE_DEVLINK(dev, val) { + FOREACH_DEVICE_DEVLINK(dev, link) { if (s == dest) - strpcpy_full(&s, l, val + STRLEN("/dev/"), &truncated); + strpcpy_full(&s, l, link + STRLEN("/dev/"), &truncated); else - strpcpyl_full(&s, l, &truncated, " ", val + STRLEN("/dev/"), NULL); + strpcpyl_full(&s, l, &truncated, " ", link + STRLEN("/dev/"), NULL); if (truncated) break; } @@ -1107,7 +1107,6 @@ static int event_execute_rules_on_remove( } static int copy_all_tags(sd_device *d, sd_device *s) { - const char *tag; int r; assert(d); diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 1bc2eda7649..75845413cf0 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -531,7 +531,6 @@ static int device_get_devpath_by_devnum(sd_device *dev, char **ret) { int udev_node_update(sd_device *dev, sd_device *dev_old) { _cleanup_free_ char *filename = NULL; - const char *devlink; int r; assert(dev); @@ -577,7 +576,6 @@ int udev_node_update(sd_device *dev, sd_device *dev_old) { int udev_node_remove(sd_device *dev) { _cleanup_free_ char *filename = NULL; - const char *devlink; int r; assert(dev); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 265d328cd37..88846ae275a 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1780,7 +1780,6 @@ static int get_property_from_string(char *line, char **ret_key, char **ret_value } static int import_parent_into_properties(sd_device *dev, const char *filter) { - const char *key, *val; sd_device *parent; int r; @@ -1896,14 +1895,11 @@ static int udev_rule_apply_token_to_event( return token_match_string(token, val); } - case TK_M_DEVLINK: { - const char *val; - + case TK_M_DEVLINK: FOREACH_DEVICE_DEVLINK(dev, val) if (token_match_string(token, strempty(startswith(val, "/dev/"))) == (token->op == OP_MATCH)) return token->op == OP_MATCH; return token->op == OP_NOMATCH; - } case TK_M_NAME: return token_match_string(token, event->name); case TK_M_ENV: { @@ -1928,14 +1924,11 @@ static int udev_rule_apply_token_to_event( return token_match_string(token, val); } case TK_M_TAG: - case TK_M_PARENTS_TAG: { - const char *val; - + case TK_M_PARENTS_TAG: FOREACH_DEVICE_CURRENT_TAG(dev, val) if (token_match_string(token, val) == (token->op == OP_MATCH)) return token->op == OP_MATCH; return token->op == OP_NOMATCH; - } case TK_M_SUBSYSTEM: case TK_M_PARENTS_SUBSYSTEM: { const char *val; diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c index fccc967a47b..ae7251cbcc1 100644 --- a/src/udev/udevadm-info.c +++ b/src/udev/udevadm-info.c @@ -86,7 +86,7 @@ static int sysattr_compare(const SysAttr *a, const SysAttr *b) { static int print_all_attributes(sd_device *device, bool is_parent) { _cleanup_free_ SysAttr *sysattrs = NULL; - const char *name, *value; + const char *value; size_t n_items = 0; int r; @@ -180,7 +180,7 @@ static int print_device_chain(sd_device *device) { } static int print_record(sd_device *device, const char *prefix) { - const char *str, *val, *subsys; + const char *str, *subsys; dev_t devnum; uint64_t q; int i, ifi; @@ -232,14 +232,16 @@ static int print_record(sd_device *device, const char *prefix) { printf("%sI: %s%i%s\n", prefix, ansi_highlight_cyan(), ifi, ansi_normal()); if (sd_device_get_devname(device, &str) >= 0) { + const char *val; + assert_se(val = path_startswith(str, "/dev/")); printf("%sN: %s%s%s\n", prefix, ansi_highlight_cyan(), val, ansi_normal()); if (device_get_devlink_priority(device, &i) >= 0) printf("%sL: %s%i%s\n", prefix, ansi_highlight_cyan(), i, ansi_normal()); - FOREACH_DEVICE_DEVLINK(device, str) { - assert_se(val = path_startswith(str, "/dev/")); + FOREACH_DEVICE_DEVLINK(device, link) { + assert_se(val = path_startswith(link, "/dev/")); printf("%sS: %s%s%s\n", prefix, ansi_highlight_cyan(), val, ansi_normal()); } } @@ -250,8 +252,8 @@ static int print_record(sd_device *device, const char *prefix) { if (sd_device_get_driver(device, &str) >= 0) printf("%sV: %s%s%s\n", prefix, ansi_highlight_yellow4(), str, ansi_normal()); - FOREACH_DEVICE_PROPERTY(device, str, val) - printf("%sE: %s=%s\n", prefix, str, val); + FOREACH_DEVICE_PROPERTY(device, key, val) + printf("%sE: %s=%s\n", prefix, key, val); if (isempty(prefix)) puts(""); @@ -425,7 +427,7 @@ static int query_device(QueryType query, sd_device* device) { } case QUERY_SYMLINK: { - const char *devlink, *prefix = ""; + const char *prefix = ""; FOREACH_DEVICE_DEVLINK(device, devlink) { if (!arg_root) @@ -448,9 +450,7 @@ static int query_device(QueryType query, sd_device* device) { return 0; } - case QUERY_PROPERTY: { - const char *key, *value; - + case QUERY_PROPERTY: FOREACH_DEVICE_PROPERTY(device, key, value) { if (arg_properties && !strv_contains(arg_properties, key)) continue; @@ -464,7 +464,6 @@ static int query_device(QueryType query, sd_device* device) { } return 0; - } case QUERY_ALL: return print_record(device, NULL); diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index 99ad22a759e..dbe13a8d3b7 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -48,8 +48,6 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, devpath, subsystem); if (arg_show_property) { - const char *key, *value; - FOREACH_DEVICE_PROPERTY(device, key, value) printf("%s=%s\n", key, value); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index 8adebbc83e2..682ff567206 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -88,7 +88,7 @@ int test_main(int argc, char *argv[], void *userdata) { _cleanup_(udev_rules_freep) UdevRules *rules = NULL; _cleanup_(udev_event_freep) UdevEvent *event = NULL; _cleanup_(sd_device_unrefp) sd_device *dev = NULL; - const char *cmd, *key, *value; + const char *cmd; sigset_t mask, sigmask_orig; void *val; int r; diff --git a/src/udev/udevadm-wait.c b/src/udev/udevadm-wait.c index 0ec7099eb01..7fa9b862634 100644 --- a/src/udev/udevadm-wait.c +++ b/src/udev/udevadm-wait.c @@ -166,8 +166,8 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, if (path_strv_contains(arg_devices, name)) return check_and_exit(sd_device_monitor_get_event(monitor)); - FOREACH_DEVICE_DEVLINK(device, name) - if (path_strv_contains(arg_devices, name)) + FOREACH_DEVICE_DEVLINK(device, link) + if (path_strv_contains(arg_devices, link)) return check_and_exit(sd_device_monitor_get_event(monitor)); return 0; diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 8cf35973385..bd22dedf33a 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -1381,7 +1381,6 @@ static int synthesize_change(sd_device *dev) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; bool part_table_read; const char *sysname; - sd_device *d; int r, k; r = sd_device_get_sysname(dev, &sysname);