network: tighten variable scope used in loop (#18277)
This commit is contained in:
@@ -580,8 +580,7 @@ static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, Lin
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
|
||||
_cleanup_(link_info_array_freep) LinkInfo *links = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
size_t allocated = 0, c = 0, j;
|
||||
sd_netlink_message *i;
|
||||
size_t allocated = 0, c = 0;
|
||||
int r;
|
||||
|
||||
assert(rtnl);
|
||||
@@ -606,7 +605,7 @@ static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, Lin
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
for (i = reply; i; i = sd_netlink_message_next(i)) {
|
||||
for (sd_netlink_message *i = reply; i; i = sd_netlink_message_next(i)) {
|
||||
if (!GREEDY_REALLOC0(links, allocated, c + 2)) /* We keep one trailing one as marker */
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -645,7 +644,7 @@ static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, Lin
|
||||
typesafe_qsort(links, c, link_info_compare);
|
||||
|
||||
if (bus)
|
||||
for (j = 0; j < c; j++)
|
||||
for (size_t j = 0; j < c; j++)
|
||||
(void) acquire_link_bitrates(bus, links + j);
|
||||
|
||||
*ret = TAKE_PTR(links);
|
||||
@@ -891,7 +890,7 @@ static int dump_gateways(
|
||||
int ifindex) {
|
||||
_cleanup_free_ struct local_address *local = NULL;
|
||||
_cleanup_strv_free_ char **buf = NULL;
|
||||
int r, n, i;
|
||||
int r, n;
|
||||
|
||||
assert(rtnl);
|
||||
assert(table);
|
||||
@@ -900,7 +899,7 @@ static int dump_gateways(
|
||||
if (n <= 0)
|
||||
return n;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
_cleanup_free_ char *gateway = NULL, *description = NULL, *with_description = NULL;
|
||||
char name[IF_NAMESIZE+1];
|
||||
|
||||
|
||||
@@ -135,7 +135,6 @@ static bool address_pool_prefix_is_taken(
|
||||
|
||||
static int address_pool_acquire_one(AddressPool *p, int family, unsigned prefixlen, union in_addr_union *found) {
|
||||
union in_addr_union u;
|
||||
unsigned i;
|
||||
int r;
|
||||
|
||||
assert(p);
|
||||
@@ -150,7 +149,7 @@ static int address_pool_acquire_one(AddressPool *p, int family, unsigned prefixl
|
||||
|
||||
u = p->in_addr;
|
||||
|
||||
for (i = 0; i < RANDOM_PREFIX_TRIAL_MAX; i++) {
|
||||
for (unsigned i = 0; i < RANDOM_PREFIX_TRIAL_MAX; i++) {
|
||||
r = in_addr_random_prefix(p->family, &u, p->prefixlen, prefixlen);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
@@ -599,7 +599,6 @@ bool link_address_is_dynamic(const Link *link, const Address *address) {
|
||||
|
||||
static int link_enumerate_ipv6_tentative_addresses(Link *link) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
|
||||
sd_netlink_message *addr;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@@ -614,7 +613,7 @@ static int link_enumerate_ipv6_tentative_addresses(Link *link) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
for (addr = reply; addr; addr = sd_netlink_message_next(addr)) {
|
||||
for (sd_netlink_message *addr = reply; addr; addr = sd_netlink_message_next(addr)) {
|
||||
unsigned char flags;
|
||||
int ifindex;
|
||||
|
||||
|
||||
@@ -44,9 +44,9 @@ static int find_next_bit(int i, uint32_t x) {
|
||||
|
||||
static int append_vlan_info_data(Link *const link, sd_netlink_message *req, uint16_t pvid, const uint32_t *br_vid_bitmap, const uint32_t *br_untagged_bitmap) {
|
||||
struct bridge_vlan_info br_vlan;
|
||||
int i, j, k, r, cnt;
|
||||
uint16_t begin, end;
|
||||
bool done, untagged = false;
|
||||
uint16_t begin, end;
|
||||
int r, cnt;
|
||||
|
||||
assert(link);
|
||||
assert(req);
|
||||
@@ -56,16 +56,17 @@ static int append_vlan_info_data(Link *const link, sd_netlink_message *req, uint
|
||||
cnt = 0;
|
||||
|
||||
begin = end = UINT16_MAX;
|
||||
for (k = 0; k < BRIDGE_VLAN_BITMAP_LEN; k++) {
|
||||
unsigned base_bit;
|
||||
uint32_t vid_map = br_vid_bitmap[k];
|
||||
for (int k = 0; k < BRIDGE_VLAN_BITMAP_LEN; k++) {
|
||||
uint32_t untagged_map = br_untagged_bitmap[k];
|
||||
uint32_t vid_map = br_vid_bitmap[k];
|
||||
unsigned base_bit;
|
||||
int i;
|
||||
|
||||
base_bit = k * 32;
|
||||
i = -1;
|
||||
done = false;
|
||||
do {
|
||||
j = find_next_bit(i, vid_map);
|
||||
int j = find_next_bit(i, vid_map);
|
||||
if (j > 0) {
|
||||
/* first hit of any bit */
|
||||
if (begin == UINT16_MAX && end == UINT16_MAX) {
|
||||
|
||||
@@ -809,7 +809,6 @@ int config_parse_dhcp_request_options(
|
||||
void *userdata) {
|
||||
|
||||
Network *network = data;
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
@@ -826,7 +825,7 @@ int config_parse_dhcp_request_options(
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (p = rvalue;;) {
|
||||
for (const char *p = rvalue;;) {
|
||||
_cleanup_free_ char *n = NULL;
|
||||
uint32_t i;
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ static int dhcp_route_configure(Route *route, Link *link) {
|
||||
static int link_set_dns_routes(Link *link, const struct in_addr *address) {
|
||||
const struct in_addr *dns;
|
||||
uint32_t table;
|
||||
int i, n, r;
|
||||
int n, r;
|
||||
|
||||
assert(link);
|
||||
assert(link->dhcp_lease);
|
||||
@@ -181,7 +181,7 @@ static int link_set_dns_routes(Link *link, const struct in_addr *address) {
|
||||
|
||||
table = link_get_dhcp_route_table(link);
|
||||
|
||||
for (i = 0; i < n; i ++) {
|
||||
for (int i = 0; i < n; i ++) {
|
||||
_cleanup_(route_freep) Route *route = NULL;
|
||||
|
||||
r = route_new(&route);
|
||||
|
||||
@@ -44,7 +44,6 @@ static int process_message(Manager *manager, sd_netlink_message *message) {
|
||||
static int speed_meter_handler(sd_event_source *s, uint64_t usec, void *userdata) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
|
||||
Manager *manager = userdata;
|
||||
sd_netlink_message *i;
|
||||
usec_t usec_now;
|
||||
Link *link;
|
||||
int r;
|
||||
@@ -84,7 +83,7 @@ static int speed_meter_handler(sd_event_source *s, uint64_t usec, void *userdata
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = reply; i; i = sd_netlink_message_next(i))
|
||||
for (sd_netlink_message *i = reply; i; i = sd_netlink_message_next(i))
|
||||
(void) process_message(manager, i);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -67,12 +67,11 @@ static void test_config_parse_hwaddr_one(const char *rvalue, int ret, const stru
|
||||
|
||||
static void test_config_parse_hwaddrs_one(const char *rvalue, const struct ether_addr* list, size_t n) {
|
||||
_cleanup_set_free_free_ Set *s = NULL;
|
||||
size_t m;
|
||||
|
||||
assert_se(config_parse_hwaddrs("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &s, NULL) == 0);
|
||||
assert_se(set_size(s) == n);
|
||||
|
||||
for (m = 0; m < n; m++) {
|
||||
for (size_t m = 0; m < n; m++) {
|
||||
_cleanup_free_ struct ether_addr *q = NULL;
|
||||
|
||||
assert_se(q = set_remove(s, &list[m]));
|
||||
|
||||
@@ -207,7 +207,6 @@ static int on_rtnl_event(sd_netlink *rtnl, sd_netlink_message *mm, void *userdat
|
||||
|
||||
static int manager_rtnl_listen(Manager *m) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
|
||||
sd_netlink_message *i;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
@@ -242,7 +241,7 @@ static int manager_rtnl_listen(Manager *m) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
for (i = reply; i; i = sd_netlink_message_next(i)) {
|
||||
for (sd_netlink_message *i = reply; i; i = sd_netlink_message_next(i)) {
|
||||
r = manager_process_link(m->rtnl, i, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
Reference in New Issue
Block a user