From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92507C433EF for ; Tue, 15 Mar 2022 07:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345701AbiCOHzP convert rfc822-to-8bit (ORCPT ); Tue, 15 Mar 2022 03:55:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345693AbiCOHzO (ORCPT ); Tue, 15 Mar 2022 03:55:14 -0400 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1DA96E0E3 for ; Tue, 15 Mar 2022 00:54:02 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-41-wQ12KsT-PDSqq8y9SNA3Rw-1; Tue, 15 Mar 2022 03:53:56 -0400 X-MC-Unique: wQ12KsT-PDSqq8y9SNA3Rw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25BE18001EA; Tue, 15 Mar 2022 07:53:54 +0000 (UTC) Received: from bahia (unknown [10.39.192.202]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED3FC7CB810; Tue, 15 Mar 2022 07:53:43 +0000 (UTC) Date: Tue, 15 Mar 2022 08:53:42 +0100 From: Greg Kurz To: Markus Armbruster Cc: qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson , Gerd Hoffmann , Christian Schoenebeck , "Gonglei (Arei)" , =?UTF-8?B?TWFyYy1BbmRyw6k=?= Lureau , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Laurent Vivier , Amit Shah , Peter Maydell , Stefano Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?B?SGVy?= =?UTF-8?B?dsOp?= Poussineau , Aleksandar Rikalo , Corey Minyard , Patrick Venture , Eduardo Habkost , Marcel Apfelbaum , Peter Xu , Jason Wang , =?UTF-8?B?Q8Op?= =?UTF-8?B?ZHJpYw==?= Le Goater , Daniel Henrique Barboza , David Gibson , Philippe =?UTF-8?B?TWF0aGlldS1EYXVkw6k=?= , Jean-Christophe Dubois , Keith Busch , Klaus Jensen , Yuval Shaia , Yoshinori Sato , Magnus Damm , Fabien Chouteau , KONRAD Frederic , Mark Cave-Ayland , Artyom Tarasenko , Alex Williamson , Eric Auger , Max Filippov , Juan Quintela , "Dr. David Alan Gilbert" , Konstantin Kostiuk , Michael Roth , "Daniel P. =?UTF-8?B?QmVycmFuZ8Op?=" , Pavel Dovgalyuk , Alex =?UTF-8?B?QmVubsOpZQ==?= , David Hildenbrand , Wenchao Wang , Colin Xu , Kamil Rytarowski , Reinoud Zandijk , Sunil Muthuswamy , Cornelia Huck , Thomas Huth , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow , kvm@vger.kernel.org, qemu-arm@nongnu.org, xen-devel@lists.xenproject.org, qemu-ppc@nongnu.org, qemu-block@nongnu.org, haxm-team@intel.com, qemu-s390x@nongnu.org Subject: Re: [PATCH 2/3] 9pfs: Use g_new() & friends where that makes obvious sense Message-ID: <20220315085342.2b07eff8@bahia> In-Reply-To: <20220314160108.1440470-3-armbru@redhat.com> References: <20220314160108.1440470-1-armbru@redhat.com> <20220314160108.1440470-3-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, 14 Mar 2022 17:01:07 +0100 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). > > Patch created mechanically with: > > $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci \ > --macro-file scripts/cocci-macro-file.h FILES... > > Except this uncovers a typing error: > > ../hw/9pfs/9p.c:855:13: warning: incompatible pointer types assigning to 'QpfEntry *' from 'QppEntry *' [-Wincompatible-pointer-types] > val = g_new0(QppEntry, 1); > ^ ~~~~~~~~~~~~~~~~~~~ > 1 warning generated. > > Harmless, because QppEntry is larger than QpfEntry. Fix to allocate a > QpfEntry instead. > > Cc: Greg Kurz > Cc: Christian Schoenebeck > Signed-off-by: Markus Armbruster > --- Reviewed-by: Greg Kurz > hw/9pfs/9p-proxy.c | 2 +- > hw/9pfs/9p-synth.c | 4 ++-- > hw/9pfs/9p.c | 8 ++++---- > hw/9pfs/codir.c | 6 +++--- > tests/qtest/virtio-9p-test.c | 4 ++-- > 5 files changed, 12 insertions(+), 12 deletions(-) > > diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c > index 8b4b5cf7dc..4c5e0fc217 100644 > --- a/hw/9pfs/9p-proxy.c > +++ b/hw/9pfs/9p-proxy.c > @@ -1187,7 +1187,7 @@ static int proxy_parse_opts(QemuOpts *opts, FsDriverEntry *fs, Error **errp) > > static int proxy_init(FsContext *ctx, Error **errp) > { > - V9fsProxy *proxy = g_malloc(sizeof(V9fsProxy)); > + V9fsProxy *proxy = g_new(V9fsProxy, 1); > int sock_id; > > if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { > diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c > index b3080e415b..d99d263985 100644 > --- a/hw/9pfs/9p-synth.c > +++ b/hw/9pfs/9p-synth.c > @@ -49,7 +49,7 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *parent, int mode, > > /* Add directory type and remove write bits */ > mode = ((mode & 0777) | S_IFDIR) & ~(S_IWUSR | S_IWGRP | S_IWOTH); > - node = g_malloc0(sizeof(V9fsSynthNode)); > + node = g_new0(V9fsSynthNode, 1); > if (attr) { > /* We are adding .. or . entries */ > node->attr = attr; > @@ -128,7 +128,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode, > } > /* Add file type and remove write bits */ > mode = ((mode & 0777) | S_IFREG); > - node = g_malloc0(sizeof(V9fsSynthNode)); > + node = g_new0(V9fsSynthNode, 1); > node->attr = &node->actual_attr; > node->attr->inode = synth_node_count++; > node->attr->nlink = 1; > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c > index a6d6b3f835..8e9d4aea73 100644 > --- a/hw/9pfs/9p.c > +++ b/hw/9pfs/9p.c > @@ -324,7 +324,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid) > return NULL; > } > } > - f = g_malloc0(sizeof(V9fsFidState)); > + f = g_new0(V9fsFidState, 1); > f->fid = fid; > f->fid_type = P9_FID_NONE; > f->ref = 1; > @@ -804,7 +804,7 @@ static int qid_inode_prefix_hash_bits(V9fsPDU *pdu, dev_t dev) > > val = qht_lookup(&pdu->s->qpd_table, &lookup, hash); > if (!val) { > - val = g_malloc0(sizeof(QpdEntry)); > + val = g_new0(QpdEntry, 1); > *val = lookup; > affix = affixForIndex(pdu->s->qp_affix_next); > val->prefix_bits = affix.bits; > @@ -852,7 +852,7 @@ static int qid_path_fullmap(V9fsPDU *pdu, const struct stat *stbuf, > return -ENFILE; > } > > - val = g_malloc0(sizeof(QppEntry)); > + val = g_new0(QpfEntry, 1); > *val = lookup; > > /* new unique inode and device combo */ > @@ -928,7 +928,7 @@ static int qid_path_suffixmap(V9fsPDU *pdu, const struct stat *stbuf, > return -ENFILE; > } > > - val = g_malloc0(sizeof(QppEntry)); > + val = g_new0(QppEntry, 1); > *val = lookup; > > /* new unique inode affix and device combo */ > diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c > index 75148bc985..93ba44fb75 100644 > --- a/hw/9pfs/codir.c > +++ b/hw/9pfs/codir.c > @@ -141,9 +141,9 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, > > /* append next node to result chain */ > if (!e) { > - *entries = e = g_malloc0(sizeof(V9fsDirEnt)); > + *entries = e = g_new0(V9fsDirEnt, 1); > } else { > - e = e->next = g_malloc0(sizeof(V9fsDirEnt)); > + e = e->next = g_new0(V9fsDirEnt, 1); > } > e->dent = qemu_dirent_dup(dent); > > @@ -163,7 +163,7 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, > break; > } > > - e->st = g_malloc0(sizeof(struct stat)); > + e->st = g_new0(struct stat, 1); > memcpy(e->st, &stbuf, sizeof(struct stat)); > } > > diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c > index 01ca076afe..e28c71bd8f 100644 > --- a/tests/qtest/virtio-9p-test.c > +++ b/tests/qtest/virtio-9p-test.c > @@ -468,12 +468,12 @@ static void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries, > togo -= 13 + 8 + 1 + 2 + slen, ++n) > { > if (!e) { > - e = g_malloc(sizeof(struct V9fsDirent)); > + e = g_new(struct V9fsDirent, 1); > if (entries) { > *entries = e; > } > } else { > - e = e->next = g_malloc(sizeof(struct V9fsDirent)); > + e = e->next = g_new(struct V9fsDirent, 1); > } > e->next = NULL; > /* qid[13] offset[8] type[1] name[s] */ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 56154C433F5 for ; Tue, 15 Mar 2022 07:54:56 +0000 (UTC) Received: from localhost ([::1]:33346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nU219-0007C5-5y for qemu-devel@archiver.kernel.org; Tue, 15 Mar 2022 03:54:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nU20Q-00068v-Dp for qemu-devel@nongnu.org; Tue, 15 Mar 2022 03:54:10 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:36981) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nU20N-0002nA-EO for qemu-devel@nongnu.org; Tue, 15 Mar 2022 03:54:10 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-41-wQ12KsT-PDSqq8y9SNA3Rw-1; Tue, 15 Mar 2022 03:53:56 -0400 X-MC-Unique: wQ12KsT-PDSqq8y9SNA3Rw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25BE18001EA; Tue, 15 Mar 2022 07:53:54 +0000 (UTC) Received: from bahia (unknown [10.39.192.202]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED3FC7CB810; Tue, 15 Mar 2022 07:53:43 +0000 (UTC) Date: Tue, 15 Mar 2022 08:53:42 +0100 From: Greg Kurz To: Markus Armbruster Subject: Re: [PATCH 2/3] 9pfs: Use g_new() & friends where that makes obvious sense Message-ID: <20220315085342.2b07eff8@bahia> In-Reply-To: <20220314160108.1440470-3-armbru@redhat.com> References: <20220314160108.1440470-1-armbru@redhat.com> <20220314160108.1440470-3-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Received-SPF: softfail client-ip=207.211.30.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Daniel Henrique Barboza , kvm@vger.kernel.org, "Michael S. Tsirkin" , Jason Wang , Christian Schoenebeck , qemu-devel@nongnu.org, Peter Xu , Klaus Jensen , KONRAD Frederic , Konstantin Kostiuk , Gerd Hoffmann , Ani Sinha , Reinoud Zandijk , Eric Blake , Sunil Muthuswamy , Stefano Stabellini , xen-devel@lists.xenproject.org, Yoshinori Sato , Juan Quintela , John Snow , Paul Durrant , Magnus Damm , Kamil Rytarowski , "Gonglei \(Arei\)" , =?UTF-8?B?SGVy?= =?UTF-8?B?dsOp?= Poussineau , Michael Roth , Anthony Perard , =?UTF-8?B?TWFyYy1BbmRyw6k=?= Lureau , Artyom Tarasenko , Laurent Vivier , Aleksandar Rikalo , Amit Shah , Mark Cave-Ayland , haxm-team@intel.com, Richard Henderson , "Dr. David Alan Gilbert" , Fabien Chouteau , Yuval Shaia , Thomas Huth , Eric Auger , Alex Williamson , qemu-arm@nongnu.org, =?UTF-8?B?Q8Op?= =?UTF-8?B?ZHJpYw==?= Le Goater , Pavel Dovgalyuk , Paolo Bonzini , Keith Busch , qemu-ppc@nongnu.org, David Hildenbrand , Alex =?UTF-8?B?QmVubsOpZQ==?= , David Gibson , Eduardo Habkost , Vladimir Sementsov-Ogievskiy , "Daniel P. =?UTF-8?B?QmVycmFuZ8Op?=" , qemu-block@nongnu.org, Max Filippov , qemu-s390x@nongnu.org, Patrick Venture , Cornelia Huck , Philippe =?UTF-8?B?TWF0aGlldS1EYXVkw6k=?= , Jean-Christophe Dubois , Corey Minyard , Wenchao Wang , Igor Mammedov , Colin Xu Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Mon, 14 Mar 2022 17:01:07 +0100 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. >=20 > This commit only touches allocations with size arguments of the form > sizeof(T). >=20 > Patch created mechanically with: >=20 > $ spatch --in-place --sp-file scripts/coccinelle/use-g_new-etc.cocci = \ > =09 --macro-file scripts/cocci-macro-file.h FILES... >=20 > Except this uncovers a typing error: >=20 > ../hw/9pfs/9p.c:855:13: warning: incompatible pointer types assigning= to 'QpfEntry *' from 'QppEntry *' [-Wincompatible-pointer-types] > =09 val =3D g_new0(QppEntry, 1); > =09=09^ ~~~~~~~~~~~~~~~~~~~ > 1 warning generated. >=20 > Harmless, because QppEntry is larger than QpfEntry. Fix to allocate a > QpfEntry instead. >=20 > Cc: Greg Kurz > Cc: Christian Schoenebeck > Signed-off-by: Markus Armbruster > --- Reviewed-by: Greg Kurz > hw/9pfs/9p-proxy.c | 2 +- > hw/9pfs/9p-synth.c | 4 ++-- > hw/9pfs/9p.c | 8 ++++---- > hw/9pfs/codir.c | 6 +++--- > tests/qtest/virtio-9p-test.c | 4 ++-- > 5 files changed, 12 insertions(+), 12 deletions(-) >=20 > diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c > index 8b4b5cf7dc..4c5e0fc217 100644 > --- a/hw/9pfs/9p-proxy.c > +++ b/hw/9pfs/9p-proxy.c > @@ -1187,7 +1187,7 @@ static int proxy_parse_opts(QemuOpts *opts, FsDrive= rEntry *fs, Error **errp) > =20 > static int proxy_init(FsContext *ctx, Error **errp) > { > - V9fsProxy *proxy =3D g_malloc(sizeof(V9fsProxy)); > + V9fsProxy *proxy =3D g_new(V9fsProxy, 1); > int sock_id; > =20 > if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { > diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c > index b3080e415b..d99d263985 100644 > --- a/hw/9pfs/9p-synth.c > +++ b/hw/9pfs/9p-synth.c > @@ -49,7 +49,7 @@ static V9fsSynthNode *v9fs_add_dir_node(V9fsSynthNode *= parent, int mode, > =20 > /* Add directory type and remove write bits */ > mode =3D ((mode & 0777) | S_IFDIR) & ~(S_IWUSR | S_IWGRP | S_IWOTH); > - node =3D g_malloc0(sizeof(V9fsSynthNode)); > + node =3D g_new0(V9fsSynthNode, 1); > if (attr) { > /* We are adding .. or . entries */ > node->attr =3D attr; > @@ -128,7 +128,7 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, i= nt mode, > } > /* Add file type and remove write bits */ > mode =3D ((mode & 0777) | S_IFREG); > - node =3D g_malloc0(sizeof(V9fsSynthNode)); > + node =3D g_new0(V9fsSynthNode, 1); > node->attr =3D &node->actual_attr; > node->attr->inode =3D synth_node_count++; > node->attr->nlink =3D 1; > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c > index a6d6b3f835..8e9d4aea73 100644 > --- a/hw/9pfs/9p.c > +++ b/hw/9pfs/9p.c > @@ -324,7 +324,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t = fid) > return NULL; > } > } > - f =3D g_malloc0(sizeof(V9fsFidState)); > + f =3D g_new0(V9fsFidState, 1); > f->fid =3D fid; > f->fid_type =3D P9_FID_NONE; > f->ref =3D 1; > @@ -804,7 +804,7 @@ static int qid_inode_prefix_hash_bits(V9fsPDU *pdu, d= ev_t dev) > =20 > val =3D qht_lookup(&pdu->s->qpd_table, &lookup, hash); > if (!val) { > - val =3D g_malloc0(sizeof(QpdEntry)); > + val =3D g_new0(QpdEntry, 1); > *val =3D lookup; > affix =3D affixForIndex(pdu->s->qp_affix_next); > val->prefix_bits =3D affix.bits; > @@ -852,7 +852,7 @@ static int qid_path_fullmap(V9fsPDU *pdu, const struc= t stat *stbuf, > return -ENFILE; > } > =20 > - val =3D g_malloc0(sizeof(QppEntry)); > + val =3D g_new0(QpfEntry, 1); > *val =3D lookup; > =20 > /* new unique inode and device combo */ > @@ -928,7 +928,7 @@ static int qid_path_suffixmap(V9fsPDU *pdu, const str= uct stat *stbuf, > return -ENFILE; > } > =20 > - val =3D g_malloc0(sizeof(QppEntry)); > + val =3D g_new0(QppEntry, 1); > *val =3D lookup; > =20 > /* new unique inode affix and device combo */ > diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c > index 75148bc985..93ba44fb75 100644 > --- a/hw/9pfs/codir.c > +++ b/hw/9pfs/codir.c > @@ -141,9 +141,9 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState= *fidp, > =20 > /* append next node to result chain */ > if (!e) { > - *entries =3D e =3D g_malloc0(sizeof(V9fsDirEnt)); > + *entries =3D e =3D g_new0(V9fsDirEnt, 1); > } else { > - e =3D e->next =3D g_malloc0(sizeof(V9fsDirEnt)); > + e =3D e->next =3D g_new0(V9fsDirEnt, 1); > } > e->dent =3D qemu_dirent_dup(dent); > =20 > @@ -163,7 +163,7 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState= *fidp, > break; > } > =20 > - e->st =3D g_malloc0(sizeof(struct stat)); > + e->st =3D g_new0(struct stat, 1); > memcpy(e->st, &stbuf, sizeof(struct stat)); > } > =20 > diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c > index 01ca076afe..e28c71bd8f 100644 > --- a/tests/qtest/virtio-9p-test.c > +++ b/tests/qtest/virtio-9p-test.c > @@ -468,12 +468,12 @@ static void v9fs_rreaddir(P9Req *req, uint32_t *cou= nt, uint32_t *nentries, > togo -=3D 13 + 8 + 1 + 2 + slen, ++n) > { > if (!e) { > - e =3D g_malloc(sizeof(struct V9fsDirent)); > + e =3D g_new(struct V9fsDirent, 1); > if (entries) { > *entries =3D e; > } > } else { > - e =3D e->next =3D g_malloc(sizeof(struct V9fsDirent)); > + e =3D e->next =3D g_new(struct V9fsDirent, 1); > } > e->next =3D NULL; > /* qid[13] offset[8] type[1] name[s] */