* [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc()
@ 2014-12-04 13:28 Markus Armbruster
2014-12-04 13:28 ` [Qemu-devel] [PATCH 1/2] net: Fuse g_malloc(); memset() into g_new0() Markus Armbruster
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Markus Armbruster @ 2014-12-04 13:28 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha
Markus Armbruster (2):
net: Fuse g_malloc(); memset() into g_new0()
net: Use g_new() & friends where that makes obvious sense
net/l2tpv3.c | 9 ++++-----
net/queue.c | 2 +-
net/slirp.c | 2 +-
3 files changed, 6 insertions(+), 7 deletions(-)
--
1.9.3
^ permalink raw reply [flat|nested] 5+ messages in thread* [Qemu-devel] [PATCH 1/2] net: Fuse g_malloc(); memset() into g_new0() 2014-12-04 13:28 [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Markus Armbruster @ 2014-12-04 13:28 ` Markus Armbruster 2014-12-04 13:28 ` [Qemu-devel] [PATCH 2/2] net: Use g_new() & friends where that makes obvious sense Markus Armbruster ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: Markus Armbruster @ 2014-12-04 13:28 UTC (permalink / raw) To: qemu-devel; +Cc: stefanha Signed-off-by: Markus Armbruster <armbru@redhat.com> --- net/l2tpv3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 3b805a7..6014c43 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -695,8 +695,7 @@ int net_init_l2tpv3(const NetClientOptions *opts, goto outerr; } - s->dgram_dst = g_malloc(sizeof(struct sockaddr_storage)); - memset(s->dgram_dst, '\0' , sizeof(struct sockaddr_storage)); + s->dgram_dst = g_new0(struct sockaddr_storage, 1); memcpy(s->dgram_dst, result->ai_addr, result->ai_addrlen); s->dst_size = result->ai_addrlen; -- 1.9.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] net: Use g_new() & friends where that makes obvious sense 2014-12-04 13:28 [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Markus Armbruster 2014-12-04 13:28 ` [Qemu-devel] [PATCH 1/2] net: Fuse g_malloc(); memset() into g_new0() Markus Armbruster @ 2014-12-04 13:28 ` Markus Armbruster 2014-12-05 15:08 ` [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Eric Blake 2014-12-19 13:15 ` Stefan Hajnoczi 3 siblings, 0 replies; 5+ messages in thread From: Markus Armbruster @ 2014-12-04 13:28 UTC (permalink / raw) To: qemu-devel; +Cc: stefanha g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, for two reasons. One, it catches multiplication overflowing size_t. Two, it returns T * rather than void *, which lets the compiler catch more type errors. This commit only touches allocations with size arguments of the form sizeof(T). Signed-off-by: Markus Armbruster <armbru@redhat.com> --- net/l2tpv3.c | 6 +++--- net/queue.c | 2 +- net/slirp.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/net/l2tpv3.c b/net/l2tpv3.c index 6014c43..8c598b0 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -489,12 +489,12 @@ static struct mmsghdr *build_l2tpv3_vector(NetL2TPV3State *s, int count) struct iovec *iov; struct mmsghdr *msgvec, *result; - msgvec = g_malloc(sizeof(struct mmsghdr) * count); + msgvec = g_new(struct mmsghdr, count); result = msgvec; for (i = 0; i < count ; i++) { msgvec->msg_hdr.msg_name = NULL; msgvec->msg_hdr.msg_namelen = 0; - iov = g_malloc(sizeof(struct iovec) * IOVSIZE); + iov = g_new(struct iovec, IOVSIZE); msgvec->msg_hdr.msg_iov = iov; iov->iov_base = g_malloc(s->header_size); iov->iov_len = s->header_size; @@ -729,7 +729,7 @@ int net_init_l2tpv3(const NetClientOptions *opts, } s->msgvec = build_l2tpv3_vector(s, MAX_L2TPV3_MSGCNT); - s->vec = g_malloc(sizeof(struct iovec) * MAX_L2TPV3_IOVCNT); + s->vec = g_new(struct iovec, MAX_L2TPV3_IOVCNT); s->header_buf = g_malloc(s->header_size); qemu_set_nonblock(fd); diff --git a/net/queue.c b/net/queue.c index f948318..ebbe2bb 100644 --- a/net/queue.c +++ b/net/queue.c @@ -62,7 +62,7 @@ NetQueue *qemu_new_net_queue(void *opaque) { NetQueue *queue; - queue = g_malloc0(sizeof(NetQueue)); + queue = g_new0(NetQueue, 1); queue->opaque = opaque; queue->nq_maxlen = 10000; diff --git a/net/slirp.c b/net/slirp.c index 377d7ef..0cbca3c 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -652,7 +652,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str, return -1; } } else { - fwd = g_malloc(sizeof(struct GuestFwd)); + fwd = g_new(struct GuestFwd, 1); fwd->hd = qemu_chr_new(buf, p, NULL); if (!fwd->hd) { error_report("could not open guest forwarding device '%s'", buf); -- 1.9.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() 2014-12-04 13:28 [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Markus Armbruster 2014-12-04 13:28 ` [Qemu-devel] [PATCH 1/2] net: Fuse g_malloc(); memset() into g_new0() Markus Armbruster 2014-12-04 13:28 ` [Qemu-devel] [PATCH 2/2] net: Use g_new() & friends where that makes obvious sense Markus Armbruster @ 2014-12-05 15:08 ` Eric Blake 2014-12-19 13:15 ` Stefan Hajnoczi 3 siblings, 0 replies; 5+ messages in thread From: Eric Blake @ 2014-12-05 15:08 UTC (permalink / raw) To: Markus Armbruster, qemu-devel; +Cc: stefanha [-- Attachment #1: Type: text/plain, Size: 489 bytes --] On 12/04/2014 06:28 AM, Markus Armbruster wrote: > Markus Armbruster (2): > net: Fuse g_malloc(); memset() into g_new0() > net: Use g_new() & friends where that makes obvious sense Reviewed-by: Eric Blake <eblake@redhat.com> > > net/l2tpv3.c | 9 ++++----- > net/queue.c | 2 +- > net/slirp.c | 2 +- > 3 files changed, 6 insertions(+), 7 deletions(-) > -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 539 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() 2014-12-04 13:28 [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Markus Armbruster ` (2 preceding siblings ...) 2014-12-05 15:08 ` [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Eric Blake @ 2014-12-19 13:15 ` Stefan Hajnoczi 3 siblings, 0 replies; 5+ messages in thread From: Stefan Hajnoczi @ 2014-12-19 13:15 UTC (permalink / raw) To: Markus Armbruster; +Cc: qemu-devel, stefanha [-- Attachment #1: Type: text/plain, Size: 462 bytes --] On Thu, Dec 04, 2014 at 02:28:15PM +0100, Markus Armbruster wrote: > Markus Armbruster (2): > net: Fuse g_malloc(); memset() into g_new0() > net: Use g_new() & friends where that makes obvious sense > > net/l2tpv3.c | 9 ++++----- > net/queue.c | 2 +- > net/slirp.c | 2 +- > 3 files changed, 6 insertions(+), 7 deletions(-) > > -- > 1.9.3 > > Thanks, applied to my net tree: https://github.com/stefanha/qemu/commits/net Stefan [-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-12-19 13:15 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-12-04 13:28 [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Markus Armbruster 2014-12-04 13:28 ` [Qemu-devel] [PATCH 1/2] net: Fuse g_malloc(); memset() into g_new0() Markus Armbruster 2014-12-04 13:28 ` [Qemu-devel] [PATCH 2/2] net: Use g_new() & friends where that makes obvious sense Markus Armbruster 2014-12-05 15:08 ` [Qemu-devel] [PATCH 0/2] net: Trivial cleanups around g_malloc() Eric Blake 2014-12-19 13:15 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).