Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B826C4338F for ; Sun, 15 Aug 2021 14:37:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E2B2260295 for ; Sun, 15 Aug 2021 14:37:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E2B2260295 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:46112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mFHGO-0007hO-5H for qemu-devel@archiver.kernel.org; Sun, 15 Aug 2021 10:37:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFHFT-0006rC-Ka for qemu-devel@nongnu.org; Sun, 15 Aug 2021 10:36:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mFHFR-0004O9-P6 for qemu-devel@nongnu.org; Sun, 15 Aug 2021 10:36:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629038184; 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=krZuGdBwN2AUJT/Dr/pk66keT8rWFwV+4RGKZFubi2c=; b=MskC2n+w6sJyB8FM+pfV3bhW2jsyiOSGejzGQN+tFly8i+N3JHsQtofWezHMcAg1+xYfat /sLhLrP67KJeqYgdnYqskJWljFllG6ZGpdq3s79nD+IibPI2IBu5R39cvztaLr9uUND/GF Ed7H9tnTYbFOxVYdF13WWHRH+uQH/QQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-Z9RVjL3-OFKeXUTN4NJv8Q-1; Sun, 15 Aug 2021 10:36:21 -0400 X-MC-Unique: Z9RVjL3-OFKeXUTN4NJv8Q-1 Received: by mail-wr1-f69.google.com with SMTP id a14-20020adfe5ce000000b00156c49c4a23so36911wrn.15 for ; Sun, 15 Aug 2021 07:36:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=krZuGdBwN2AUJT/Dr/pk66keT8rWFwV+4RGKZFubi2c=; b=jiOZX/NKHz4NASUTSJPJHkFp3jRDBKJyG8FO4Seq/fJCsfW4oZWqOxCeIWEhlq10fh FIDeVvQlQnaNyK1n1RmPSAqpUyDe1q2w6O+LsI8FlvwCnaZFslUBKtUmOVQo1YUBqM7R e1M+muK1TQJWsYPEaoQiFMB3GmLrElbm18YS2dVpH22Q7zXJsvc/YhbgKz2L8bAcNxQZ RL5a10AxGuvxHccCfqibTWGdIMPgsEjLrYTxqOjuPx2PMEKGL/TV9AhLrBM73v+dNldE Yvrmzsd96Pv1EEmI3jKUvfv0IdWllZYwCQoE9VbEjFFOBal6dIP2BI02hbF9SJCdkWzA uUMg== X-Gm-Message-State: AOAM5313KeX31XN4AujODr0wUBnoNHlp/qgnBeLnc/zNd+tWDZZgmLvg g3vmvjFTvl3v4zpcfgieaO7RO7ED9zv8Qva24ERzB5PnOlyhlOiONq50djLdqb9yaZghnKTrQ6t YXB5RaxaLXXTO6DI= X-Received: by 2002:a1c:7dd0:: with SMTP id y199mr11123683wmc.23.1629038180108; Sun, 15 Aug 2021 07:36:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+teC6ABqNJgzB4CWD2xoh21KsbIva1b3abMQKdVBgCw8SSAXtY5+FDlInHM20K6TIAaX/zg== X-Received: by 2002:a1c:7dd0:: with SMTP id y199mr11123673wmc.23.1629038179893; Sun, 15 Aug 2021 07:36:19 -0700 (PDT) Received: from [192.168.1.36] (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id b15sm8298459wrq.5.2021.08.15.07.36.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Aug 2021 07:36:19 -0700 (PDT) Subject: Re: [PULL 24/30] spapr_pci: populate ibm,loc-code To: Peter Maydell , David Gibson References: <1436284182-5063-1-git-send-email-agraf@suse.de> <1436284182-5063-25-git-send-email-agraf@suse.de> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: <1daaacdf-4725-3350-601f-24025d3944f4@redhat.com> Date: Sun, 15 Aug 2021 16:36:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -55 X-Spam_score: -5.6 X-Spam_bar: ----- X-Spam_report: (-5.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-2.147, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc , QEMU Developers , Nikunj A Dadhania , Greg Kurz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 8/13/21 5:17 PM, Peter Maydell wrote: > On Tue, 10 Aug 2021 at 05:40, David Gibson wrote: >> >> On Mon, Aug 09, 2021 at 10:57:00AM +0100, Peter Maydell wrote: >>> >>> Cleanest fix would be to declare 'path' and 'host' as >>> g_autofree char *path = NULL; >>> g_autofree char *host = NULL; >>> and then you can remove all the manual g_free(path) and g_free(host) calls. >> >> Thanks for the report. I've committed the fix (I hope) below to ppc-for-6.1: >> >> From 70ae61b510dc571c407b28c46498cae60e60ca66 Mon Sep 17 00:00:00 2001 >> From: David Gibson >> Date: Tue, 10 Aug 2021 14:28:19 +1000 >> Subject: [PATCH] spapr_pci: Fix leak in spapr_phb_vfio_get_loc_code() with >> g_autofree >> >> This uses g_autofree to simplify logic in spapr_phb_vfio_get_loc_code(), >> in the process fixing a leak in one of the paths. I'm told this fixes >> Coverity error CID 1460454 >> >> Reported-by: Peter Maydell >> Fixes: 16b0ea1d852 ("spapr_pci: populate ibm,loc-code") >> Signed-off-by: David Gibson >> --- >> hw/ppc/spapr_pci.c | 17 ++++++----------- >> 1 file changed, 6 insertions(+), 11 deletions(-) >> >> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c >> index 7a725855f9..13d806f390 100644 >> --- a/hw/ppc/spapr_pci.c >> +++ b/hw/ppc/spapr_pci.c >> @@ -782,33 +782,28 @@ static AddressSpace *spapr_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn) >> >> static char *spapr_phb_vfio_get_loc_code(SpaprPhbState *sphb, PCIDevice *pdev) >> { >> - char *path = NULL, *buf = NULL, *host = NULL; >> + g_autofree char *path = NULL; >> + g_autofree char *host = NULL; >> + char *buf = NULL; >> >> /* Get the PCI VFIO host id */ >> host = object_property_get_str(OBJECT(pdev), "host", NULL); >> if (!host) { >> - goto err_out; >> + return NULL; >> } >> >> /* Construct the path of the file that will give us the DT location */ >> path = g_strdup_printf("/sys/bus/pci/devices/%s/devspec", host); >> - g_free(host); >> if (!g_file_get_contents(path, &buf, NULL, NULL)) { >> - goto err_out; >> + return NULL; >> } >> - g_free(path); >> >> /* Construct and read from host device tree the loc-code */ >> path = g_strdup_printf("/proc/device-tree%s/ibm,loc-code", buf); >> - g_free(buf); > > This deletion doesn't look right -- 'buf' is not autofree > (and shouldn't be, since we're returning it). Oops, good catch! > If you want to delete this 'g_free' you need to make the > first g_file_get_contents() use a separate char* variable from > the variable we use to return the eventual result data buffer; > then you can make that new variable be g_autofree. > >> if (!g_file_get_contents(path, &buf, NULL, NULL)) { >> - goto err_out; >> + return NULL; >> } >> return buf; >> - >> -err_out: >> - g_free(path); >> - return NULL; >> } > > thanks > -- PMM >