From nobody Fri Nov 29 08:35:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1647274043; cv=none; d=zohomail.com; s=zohoarc; b=n5aHypxOAVEjJWeQIJyYNhVM9bx9lnL6ZD/WEeed9ZUjVhcwkJSrFHCYgzET4VgSGcrYStyyNUzlgQyqNnt6hSeHVYy1fHizs5t5MIXHneSMFH8M4fyTcEWm/0dJq8Cp5uzs6+e/7C9EzLxkJvIb8F8wWL4HTrLfF5ETrZaqqoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647274043; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jyh5Aky+XmxKXch9GhHyv+ocJ1z/NmLUE6mIW6ga0GM=; b=k4IFBhRQNY1Gy5/Eir2TSnO6Cm2fC0mhJsmxDpG4O/yFr5zdYM7BwJI3z509wTN4Jcg4JPuHEh+p08qT5BCHAc1WD4SA2OkgL95iW6yVHSsv1GlBQ7YgaWbNx7X6uYe4WDMhIGQGBu8AFvCekKobsZagDZnds2FWNjoVeUs/lgE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1647274042445711.1911036975463; Mon, 14 Mar 2022 09:07:22 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.290306.492325 (Exim 4.92) (envelope-from ) id 1nTn8h-0004Nn-Dl; Mon, 14 Mar 2022 16:01:43 +0000 Received: by outflank-mailman (output) from mailman id 290306.492325; Mon, 14 Mar 2022 16:01:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nTn8h-0004Ne-9f; Mon, 14 Mar 2022 16:01:43 +0000 Received: by outflank-mailman (input) for mailman id 290306; Mon, 14 Mar 2022 16:01:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nTn8f-0003d5-SB for xen-devel@lists.xenproject.org; Mon, 14 Mar 2022 16:01:41 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 08438bf1-a3b0-11ec-853b-5f4723681683; Mon, 14 Mar 2022 17:01:40 +0100 (CET) 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-629-QY0a79qXNymPxjJmfg1VZQ-1; Mon, 14 Mar 2022 12:01:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F806899ED9; Mon, 14 Mar 2022 16:01:33 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF49A1111C68; Mon, 14 Mar 2022 16:01:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AA31321D1F58; Mon, 14 Mar 2022 17:01:08 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 08438bf1-a3b0-11ec-853b-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647273698; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jyh5Aky+XmxKXch9GhHyv+ocJ1z/NmLUE6mIW6ga0GM=; b=HO91wm7njYYk/5a+8raPj8UPRfHoswl/9zzk2hiFTBJ0jbRzqeQjvudETv87ilMZ6rp6jw inBaFYCytD89ojVF4LDXdNnh1zOrX+DveEBqWjO+LLckX0sAM8p0EwOQU7alU4SRuvTO2R oJBdVROVIjGE4ebucx886Y5DucC5B2g= X-MC-Unique: QY0a79qXNymPxjJmfg1VZQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson , Gerd Hoffmann , Christian Schoenebeck , "Gonglei (Arei)" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Igor Mammedov , Ani Sinha , Laurent Vivier , Amit Shah , Peter Maydell , Stefano Stabellini , Anthony Perard , Paul Durrant , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Aleksandar Rikalo , Corey Minyard , Patrick Venture , Eduardo Habkost , Marcel Apfelbaum , Peter Xu , Jason Wang , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Greg Kurz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , 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 , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Pavel Dovgalyuk , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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: [PATCH 2/3] 9pfs: Use g_new() & friends where that makes obvious sense Date: Mon, 14 Mar 2022 17:01:07 +0100 Message-Id: <20220314160108.1440470-3-armbru@redhat.com> In-Reply-To: <20220314160108.1440470-1-armbru@redhat.com> References: <20220314160108.1440470-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1647274045062100001 Content-Type: text/plain; charset="utf-8" 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 t= o 'QpfEntry *' from 'QppEntry *' [-Wincompatible-pointer-types] val =3D 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: Alex Benn=C3=A9e Reviewed-by: Christian Schoenebeck 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, FsDriverE= ntry *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 *pa= rent, 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, int= 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 fi= d) 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, dev= _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 struct = 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 struc= t 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 *count= , 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] */ --=20 2.35.1