* [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense
@ 2015-10-29 15:55 Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 1/4] ui: " Markus Armbruster
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-10-29 15:55 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, kraxel
v2:
* Trivially rebased
Markus Armbruster (4):
ui: Use g_new() & friends where that makes obvious sense
audio: Use g_new() & friends where that makes obvious sense
qxl: Use g_new() & friends where that makes obvious sense
usb: Use g_new() & friends where that makes obvious sense
audio/alsaaudio.c | 2 +-
audio/coreaudio.c | 2 +-
audio/dsoundaudio.c | 2 +-
audio/ossaudio.c | 2 +-
audio/paaudio.c | 2 +-
audio/wavaudio.c | 2 +-
hw/audio/intel-hda.c | 2 +-
hw/display/qxl.c | 2 +-
hw/usb/ccid-card-emulated.c | 4 ++--
hw/usb/dev-mtp.c | 3 +--
hw/usb/hcd-xhci.c | 2 +-
hw/usb/redirect.c | 6 +++---
ui/console.c | 2 +-
ui/curses.c | 2 +-
ui/input-legacy.c | 4 ++--
ui/keymaps.c | 2 +-
ui/sdl.c | 2 +-
ui/vnc-jobs.c | 6 +++---
ui/vnc.c | 6 +++---
19 files changed, 27 insertions(+), 28 deletions(-)
--
2.4.3
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 1/4] ui: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
@ 2015-10-29 15:55 ` Markus Armbruster
2015-11-03 12:06 ` Michael Tokarev
2015-11-03 16:12 ` [Qemu-devel] [PATCH v3 " Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 2/4] audio: " Markus Armbruster
` (4 subsequent siblings)
5 siblings, 2 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-10-29 15:55 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, kraxel
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). Same Coccinelle semantic patch as in commit b45c03f.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
ui/console.c | 2 +-
ui/curses.c | 2 +-
ui/input-legacy.c | 4 ++--
ui/keymaps.c | 2 +-
ui/sdl.c | 2 +-
ui/vnc-jobs.c | 6 +++---
ui/vnc.c | 6 +++---
7 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/ui/console.c b/ui/console.c
index cf649b2..b862cfb 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -450,7 +450,7 @@ static void text_console_resize(QemuConsole *s)
if (s->width < w1)
w1 = s->width;
- cells = g_malloc(s->width * s->total_height * sizeof(TextCell));
+ cells = g_new(TextCell, s->width * s->total_height);
for(y = 0; y < s->total_height; y++) {
c = &cells[y * s->width];
if (w1 > 0) {
diff --git a/ui/curses.c b/ui/curses.c
index 8edb038..db83188 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -382,7 +382,7 @@ void curses_display_init(DisplayState *ds, int full_screen)
curses_winch_init();
- dcl = (DisplayChangeListener *) g_malloc0(sizeof(DisplayChangeListener));
+ dcl = g_new0(DisplayChangeListener, 1);
dcl->ops = &dcl_ops;
register_displaychangelistener(dcl);
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index e50f296..c5f173d 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -205,7 +205,7 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
{
QEMUPutMouseEntry *s;
- s = g_malloc0(sizeof(QEMUPutMouseEntry));
+ s = g_new0(QEMUPutMouseEntry, 1);
s->qemu_put_mouse_event = func;
s->qemu_put_mouse_event_opaque = opaque;
@@ -239,7 +239,7 @@ QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
{
QEMUPutLEDEntry *s;
- s = g_malloc0(sizeof(QEMUPutLEDEntry));
+ s = g_new0(QEMUPutLEDEntry, 1);
s->put_led = func;
s->opaque = opaque;
diff --git a/ui/keymaps.c b/ui/keymaps.c
index 49410ae..1b9ba3f 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -109,7 +109,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
}
if (!k) {
- k = g_malloc0(sizeof(kbd_layout_t));
+ k = g_new0(kbd_layout_t, 1);
}
for(;;) {
diff --git a/ui/sdl.c b/ui/sdl.c
index 3be2910..570cb99 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -985,7 +985,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
sdl_grab_start();
}
- dcl = g_malloc0(sizeof(DisplayChangeListener));
+ dcl = g_new0(DisplayChangeListener, 1);
dcl->ops = &dcl_ops;
register_displaychangelistener(dcl);
diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
index 22c9abc..9512b87 100644
--- a/ui/vnc-jobs.c
+++ b/ui/vnc-jobs.c
@@ -79,7 +79,7 @@ static void vnc_unlock_queue(VncJobQueue *queue)
VncJob *vnc_job_new(VncState *vs)
{
- VncJob *job = g_malloc0(sizeof(VncJob));
+ VncJob *job = g_new0(VncJob, 1);
job->vs = vs;
vnc_lock_queue(queue);
@@ -90,7 +90,7 @@ VncJob *vnc_job_new(VncState *vs)
int vnc_job_add_rect(VncJob *job, int x, int y, int w, int h)
{
- VncRectEntry *entry = g_malloc0(sizeof(VncRectEntry));
+ VncRectEntry *entry = g_new0(VncRectEntry, 1);
entry->rect.x = x;
entry->rect.y = y;
@@ -298,7 +298,7 @@ disconnected:
static VncJobQueue *vnc_queue_init(void)
{
- VncJobQueue *queue = g_malloc0(sizeof(VncJobQueue));
+ VncJobQueue *queue = g_new0(VncJobQueue, 1);
qemu_cond_init(&queue->cond);
qemu_mutex_init(&queue->mutex);
diff --git a/ui/vnc.c b/ui/vnc.c
index faff054..2725934 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -173,7 +173,7 @@ static VncBasicInfo *vnc_basic_info_get(struct sockaddr_storage *sa,
return NULL;
}
- info = g_malloc0(sizeof(VncBasicInfo));
+ info = g_new0(VncBasicInfo, 1);
info->host = g_strdup(host);
info->service = g_strdup(serv);
info->family = inet_netfamily(sa->ss_family);
@@ -2956,7 +2956,7 @@ static void vnc_refresh(DisplayChangeListener *dcl)
static void vnc_connect(VncDisplay *vd, int csock,
bool skipauth, bool websocket)
{
- VncState *vs = g_malloc0(sizeof(VncState));
+ VncState *vs = g_new0(VncState, 1);
int i;
vs->csock = csock;
@@ -2979,7 +2979,7 @@ static void vnc_connect(VncDisplay *vd, int csock,
vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect));
for (i = 0; i < VNC_STAT_ROWS; ++i) {
- vs->lossy_rect[i] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t));
+ vs->lossy_rect[i] = g_new0(uint8_t, VNC_STAT_COLS);
}
VNC_DEBUG("New client on socket %d\n", csock);
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 2/4] audio: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 1/4] ui: " Markus Armbruster
@ 2015-10-29 15:55 ` Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 3/4] qxl: " Markus Armbruster
` (3 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-10-29 15:55 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, kraxel
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). Same Coccinelle semantic patch as in commit b45c03f.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
audio/alsaaudio.c | 2 +-
audio/coreaudio.c | 2 +-
audio/dsoundaudio.c | 2 +-
audio/ossaudio.c | 2 +-
audio/paaudio.c | 2 +-
audio/wavaudio.c | 2 +-
hw/audio/intel-hda.c | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 6315b2d..76813f4 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -1125,7 +1125,7 @@ static ALSAConf glob_conf = {
static void *alsa_audio_init (void)
{
- ALSAConf *conf = g_malloc(sizeof(ALSAConf));
+ ALSAConf *conf = g_new(ALSAConf, 1);
*conf = glob_conf;
return conf;
}
diff --git a/audio/coreaudio.c b/audio/coreaudio.c
index 6dfd63e..6390ba4 100644
--- a/audio/coreaudio.c
+++ b/audio/coreaudio.c
@@ -504,7 +504,7 @@ static CoreaudioConf glob_conf = {
static void *coreaudio_audio_init (void)
{
- CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
+ CoreaudioConf *conf = g_new(CoreaudioConf, 1);
*conf = glob_conf;
atexit(coreaudio_atexit);
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index e9472c1..3949fa4 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -786,7 +786,7 @@ static void *dsound_audio_init (void)
{
int err;
HRESULT hr;
- dsound *s = g_malloc0(sizeof(dsound));
+ dsound *s = g_new0(dsound, 1);
s->conf = glob_conf;
hr = CoInitialize (NULL);
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index 7dbe333..2614c62 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -848,7 +848,7 @@ static OSSConf glob_conf = {
static void *oss_audio_init (void)
{
- OSSConf *conf = g_malloc(sizeof(OSSConf));
+ OSSConf *conf = g_new(OSSConf, 1);
*conf = glob_conf;
if (access(conf->devpath_in, R_OK | W_OK) < 0 ||
diff --git a/audio/paaudio.c b/audio/paaudio.c
index fea6071..9c498cf 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -814,7 +814,7 @@ static PAConf glob_conf = {
static void *qpa_audio_init (void)
{
- paaudio *g = g_malloc(sizeof(paaudio));
+ paaudio *g = g_new(paaudio, 1);
g->conf = glob_conf;
g->mainloop = NULL;
g->context = NULL;
diff --git a/audio/wavaudio.c b/audio/wavaudio.c
index c586020..f706fae 100644
--- a/audio/wavaudio.c
+++ b/audio/wavaudio.c
@@ -230,7 +230,7 @@ static WAVConf glob_conf = {
static void *wav_audio_init (void)
{
- WAVConf *conf = g_malloc(sizeof(WAVConf));
+ WAVConf *conf = g_new(WAVConf, 1);
*conf = glob_conf;
return conf;
}
diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index 433463e..6074c2e 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -467,7 +467,7 @@ static void intel_hda_parse_bdl(IntelHDAState *d, IntelHDAStream *st)
addr = intel_hda_addr(st->bdlp_lbase, st->bdlp_ubase);
st->bentries = st->lvi +1;
g_free(st->bpl);
- st->bpl = g_malloc(sizeof(bpl) * st->bentries);
+ st->bpl = g_new(bpl, st->bentries);
for (i = 0; i < st->bentries; i++, addr += 16) {
pci_dma_read(&d->pci, addr, buf, 16);
st->bpl[i].addr = le64_to_cpu(*(uint64_t *)buf);
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 3/4] qxl: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 1/4] ui: " Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 2/4] audio: " Markus Armbruster
@ 2015-10-29 15:55 ` Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 4/4] usb: " Markus Armbruster
` (2 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-10-29 15:55 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, kraxel
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). Same Coccinelle semantic patch as in commit b45c03f.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
hw/display/qxl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/display/qxl.c b/hw/display/qxl.c
index 9c961da..8a3040c 100644
--- a/hw/display/qxl.c
+++ b/hw/display/qxl.c
@@ -2156,7 +2156,7 @@ static int qxl_post_load(void *opaque, int version)
qxl_create_guest_primary(d, 1, QXL_SYNC);
/* replay surface-create and cursor-set commands */
- cmds = g_malloc0(sizeof(QXLCommandExt) * (d->ssd.num_surfaces + 1));
+ cmds = g_new0(QXLCommandExt, d->ssd.num_surfaces + 1);
for (in = 0, out = 0; in < d->ssd.num_surfaces; in++) {
if (d->guest_surfaces.cmds[in] == 0) {
continue;
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v2 4/4] usb: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
` (2 preceding siblings ...)
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 3/4] qxl: " Markus Armbruster
@ 2015-10-29 15:55 ` Markus Armbruster
2015-10-30 11:13 ` [Qemu-devel] [PATCH v2 0/4] ui audio qxl " Gerd Hoffmann
2015-11-03 12:09 ` Michael Tokarev
5 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-10-29 15:55 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, kraxel
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). Same Coccinelle semantic patch as in commit b45c03f.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
hw/usb/ccid-card-emulated.c | 4 ++--
hw/usb/dev-mtp.c | 3 +--
hw/usb/hcd-xhci.c | 2 +-
hw/usb/redirect.c | 6 +++---
4 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c
index 72329ed..869a63c 100644
--- a/hw/usb/ccid-card-emulated.c
+++ b/hw/usb/ccid-card-emulated.c
@@ -166,7 +166,7 @@ static void emulated_push_event(EmulatedState *card, EmulEvent *event)
static void emulated_push_type(EmulatedState *card, uint32_t type)
{
- EmulEvent *event = (EmulEvent *)g_malloc(sizeof(EmulEvent));
+ EmulEvent *event = g_new(EmulEvent, 1);
assert(event);
event->p.gen.type = type;
@@ -175,7 +175,7 @@ static void emulated_push_type(EmulatedState *card, uint32_t type)
static void emulated_push_error(EmulatedState *card, uint64_t code)
{
- EmulEvent *event = (EmulEvent *)g_malloc(sizeof(EmulEvent));
+ EmulEvent *event = g_new(EmulEvent, 1);
assert(event);
event->p.error.type = EMUL_ERROR;
diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 809b1cb..a276267 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -359,8 +359,7 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject *o)
}
while ((entry = readdir(dir)) != NULL) {
if ((o->nchildren % 32) == 0) {
- o->children = g_realloc(o->children,
- (o->nchildren + 32) * sizeof(MTPObject *));
+ o->children = g_renew(MTPObject *, o->children, o->nchildren + 32);
}
o->children[o->nchildren] =
usb_mtp_object_alloc(s, s->next_handle++, o, entry->d_name);
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 1c57e20..268ab36 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -2188,7 +2188,7 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
xfer->trbs = NULL;
}
if (!xfer->trbs) {
- xfer->trbs = g_malloc(sizeof(XHCITRB) * length);
+ xfer->trbs = g_new(XHCITRB, length);
xfer->trb_alloced = length;
}
xfer->trb_count = length;
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 38086cd..30ff742 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -322,7 +322,7 @@ static void packet_id_queue_add(struct PacketIdQueue *q, uint64_t id)
DPRINTF("adding packet id %"PRIu64" to %s queue\n", id, q->name);
- e = g_malloc0(sizeof(struct PacketIdQueueEntry));
+ e = g_new0(struct PacketIdQueueEntry, 1);
e->id = id;
QTAILQ_INSERT_TAIL(&q->head, e, next);
q->size++;
@@ -468,7 +468,7 @@ static void bufp_alloc(USBRedirDevice *dev, uint8_t *data, uint16_t len,
dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 0;
}
- bufp = g_malloc(sizeof(struct buf_packet));
+ bufp = g_new(struct buf_packet, 1);
bufp->data = data;
bufp->len = len;
bufp->offset = 0;
@@ -2234,7 +2234,7 @@ static int usbredir_get_bufpq(QEMUFile *f, void *priv, size_t unused)
endp->bufpq_size = qemu_get_be32(f);
for (i = 0; i < endp->bufpq_size; i++) {
- bufp = g_malloc(sizeof(struct buf_packet));
+ bufp = g_new(struct buf_packet, 1);
bufp->len = qemu_get_be32(f);
bufp->status = qemu_get_be32(f);
bufp->offset = 0;
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
` (3 preceding siblings ...)
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 4/4] usb: " Markus Armbruster
@ 2015-10-30 11:13 ` Gerd Hoffmann
2015-10-30 11:31 ` Gerd Hoffmann
2015-10-30 14:16 ` Markus Armbruster
2015-11-03 12:09 ` Michael Tokarev
5 siblings, 2 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2015-10-30 11:13 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-trivial, qemu-devel
On Do, 2015-10-29 at 16:55 +0100, Markus Armbruster wrote:
> v2:
> * Trivially rebased
>
> Markus Armbruster (4):
> ui: Use g_new() & friends where that makes obvious sense
> audio: Use g_new() & friends where that makes obvious sense
> qxl: Use g_new() & friends where that makes obvious sense
> usb: Use g_new() & friends where that makes obvious sense
I'd prefer to drop the audio one because there still is the gsoc patch
series pending which touches all this anyway.
Otherwise looks fine to me.
Do you want me pick this up or send a pull request yourself?
On case of the latter:
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
cheers,
Gerd
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense
2015-10-30 11:13 ` [Qemu-devel] [PATCH v2 0/4] ui audio qxl " Gerd Hoffmann
@ 2015-10-30 11:31 ` Gerd Hoffmann
2015-10-30 14:16 ` Markus Armbruster
1 sibling, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2015-10-30 11:31 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-trivial, qemu-devel
On Fr, 2015-10-30 at 12:13 +0100, Gerd Hoffmann wrote:
> Do you want me pick this up or send a pull request yourself?
Oh, I see you have trivial cc'ed. scratch the question then ;)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense
2015-10-30 11:13 ` [Qemu-devel] [PATCH v2 0/4] ui audio qxl " Gerd Hoffmann
2015-10-30 11:31 ` Gerd Hoffmann
@ 2015-10-30 14:16 ` Markus Armbruster
1 sibling, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-10-30 14:16 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-trivial, qemu-devel
Gerd Hoffmann <kraxel@redhat.com> writes:
> On Do, 2015-10-29 at 16:55 +0100, Markus Armbruster wrote:
>> v2:
>> * Trivially rebased
>>
>> Markus Armbruster (4):
>> ui: Use g_new() & friends where that makes obvious sense
>> audio: Use g_new() & friends where that makes obvious sense
>> qxl: Use g_new() & friends where that makes obvious sense
>> usb: Use g_new() & friends where that makes obvious sense
>
> I'd prefer to drop the audio one because there still is the gsoc patch
> series pending which touches all this anyway.
I'm fine with delaying the audio part; running spatch again is easy
enough. I'd appreciate a reminder when the audio subsystem is ready for
this work.
> Otherwise looks fine to me.
>
> Do you want me pick this up or send a pull request yourself?
I thought either you or -trivial.
> On case of the latter:
>
> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Thanks!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 1/4] ui: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 1/4] ui: " Markus Armbruster
@ 2015-11-03 12:06 ` Michael Tokarev
2015-11-03 13:49 ` Markus Armbruster
2015-11-03 16:12 ` [Qemu-devel] [PATCH v3 " Markus Armbruster
1 sibling, 1 reply; 12+ messages in thread
From: Michael Tokarev @ 2015-11-03 12:06 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: qemu-trivial, kraxel
29.10.2015 18:55, Markus Armbruster wrote:
> 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). Same Coccinelle semantic patch as in commit b45c03f.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
> ui/console.c | 2 +-
> ui/curses.c | 2 +-
> ui/input-legacy.c | 4 ++--
> ui/keymaps.c | 2 +-
> ui/sdl.c | 2 +-
> ui/vnc-jobs.c | 6 +++---
> ui/vnc.c | 6 +++---
> 7 files changed, 12 insertions(+), 12 deletions(-)
ui/vnc.c code has been modified by Eric Blake meanwhile,
in 2d32addae70987521578d8bb27c6b3f52cdcbdcb "sockets:
Convert to new qapi union layout".
The patch applies for other files however.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
` (4 preceding siblings ...)
2015-10-30 11:13 ` [Qemu-devel] [PATCH v2 0/4] ui audio qxl " Gerd Hoffmann
@ 2015-11-03 12:09 ` Michael Tokarev
5 siblings, 0 replies; 12+ messages in thread
From: Michael Tokarev @ 2015-11-03 12:09 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: qemu-trivial, kraxel
29.10.2015 18:55, Markus Armbruster wrote:
> v2:
> * Trivially rebased
>
> Markus Armbruster (4):
> ui: Use g_new() & friends where that makes obvious sense
> audio: Use g_new() & friends where that makes obvious sense
> qxl: Use g_new() & friends where that makes obvious sense
> usb: Use g_new() & friends where that makes obvious sense
Applied to -trivial except the audio bits and ui/vnc.c bits.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v2 1/4] ui: Use g_new() & friends where that makes obvious sense
2015-11-03 12:06 ` Michael Tokarev
@ 2015-11-03 13:49 ` Markus Armbruster
0 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-11-03 13:49 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-trivial, qemu-devel, kraxel
Michael Tokarev <mjt@tls.msk.ru> writes:
> 29.10.2015 18:55, Markus Armbruster wrote:
>> 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). Same Coccinelle semantic patch as in commit b45c03f.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> ---
>> ui/console.c | 2 +-
>> ui/curses.c | 2 +-
>> ui/input-legacy.c | 4 ++--
>> ui/keymaps.c | 2 +-
>> ui/sdl.c | 2 +-
>> ui/vnc-jobs.c | 6 +++---
>> ui/vnc.c | 6 +++---
>> 7 files changed, 12 insertions(+), 12 deletions(-)
>
> ui/vnc.c code has been modified by Eric Blake meanwhile,
> in 2d32addae70987521578d8bb27c6b3f52cdcbdcb "sockets:
> Convert to new qapi union layout".
>
> The patch applies for other files however.
I can regenerate this patch easily. Would you be willing to replace it
in your tree by a v3?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v3 1/4] ui: Use g_new() & friends where that makes obvious sense
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 1/4] ui: " Markus Armbruster
2015-11-03 12:06 ` Michael Tokarev
@ 2015-11-03 16:12 ` Markus Armbruster
1 sibling, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2015-11-03 16:12 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, kraxel
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). Same Coccinelle semantic patch as in commit b45c03f.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
v3: Straightforward rebase: one hunk dropped from ui/vnc.c
ui/console.c | 2 +-
ui/curses.c | 2 +-
ui/input-legacy.c | 4 ++--
ui/keymaps.c | 2 +-
ui/sdl.c | 2 +-
ui/vnc-jobs.c | 6 +++---
ui/vnc.c | 4 ++--
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/ui/console.c b/ui/console.c
index f26544e..745c354 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -450,7 +450,7 @@ static void text_console_resize(QemuConsole *s)
if (s->width < w1)
w1 = s->width;
- cells = g_malloc(s->width * s->total_height * sizeof(TextCell));
+ cells = g_new(TextCell, s->width * s->total_height);
for(y = 0; y < s->total_height; y++) {
c = &cells[y * s->width];
if (w1 > 0) {
diff --git a/ui/curses.c b/ui/curses.c
index 8edb038..db83188 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -382,7 +382,7 @@ void curses_display_init(DisplayState *ds, int full_screen)
curses_winch_init();
- dcl = (DisplayChangeListener *) g_malloc0(sizeof(DisplayChangeListener));
+ dcl = g_new0(DisplayChangeListener, 1);
dcl->ops = &dcl_ops;
register_displaychangelistener(dcl);
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index a67ed32..e0a39f0 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -206,7 +206,7 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
{
QEMUPutMouseEntry *s;
- s = g_malloc0(sizeof(QEMUPutMouseEntry));
+ s = g_new0(QEMUPutMouseEntry, 1);
s->qemu_put_mouse_event = func;
s->qemu_put_mouse_event_opaque = opaque;
@@ -240,7 +240,7 @@ QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
{
QEMUPutLEDEntry *s;
- s = g_malloc0(sizeof(QEMUPutLEDEntry));
+ s = g_new0(QEMUPutLEDEntry, 1);
s->put_led = func;
s->opaque = opaque;
diff --git a/ui/keymaps.c b/ui/keymaps.c
index 49410ae..1b9ba3f 100644
--- a/ui/keymaps.c
+++ b/ui/keymaps.c
@@ -109,7 +109,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table,
}
if (!k) {
- k = g_malloc0(sizeof(kbd_layout_t));
+ k = g_new0(kbd_layout_t, 1);
}
for(;;) {
diff --git a/ui/sdl.c b/ui/sdl.c
index 3be2910..570cb99 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -985,7 +985,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
sdl_grab_start();
}
- dcl = g_malloc0(sizeof(DisplayChangeListener));
+ dcl = g_new0(DisplayChangeListener, 1);
dcl->ops = &dcl_ops;
register_displaychangelistener(dcl);
diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c
index 22c9abc..9512b87 100644
--- a/ui/vnc-jobs.c
+++ b/ui/vnc-jobs.c
@@ -79,7 +79,7 @@ static void vnc_unlock_queue(VncJobQueue *queue)
VncJob *vnc_job_new(VncState *vs)
{
- VncJob *job = g_malloc0(sizeof(VncJob));
+ VncJob *job = g_new0(VncJob, 1);
job->vs = vs;
vnc_lock_queue(queue);
@@ -90,7 +90,7 @@ VncJob *vnc_job_new(VncState *vs)
int vnc_job_add_rect(VncJob *job, int x, int y, int w, int h)
{
- VncRectEntry *entry = g_malloc0(sizeof(VncRectEntry));
+ VncRectEntry *entry = g_new0(VncRectEntry, 1);
entry->rect.x = x;
entry->rect.y = y;
@@ -298,7 +298,7 @@ disconnected:
static VncJobQueue *vnc_queue_init(void)
{
- VncJobQueue *queue = g_malloc0(sizeof(VncJobQueue));
+ VncJobQueue *queue = g_new0(VncJobQueue, 1);
qemu_cond_init(&queue->cond);
qemu_mutex_init(&queue->mutex);
diff --git a/ui/vnc.c b/ui/vnc.c
index 7b37e3b..fcabcf9 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2966,7 +2966,7 @@ static void vnc_refresh(DisplayChangeListener *dcl)
static void vnc_connect(VncDisplay *vd, int csock,
bool skipauth, bool websocket)
{
- VncState *vs = g_malloc0(sizeof(VncState));
+ VncState *vs = g_new0(VncState, 1);
int i;
vs->csock = csock;
@@ -2989,7 +2989,7 @@ static void vnc_connect(VncDisplay *vd, int csock,
vs->lossy_rect = g_malloc0(VNC_STAT_ROWS * sizeof (*vs->lossy_rect));
for (i = 0; i < VNC_STAT_ROWS; ++i) {
- vs->lossy_rect[i] = g_malloc0(VNC_STAT_COLS * sizeof (uint8_t));
+ vs->lossy_rect[i] = g_new0(uint8_t, VNC_STAT_COLS);
}
VNC_DEBUG("New client on socket %d\n", csock);
--
2.4.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-11-03 16:12 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-29 15:55 [Qemu-devel] [PATCH v2 0/4] ui audio qxl usb: Use g_new() & friends where that makes obvious sense Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 1/4] ui: " Markus Armbruster
2015-11-03 12:06 ` Michael Tokarev
2015-11-03 13:49 ` Markus Armbruster
2015-11-03 16:12 ` [Qemu-devel] [PATCH v3 " Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 2/4] audio: " Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 3/4] qxl: " Markus Armbruster
2015-10-29 15:55 ` [Qemu-devel] [PATCH v2 4/4] usb: " Markus Armbruster
2015-10-30 11:13 ` [Qemu-devel] [PATCH v2 0/4] ui audio qxl " Gerd Hoffmann
2015-10-30 11:31 ` Gerd Hoffmann
2015-10-30 14:16 ` Markus Armbruster
2015-11-03 12:09 ` Michael Tokarev
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).