Return-Path: Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l20-20020a1709066b9400b006dabdbc8350sm7157034ejr.30.2022.03.14.12.23.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 12:23:10 -0700 (PDT) Received: from zen (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 117581FFB7; Mon, 14 Mar 2022 19:23:10 +0000 (GMT) References: <20220314160108.1440470-1-armbru@redhat.com> <20220314160108.1440470-3-armbru@redhat.com> User-agent: mu4e 1.7.10; emacs 28.0.92 From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Markus Armbruster Cc: qemu-devel@nongnu.org, Paolo Bonzini , Richard Henderson , Gerd Hoffmann , Christian Schoenebeck , "Gonglei (Arei)" , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , "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?= Poussineau , Aleksandar Rikalo , Corey Minyard , Patrick Venture , Eduardo Habkost , Marcel Apfelbaum , Peter Xu , Jason Wang , =?utf-8?Q?C=C3=A9dric?= Le Goater , Daniel Henrique Barboza , David Gibson , Greg Kurz , Philippe =?utf-8?Q?Mathieu-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_P=2E_Berrang=C3=A9?= , Pavel Dovgalyuk , 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 Date: Mon, 14 Mar 2022 19:23:04 +0000 In-reply-to: <20220314160108.1440470-3-armbru@redhat.com> Message-ID: <87ee345of5.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TUID: zIxMcB6hNcGR Markus Armbruster writes: > 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 =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 --=20 Alex Benn=C3=A9e