From: Ben Pfaff Date: Mon, 28 Sep 2009 20:56:42 +0000 (-0700) Subject: Add new function xzalloc(n) as a shorthand for xcalloc(1, n). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec6fde61c85ff6a57b05d422a9d8b5ef679ad928;p=openvswitch Add new function xzalloc(n) as a shorthand for xcalloc(1, n). --- diff --git a/SubmittingPatches b/SubmittingPatches index 917cddbf..280f11ef 100644 --- a/SubmittingPatches +++ b/SubmittingPatches @@ -193,7 +193,7 @@ index 32647ea..00cffbc 100644 /* Get rid of deleted bridges and add new bridges. */ svec_sort(&old_br); @@ -793,7 +780,7 @@ bridge_create(const char *name) - br = xcalloc(1, sizeof *br); + br = xzalloc(sizeof *br); error = dpif_create(name, &br->dpif); - if (error == EEXIST) { diff --git a/extras/ezio/ovs-switchui.c b/extras/ezio/ovs-switchui.c index 0f6640e0..e56f83e0 100644 --- a/extras/ezio/ovs-switchui.c +++ b/extras/ezio/ovs-switchui.c @@ -1247,7 +1247,7 @@ allocate_message(struct message **msgp) { if (!*msgp) { /* Allocate and initialize message. */ - *msgp = xcalloc(1, sizeof **msgp); + *msgp = xzalloc(sizeof **msgp); (*msgp)->index = n_messages; /* Add to list of messages. */ diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index 4f907813..720cd2fa 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -172,7 +172,7 @@ dhclient_create(const char *netdev_name, return error; } - cli = xcalloc(1, sizeof *cli); + cli = xzalloc(sizeof *cli); cli->modify_request = modify_request; cli->validate_offer = validate_offer; cli->aux = aux; diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4c25f139..8bd9648d 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -219,7 +219,7 @@ create_dp_netdev(const char *name, int dp_idx, struct dpif **dpifp) } /* Create datapath. */ - dp_netdevs[dp_idx] = dp = xcalloc(1, sizeof *dp); + dp_netdevs[dp_idx] = dp = xzalloc(sizeof *dp); list_push_back(&dp_netdev_list, &dp->node); dp->dp_idx = dp_idx; dp->open_cnt = 0; @@ -788,7 +788,7 @@ add_flow(struct dpif *dpif, struct odp_flow *odp_flow) struct dp_netdev_flow *flow; int error; - flow = xcalloc(1, sizeof *flow); + flow = xzalloc(sizeof *flow); flow->key = odp_flow->key; flow->key.reserved = 0; diff --git a/lib/learning-switch.c b/lib/learning-switch.c index 73464c68..99d5ee4c 100644 --- a/lib/learning-switch.c +++ b/lib/learning-switch.c @@ -110,7 +110,7 @@ lswitch_create(struct rconn *rconn, bool learn_macs, int max_idle) struct lswitch *sw; size_t i; - sw = xcalloc(1, sizeof *sw); + sw = xzalloc(sizeof *sw); sw->max_idle = max_idle; sw->datapath_id = 0; sw->last_features_request = time_now() - 1; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 73247030..c33405fd 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -203,7 +203,7 @@ netdev_linux_open(const char *name, char *suffix, int ethertype, int error; /* Allocate network device. */ - netdev = xcalloc(1, sizeof *netdev); + netdev = xzalloc(sizeof *netdev); netdev_init(&netdev->netdev, suffix, &netdev_linux_class); netdev->netdev_fd = -1; netdev->tap_fd = -1; diff --git a/lib/poll-loop.c b/lib/poll-loop.c index aff2c335..26a17e83 100644 --- a/lib/poll-loop.c +++ b/lib/poll-loop.c @@ -253,7 +253,7 @@ poll_cancel(struct poll_waiter *pw) static struct poll_waiter * new_waiter(int fd, short int events) { - struct poll_waiter *waiter = xcalloc(1, sizeof *waiter); + struct poll_waiter *waiter = xzalloc(sizeof *waiter); assert(fd >= 0); waiter->fd = fd; waiter->events = events; diff --git a/lib/process.c b/lib/process.c index 1fe3c123..0c7f424f 100644 --- a/lib/process.c +++ b/lib/process.c @@ -161,7 +161,7 @@ process_register(const char *name, pid_t pid) assert(sigchld_is_blocked()); - p = xcalloc(1, sizeof *p); + p = xzalloc(sizeof *p); p->pid = pid; slash = strrchr(name, '/'); p->name = xstrdup(slash ? slash + 1 : name); diff --git a/lib/rconn.c b/lib/rconn.c index 2cbe43e9..b6e958ee 100644 --- a/lib/rconn.c +++ b/lib/rconn.c @@ -176,7 +176,7 @@ rconn_new_from_vconn(const char *name, struct vconn *vconn) struct rconn * rconn_create(int probe_interval, int max_backoff) { - struct rconn *rc = xcalloc(1, sizeof *rc); + struct rconn *rc = xzalloc(sizeof *rc); rc->state = S_VOID; rc->state_entered = time_now(); diff --git a/lib/stp.c b/lib/stp.c index 87230bd9..cf1b2f98 100644 --- a/lib/stp.c +++ b/lib/stp.c @@ -214,7 +214,7 @@ stp_create(const char *name, stp_identifier bridge_id, struct stp *stp; struct stp_port *p; - stp = xcalloc(1, sizeof *stp); + stp = xzalloc(sizeof *stp); stp->name = xstrdup(name); stp->bridge_id = bridge_id; if (!(stp->bridge_id >> 48)) { diff --git a/lib/util.c b/lib/util.c index f766d59e..cecd5825 100644 --- a/lib/util.c +++ b/lib/util.c @@ -42,6 +42,12 @@ xcalloc(size_t count, size_t size) return p; } +void * +xzalloc(size_t size) +{ + return xcalloc(1, size); +} + void * xmalloc(size_t size) { diff --git a/lib/util.h b/lib/util.h index 962bad2f..1290d33e 100644 --- a/lib/util.h +++ b/lib/util.h @@ -98,6 +98,7 @@ void ovs_print_version(char *date, char *time, void out_of_memory(void) NO_RETURN; void *xmalloc(size_t) MALLOC_LIKE; void *xcalloc(size_t, size_t) MALLOC_LIKE; +void *xzalloc(size_t) MALLOC_LIKE; void *xrealloc(void *, size_t); void *xmemdup(const void *, size_t) MALLOC_LIKE; char *xmemdup0(const char *, size_t) MALLOC_LIKE; diff --git a/ofproto/discovery.c b/ofproto/discovery.c index 2868db5a..c7625066 100644 --- a/ofproto/discovery.c +++ b/ofproto/discovery.c @@ -102,7 +102,7 @@ discovery_create(const char *re, bool update_resolv_conf, char local_name[IF_NAMESIZE]; int error; - d = xcalloc(1, sizeof *d); + d = xzalloc(sizeof *d); /* Controller regular expression. */ error = discovery_set_accept_controller_re(d, re); diff --git a/ofproto/executer.c b/ofproto/executer.c index bc42ccf8..cdbe5bd9 100644 --- a/ofproto/executer.c +++ b/ofproto/executer.c @@ -471,7 +471,7 @@ executer_create(const char *command_acl, const char *command_dir, return errno; } - e = xcalloc(1, sizeof *e); + e = xzalloc(sizeof *e); e->command_acl = xstrdup(command_acl); e->command_dir = (command_dir ? xstrdup(command_dir) diff --git a/ofproto/in-band.c b/ofproto/in-band.c index 2b362bc0..4a2ea834 100644 --- a/ofproto/in-band.c +++ b/ofproto/in-band.c @@ -624,7 +624,7 @@ in_band_create(struct ofproto *ofproto, struct dpif *dpif, return error; } - in_band = xcalloc(1, sizeof *in_band); + in_band = xzalloc(sizeof *in_band); in_band->ofproto = ofproto; in_band->controller = controller; in_band->ss_cat = switch_status_register(ss, "in-band", diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index eb8a7a91..c618e3c7 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -292,7 +292,7 @@ ofproto_create(const char *datapath, const struct ofhooks *ofhooks, void *aux, dpif_recv_purge(dpif); /* Initialize settings. */ - p = xcalloc(1, sizeof *p); + p = xzalloc(sizeof *p); p->fallback_dpid = pick_fallback_dpid(); p->datapath_id = p->fallback_dpid; p->manufacturer = xstrdup("Nicira Networks, Inc."); @@ -1389,7 +1389,7 @@ rule_create(struct rule *super, const union ofp_action *actions, size_t n_actions, uint16_t idle_timeout, uint16_t hard_timeout) { - struct rule *rule = xcalloc(1, sizeof *rule); + struct rule *rule = xzalloc(sizeof *rule); rule->idle_timeout = idle_timeout; rule->hard_timeout = hard_timeout; rule->used = rule->created = time_msec(); @@ -2427,7 +2427,7 @@ query_stats(struct ofproto *p, struct rule *rule, byte_count = rule->byte_count; n_odp_flows = rule->cr.wc.wildcards ? list_size(&rule->list) : 1; - odp_flows = xcalloc(1, n_odp_flows * sizeof *odp_flows); + odp_flows = xzalloc(n_odp_flows * sizeof *odp_flows); if (rule->cr.wc.wildcards) { size_t i = 0; LIST_FOR_EACH (subrule, struct rule, list, &rule->list) { diff --git a/ofproto/pinsched.c b/ofproto/pinsched.c index 0afd22ff..a4f5bfad 100644 --- a/ofproto/pinsched.c +++ b/ofproto/pinsched.c @@ -227,7 +227,7 @@ pinsched_create(int rate_limit, int burst_limit, struct switch_status *ss) { struct pinsched *ps; - ps = xcalloc(1, sizeof *ps); + ps = xzalloc(sizeof *ps); port_array_init(&ps->queues); ps->n_queued = 0; ps->last_tx_port = PORT_ARRAY_SIZE; diff --git a/ofproto/pktbuf.c b/ofproto/pktbuf.c index 450cc3b6..3701aebd 100644 --- a/ofproto/pktbuf.c +++ b/ofproto/pktbuf.c @@ -63,7 +63,7 @@ pktbuf_capacity(void) struct pktbuf * pktbuf_create(void) { - return xcalloc(1, sizeof *pktbuf_create()); + return xzalloc(sizeof *pktbuf_create()); } void diff --git a/ofproto/status.c b/ofproto/status.c index b2cb9356..5e618882 100644 --- a/ofproto/status.c +++ b/ofproto/status.c @@ -177,7 +177,7 @@ switch_status_cb(struct status_reply *sr, void *ss_) struct switch_status * switch_status_create(const struct ofproto *ofproto) { - struct switch_status *ss = xcalloc(1, sizeof *ss); + struct switch_status *ss = xzalloc(sizeof *ss); ss->booted = time_now(); list_init(&ss->categories); ss->config_cat = switch_status_register(ss, "config", config_status_cb, diff --git a/tests/test-classifier.c b/tests/test-classifier.c index 0307e48f..d36c8eb1 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -446,7 +446,7 @@ make_rule(int wc_fields, unsigned int priority, int value_pat) } } - rule = xcalloc(1, sizeof *rule); + rule = xzalloc(sizeof *rule); cls_rule_from_flow(&rule->cls_rule, &flow, wildcards, !wildcards ? UINT_MAX : priority); return rule; diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index b0db9ab0..b1e4e165 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -964,7 +964,7 @@ bridge_create(const char *name) int error; assert(!bridge_lookup(name)); - br = xcalloc(1, sizeof *br); + br = xzalloc(sizeof *br); error = dpif_create(name, &br->dpif); if (error == EEXIST || error == EBUSY) { @@ -2838,7 +2838,7 @@ port_create(struct bridge *br, const char *name) { struct port *port; - port = xcalloc(1, sizeof *port); + port = xzalloc(sizeof *port); port->bridge = br; port->port_idx = br->n_ports; port->vlan = -1; @@ -3191,7 +3191,7 @@ iface_create(struct port *port, const char *name) { struct iface *iface; - iface = xcalloc(1, sizeof *iface); + iface = xzalloc(sizeof *iface); iface->port = port; iface->port_ifidx = port->n_ifaces; iface->name = xstrdup(name); @@ -3398,7 +3398,7 @@ mirror_create(struct bridge *br, const char *name) VLOG_INFO("created port mirror %s on bridge %s", name, br->name); bridge_flush(br); - br->mirrors[i] = m = xcalloc(1, sizeof *m); + br->mirrors[i] = m = xzalloc(sizeof *m); m->bridge = br; m->idx = i; m->name = xstrdup(name); diff --git a/vswitchd/proc-net-compat.c b/vswitchd/proc-net-compat.c index 7a595265..68ae1ac8 100644 --- a/vswitchd/proc-net-compat.c +++ b/vswitchd/proc-net-compat.c @@ -256,7 +256,7 @@ proc_net_compat_update_vlan(const char *tagged_dev, const char *trunk_dev, } if (!vlan) { /* Create a new compat_vlan for (trunk_dev,vid). */ - vlan = xcalloc(1, sizeof *vlan); + vlan = xzalloc(sizeof *vlan); vlan->trunk_dev = xstrdup(trunk_dev); vlan->vid = vid; vlan->vlan_dev = xasprintf("%s.%d", trunk_dev, vid);