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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 0F5F6C433F5 for ; Tue, 15 Mar 2022 14:03:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.290809.493304 (Exim 4.92) (envelope-from ) id 1nU7lb-0007H3-Ny; Tue, 15 Mar 2022 14:03:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 290809.493304; Tue, 15 Mar 2022 14:03:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU7lb-0007Gw-KN; Tue, 15 Mar 2022 14:03:15 +0000 Received: by outflank-mailman (input) for mailman id 290809; Tue, 15 Mar 2022 14:03:14 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nU7la-0007GI-H2 for xen-devel@lists.xenproject.org; Tue, 15 Mar 2022 14:03:14 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a715c491-a468-11ec-8eba-a37418f5ba1a; Tue, 15 Mar 2022 15:03:13 +0100 (CET) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-266-LExbIUHVMB2k-e1e--Crmg-1; Tue, 15 Mar 2022 10:03:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7419380390A; Tue, 15 Mar 2022 14:03:03 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CC1AC53741; Tue, 15 Mar 2022 14:03:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 32B4B21E6821; Tue, 15 Mar 2022 15:03:02 +0100 (CET) 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: a715c491-a468-11ec-8eba-a37418f5ba1a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647352992; 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: in-reply-to:in-reply-to:references:references; bh=MKik6AtmKkZjLoAeTfrbKw62PODykM0Fa40qjwa00Cw=; b=ZrZAqGVau8Sxjhc1470Ore8CqkcIMd+pDFtNFQrHlYA42vbX1e7hHa8W7U2QUY7hPrtHZH p8VOrwdl4jo398nH1DmNDop5BScXTBFMPBnxmIfxolAmQyPAixvwYsBHAtxWgS3CNsu14r U582pLsrl2QE/sa2sxl76NEESQgtWWs= X-MC-Unique: LExbIUHVMB2k-e1e--Crmg-1 From: Markus Armbruster To: Eric Blake 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 , Daniel P. =?utf-8?Q?Berrang=C3=A9?= , Pavel Dovgalyuk , Alex =?utf-8?Q?Benn=C3=A9e?= , David Hildenbrand , Wenchao Wang , Colin Xu , Kamil Rytarowski , Reinoud Zandijk , Sunil Muthuswamy , Cornelia Huck , Thomas Huth , 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 3/3] Use g_new() & friends where that makes obvious sense References: <20220314160108.1440470-1-armbru@redhat.com> <20220314160108.1440470-4-armbru@redhat.com> <20220315090748.acju5mjbe4tax272@redhat.com> Date: Tue, 15 Mar 2022 15:03:02 +0100 In-Reply-To: <20220315090748.acju5mjbe4tax272@redhat.com> (Eric Blake's message of "Tue, 15 Mar 2022 04:07:48 -0500") Message-ID: <87zglrjotl.fsf@pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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-Type: text/plain Eric Blake writes: > On Mon, Mar 14, 2022 at 05:01:08PM +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... >> >> Signed-off-by: Markus Armbruster >> --- > > I agree that this is mechanical, but... > > >> qga/commands-win32.c | 8 ++--- >> qga/commands.c | 2 +- >> qom/qom-qmp-cmds.c | 2 +- >> replay/replay-char.c | 4 +-- >> replay/replay-events.c | 10 +++--- >> scripts/coverity-scan/model.c | 2 +- > > ...are we sure we want to touch this particular file? Good catch! >> diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c >> index 9d4fba53d9..30bea672e1 100644 >> --- a/scripts/coverity-scan/model.c >> +++ b/scripts/coverity-scan/model.c >> @@ -356,7 +356,7 @@ int g_poll (GPollFD *fds, unsigned nfds, int timeout) >> typedef struct _GIOChannel GIOChannel; >> GIOChannel *g_io_channel_unix_new(int fd) >> { >> - GIOChannel *c = g_malloc0(sizeof(GIOChannel)); >> + GIOChannel *c = g_new0(GIOChannel, 1); >> __coverity_escape__(fd); >> return c; >> } > > Our model has a definition of g_malloc0(), but I'm not sure whether > Coverity picks up the macro g_new0() in the same manner. I believe it does, by parsing the macro definition from the header. Regardless, I'd prefer to keep model.c self-contained. I'll drop this hunk. Thanks! 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 1BDFAC433EF for ; Tue, 15 Mar 2022 14:05:59 +0000 (UTC) Received: from localhost ([::1]:50242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nU7oE-0004hv-3q for qemu-devel@archiver.kernel.org; Tue, 15 Mar 2022 10:05:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nU7lc-00036D-FG for qemu-devel@nongnu.org; Tue, 15 Mar 2022 10:03:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31309) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nU7lZ-0003GI-CX for qemu-devel@nongnu.org; Tue, 15 Mar 2022 10:03:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647352992; 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: in-reply-to:in-reply-to:references:references; bh=MKik6AtmKkZjLoAeTfrbKw62PODykM0Fa40qjwa00Cw=; b=ZrZAqGVau8Sxjhc1470Ore8CqkcIMd+pDFtNFQrHlYA42vbX1e7hHa8W7U2QUY7hPrtHZH p8VOrwdl4jo398nH1DmNDop5BScXTBFMPBnxmIfxolAmQyPAixvwYsBHAtxWgS3CNsu14r U582pLsrl2QE/sa2sxl76NEESQgtWWs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-266-LExbIUHVMB2k-e1e--Crmg-1; Tue, 15 Mar 2022 10:03:10 -0400 X-MC-Unique: LExbIUHVMB2k-e1e--Crmg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7419380390A; Tue, 15 Mar 2022 14:03:03 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.112.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CC1AC53741; Tue, 15 Mar 2022 14:03:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 32B4B21E6821; Tue, 15 Mar 2022 15:03:02 +0100 (CET) From: Markus Armbruster To: Eric Blake Subject: Re: [PATCH 3/3] Use g_new() & friends where that makes obvious sense References: <20220314160108.1440470-1-armbru@redhat.com> <20220314160108.1440470-4-armbru@redhat.com> <20220315090748.acju5mjbe4tax272@redhat.com> Date: Tue, 15 Mar 2022 15:03:02 +0100 In-Reply-To: <20220315090748.acju5mjbe4tax272@redhat.com> (Eric Blake's message of "Tue, 15 Mar 2022 04:07:48 -0500") Message-ID: <87zglrjotl.fsf@pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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-Type: text/plain Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 , 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?Q?Herv=C3=A9?= Poussineau , Michael Roth , Anthony Perard , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , Artyom Tarasenko , Laurent Vivier , Aleksandar Rikalo , Amit Shah , Mark Cave-Ayland , haxm-team@intel.com, Richard Henderson , Greg Kurz , Fabien Chouteau , Yuval Shaia , Thomas Huth , Eric Auger , Alex Williamson , qemu-arm@nongnu.org, =?utf-8?Q?C=C3=A9dric?= Le Goater , Pavel Dovgalyuk , Paolo Bonzini , Keith Busch , qemu-ppc@nongnu.org, David Hildenbrand , Alex =?utf-8?Q?Benn=C3=A9e?= , David Gibson , Eduardo Habkost , Vladimir Sementsov-Ogievskiy , "Daniel P. =?utf-8?Q?Berrang=C3=A9?=" , qemu-block@nongnu.org, Max Filippov , qemu-s390x@nongnu.org, Patrick Venture , Cornelia Huck , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Jean-Christophe Dubois , Corey Minyard , Wenchao Wang , Igor Mammedov , "Dr. David Alan Gilbert" , Colin Xu Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Eric Blake writes: > On Mon, Mar 14, 2022 at 05:01:08PM +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... >> >> Signed-off-by: Markus Armbruster >> --- > > I agree that this is mechanical, but... > > >> qga/commands-win32.c | 8 ++--- >> qga/commands.c | 2 +- >> qom/qom-qmp-cmds.c | 2 +- >> replay/replay-char.c | 4 +-- >> replay/replay-events.c | 10 +++--- >> scripts/coverity-scan/model.c | 2 +- > > ...are we sure we want to touch this particular file? Good catch! >> diff --git a/scripts/coverity-scan/model.c b/scripts/coverity-scan/model.c >> index 9d4fba53d9..30bea672e1 100644 >> --- a/scripts/coverity-scan/model.c >> +++ b/scripts/coverity-scan/model.c >> @@ -356,7 +356,7 @@ int g_poll (GPollFD *fds, unsigned nfds, int timeout) >> typedef struct _GIOChannel GIOChannel; >> GIOChannel *g_io_channel_unix_new(int fd) >> { >> - GIOChannel *c = g_malloc0(sizeof(GIOChannel)); >> + GIOChannel *c = g_new0(GIOChannel, 1); >> __coverity_escape__(fd); >> return c; >> } > > Our model has a definition of g_malloc0(), but I'm not sure whether > Coverity picks up the macro g_new0() in the same manner. I believe it does, by parsing the macro definition from the header. Regardless, I'd prefer to keep model.c self-contained. I'll drop this hunk. Thanks!