From: Zbigniew Jędrzejewski-Szmek Date: Tue, 3 Aug 2021 14:47:37 +0000 (+0200) Subject: udev/builtins: inline iterator variables and other small modernizations X-Git-Tag: v250-rc1~871^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d3d2e3abda33ef0fa88628f749c04dc77e878275;p=thirdparty%2Fsystemd.git udev/builtins: inline iterator variables and other small modernizations --- diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c index b1de363083c..cdb1df7c04d 100644 --- a/src/udev/udev-builtin-blkid.c +++ b/src/udev/udev-builtin-blkid.c @@ -116,8 +116,7 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) { _cleanup_free_ char *root_id = NULL, *root_label = NULL; bool found_esp = false; - blkid_partlist pl; - int i, nvals, r; + int r; assert(pr); @@ -126,12 +125,12 @@ static int find_gpt_root(sd_device *dev, blkid_probe pr, bool test) { * disk, and add a property indicating its partition UUID. */ errno = 0; - pl = blkid_probe_get_partitions(pr); + blkid_partlist pl = blkid_probe_get_partitions(pr); if (!pl) return errno_or_else(ENOMEM); - nvals = blkid_partlist_numof_partitions(pl); - for (i = 0; i < nvals; i++) { + int nvals = blkid_partlist_numof_partitions(pl); + for (int i = 0; i < nvals; i++) { blkid_partition pp; const char *stype, *sid, *label; sd_id128_t type; @@ -240,7 +239,7 @@ static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) { bool noraid = false, is_gpt = false; _cleanup_close_ int fd = -1; int64_t offset = 0; - int nvals, i, r; + int r; static const struct option options[] = { { "offset", required_argument, NULL, 'o' }, @@ -325,11 +324,11 @@ static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) { (void) sd_device_get_property_value(dev, "ID_PART_GPT_AUTO_ROOT_UUID", &root_partition); errno = 0; - nvals = blkid_probe_numof_values(pr); + int nvals = blkid_probe_numof_values(pr); if (nvals < 0) return log_device_debug_errno(dev, errno_or_else(ENOMEM), "Failed to get number of probed values: %m"); - for (i = 0; i < nvals; i++) { + for (int i = 0; i < nvals; i++) { if (blkid_probe_get_value(pr, i, &name, &data, NULL) < 0) continue; diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 6921cfba585..08a9e9c65d5 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -92,7 +92,7 @@ static void get_cap_mask(sd_device *pdev, const char* attr, memzero(bitmask, bitmask_size); i = 0; - while ((word = strrchr(text, ' ')) != NULL) { + while ((word = strrchr(text, ' '))) { r = safe_atolu_full(word+1, 16, &val); if (r < 0) log_device_debug_errno(pdev, r, "Ignoring %s block which failed to parse: %m", attr); @@ -101,7 +101,7 @@ static void get_cap_mask(sd_device *pdev, const char* attr, else log_device_debug(pdev, "Ignoring %s block %lX which is larger than maximum size", attr, val); *word = '\0'; - ++i; + i++; } r = safe_atolu_full(text, 16, &val); if (r < 0) @@ -120,9 +120,9 @@ static void get_cap_mask(sd_device *pdev, const char* attr, /* skip over leading zeros */ while (bitmask[val-1] == 0 && val > 0) --val; - for (i = 0; i < val; ++i) { + for (unsigned long j = 0; j < val; j++) { DISABLE_WARNING_FORMAT_NONLITERAL; - log_device_debug(pdev, text, i * BITS_PER_LONG, bitmask[i]); + log_device_debug(pdev, text, j * BITS_PER_LONG, bitmask[j]); REENABLE_WARNING; } } @@ -153,7 +153,6 @@ static bool test_pointers(sd_device *dev, const unsigned long* bitmask_rel, const unsigned long* bitmask_props, bool test) { - int button, axis; bool has_abs_coordinates = false; bool has_rel_coordinates = false; bool has_mt_coordinates = false; @@ -193,7 +192,7 @@ static bool test_pointers(sd_device *dev, has_stylus = test_bit(BTN_STYLUS, bitmask_key); has_pen = test_bit(BTN_TOOL_PEN, bitmask_key); finger_but_no_pen = test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key); - for (button = BTN_MOUSE; button < BTN_JOYSTICK && !has_mouse_button; button++) + for (int button = BTN_MOUSE; button < BTN_JOYSTICK && !has_mouse_button; button++) has_mouse_button = test_bit(button, bitmask_key); has_rel_coordinates = test_bit(EV_REL, bitmask_ev) && test_bit(REL_X, bitmask_rel) && test_bit(REL_Y, bitmask_rel); has_mt_coordinates = test_bit(ABS_MT_POSITION_X, bitmask_abs) && test_bit(ABS_MT_POSITION_Y, bitmask_abs); @@ -214,14 +213,14 @@ static bool test_pointers(sd_device *dev, * Catz Mad Catz M.M.O.TE). Skip those. */ if (!test_bit(BTN_JOYSTICK - 1, bitmask_key)) { - for (button = BTN_JOYSTICK; button < BTN_DIGI && !has_joystick_axes_or_buttons; button++) + for (int button = BTN_JOYSTICK; button < BTN_DIGI && !has_joystick_axes_or_buttons; button++) has_joystick_axes_or_buttons = test_bit(button, bitmask_key); - for (button = BTN_TRIGGER_HAPPY1; button <= BTN_TRIGGER_HAPPY40 && !has_joystick_axes_or_buttons; button++) + for (int button = BTN_TRIGGER_HAPPY1; button <= BTN_TRIGGER_HAPPY40 && !has_joystick_axes_or_buttons; button++) has_joystick_axes_or_buttons = test_bit(button, bitmask_key); - for (button = BTN_DPAD_UP; button <= BTN_DPAD_RIGHT && !has_joystick_axes_or_buttons; button++) + for (int button = BTN_DPAD_UP; button <= BTN_DPAD_RIGHT && !has_joystick_axes_or_buttons; button++) has_joystick_axes_or_buttons = test_bit(button, bitmask_key); } - for (axis = ABS_RX; axis < ABS_PRESSURE && !has_joystick_axes_or_buttons; axis++) + for (int axis = ABS_RX; axis < ABS_PRESSURE && !has_joystick_axes_or_buttons; axis++) has_joystick_axes_or_buttons = test_bit(axis, bitmask_abs); if (has_abs_coordinates) { diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c index 3be8bd56f46..0e31002b42e 100644 --- a/src/udev/udev-builtin-kmod.c +++ b/src/udev/udev-builtin-kmod.c @@ -21,16 +21,14 @@ _printf_(6,0) static void udev_kmod_log(void *data, int priority, const char *fi } static int builtin_kmod(sd_device *dev, int argc, char *argv[], bool test) { - int i; - if (!ctx) return 0; if (argc < 3 || !streq(argv[1], "load")) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "%s: expected: load ", argv[0]); + "%s: expected: load …", argv[0]); - for (i = 2; argv[i]; i++) + for (int i = 2; argv[i]; i++) (void) module_load_and_warn(ctx, argv[i], false); return 0; diff --git a/src/udev/udev-builtin-path_id.c b/src/udev/udev-builtin-path_id.c index 65c40de4c8c..effc36f36a6 100644 --- a/src/udev/udev-builtin-path_id.c +++ b/src/udev/udev-builtin-path_id.c @@ -378,7 +378,6 @@ static sd_device *handle_scsi_hyperv(sd_device *parent, char **path, size_t guid const char *guid_str; _cleanup_free_ char *lun = NULL; char guid[39]; - size_t i, k; assert(parent); assert(path); @@ -396,7 +395,8 @@ static sd_device *handle_scsi_hyperv(sd_device *parent, char **path, size_t guid if (strlen(guid_str) < guid_str_len || guid_str[0] != '{' || guid_str[guid_str_len-1] != '}') return NULL; - for (i = 1, k = 0; i < guid_str_len-1; i++) { + size_t k = 0; + for (size_t i = 1; i < guid_str_len-1; i++) { if (guid_str[i] == '-') continue; guid[k++] = guid_str[i]; @@ -681,11 +681,10 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) { { char tag[UDEV_NAME_SIZE]; - size_t i; - const char *p; + size_t i = 0; /* compose valid udev tag name */ - for (p = path, i = 0; *p; p++) { + for (const char *p = path; *p; p++) { if ((*p >= '0' && *p <= '9') || (*p >= 'A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z') || diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c index bdaecb812b0..746fb40e645 100644 --- a/src/udev/udev-builtin-usb_id.c +++ b/src/udev/udev-builtin-usb_id.c @@ -405,10 +405,8 @@ fallback: const char *usb_serial; if (sd_device_get_sysattr_value(dev_usb, "serial", &usb_serial) >= 0) { - const unsigned char *p; - /* http://msdn.microsoft.com/en-us/library/windows/hardware/gg487321.aspx */ - for (p = (unsigned char *) usb_serial; *p != '\0'; p++) + for (const unsigned char *p = (unsigned char*) usb_serial; *p != '\0'; p++) if (*p < 0x20 || *p > 0x7f || *p == ',') { usb_serial = NULL; break;