Skip to content

Commit 2fea609

Browse files
committed
sd-netlink: use structured initializers
1 parent f6bdbd9 commit 2fea609

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/libsystemd/sd-netlink/sd-netlink.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,30 @@ static int sd_netlink_new(sd_netlink **ret) {
2121

2222
assert_return(ret, -EINVAL);
2323

24-
rtnl = new0(sd_netlink, 1);
24+
rtnl = new(sd_netlink, 1);
2525
if (!rtnl)
2626
return -ENOMEM;
2727

28-
rtnl->n_ref = REFCNT_INIT;
29-
rtnl->fd = -1;
30-
rtnl->sockaddr.nl.nl_family = AF_NETLINK;
31-
rtnl->original_pid = getpid_cached();
32-
rtnl->protocol = -1;
28+
*rtnl = (sd_netlink) {
29+
.n_ref = REFCNT_INIT,
30+
.fd = -1,
31+
.sockaddr.nl.nl_family = AF_NETLINK,
32+
.original_pid = getpid_cached(),
33+
.protocol = -1,
3334

34-
LIST_HEAD_INIT(rtnl->match_callbacks);
35+
/* Change notification responses have sequence 0, so we must
36+
* start our request sequence numbers at 1, or we may confuse our
37+
* responses with notifications from the kernel */
38+
.serial = 1,
39+
40+
};
3541

3642
/* We guarantee that the read buffer has at least space for
3743
* a message header */
3844
if (!greedy_realloc((void**)&rtnl->rbuffer, &rtnl->rbuffer_allocated,
3945
sizeof(struct nlmsghdr), sizeof(uint8_t)))
4046
return -ENOMEM;
4147

42-
/* Change notification responses have sequence 0, so we must
43-
* start our request sequence numbers at 1, or we may confuse our
44-
* responses with notifications from the kernel */
45-
rtnl->serial = 1;
46-
4748
*ret = TAKE_PTR(rtnl);
4849

4950
return 0;
@@ -827,13 +828,15 @@ int sd_netlink_add_match(sd_netlink *rtnl,
827828
assert_return(callback, -EINVAL);
828829
assert_return(!rtnl_pid_changed(rtnl), -ECHILD);
829830

830-
c = new0(struct match_callback, 1);
831+
c = new(struct match_callback, 1);
831832
if (!c)
832833
return -ENOMEM;
833834

834-
c->callback = callback;
835-
c->type = type;
836-
c->userdata = userdata;
835+
*c = (struct match_callback) {
836+
.callback = callback,
837+
.type = type,
838+
.userdata = userdata,
839+
};
837840

838841
switch (type) {
839842
case RTM_NEWLINK:

0 commit comments

Comments
 (0)