From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AAAFFA0543; Mon, 21 Nov 2022 09:44:42 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4EF2240150; Mon, 21 Nov 2022 09:44:42 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 1FA414014F for ; Mon, 21 Nov 2022 09:44:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669020279; 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=viuZnaRIhbrgyol4qObeQr03zolOKwittbTf9L1HS8M=; b=HKxJT97p5AE0mN0leVS7f6l1VOpc35ScfY6wfpXi21BVpi/EH+MJZVRhiJPXYrfdXRX92r Xa8l8eM4h8YZzZT5vFZXZYK/Gv8LiCR8lKDzQDwkjcS3an0WiNqmH9TstKjM8h04drR+1r 1a3Khp6xx6Mg6NdwSCnBkY+aGaaERsA= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-650-C9yF42nZNR2RHGlWZmQ5bw-1; Mon, 21 Nov 2022 03:44:34 -0500 X-MC-Unique: C9yF42nZNR2RHGlWZmQ5bw-1 Received: by mail-pl1-f199.google.com with SMTP id h16-20020a170902f55000b001871b770a83so8895973plf.9 for ; Mon, 21 Nov 2022 00:44:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=viuZnaRIhbrgyol4qObeQr03zolOKwittbTf9L1HS8M=; b=jQcgMF+csIrTfJ+fzeCz3UhST19YTiVKcbtIohMuxw8qguzJsrXQIm5zi/6caZXW6g qbm5Kq9yhKHgnHrG3Fa1c0wFb4vtkTRoaFaLkzbvv0XZRK4CqO0YxRSeRX5X76gpdeBn /erOnnaBvvJhFophRVUJvVqePEZ50Wx6xzIEPQJzutz/TFQlztj83pGzD+ZoqUEhluKO tnuQT6tjOsLSi9MaJq7Lg/OWeakQny/Kkw+T4Ly/pJzvY5F+wq6c7F3ppczdXjOrDlIy ReqzFTw8XUVEd8okmgyYLSypuXnfmeKG0w/xMOYD7wemu7srMU6zzm+NPAZ4PWlNCQiK HlSA== X-Gm-Message-State: ANoB5pkIRlH0ijh+4bUvPT+GTqHDha+B5h2qQ8tTpfv/g35BwNAjYx50 dOwJT2f9GCEcfvUEsC133B5wvYpFJRZfrfduR/wTzusAGSk4ur4klLbqdwwwJEn4oHMcgmMbm8y 6lJ0K0T1iIki+utzQlEI= X-Received: by 2002:a17:902:8e81:b0:188:4f86:e4d5 with SMTP id bg1-20020a1709028e8100b001884f86e4d5mr3316612plb.16.1669020273477; Mon, 21 Nov 2022 00:44:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AgmWT2InXz4Y/3mQ7zFRY7NXjBUTW9o9Km0RaAQRSJEUOzUWwoak4fTbIMf6o3OWReQ27WzcB+I/U/7d79O0= X-Received: by 2002:a17:902:8e81:b0:188:4f86:e4d5 with SMTP id bg1-20020a1709028e8100b001884f86e4d5mr3316599plb.16.1669020273148; Mon, 21 Nov 2022 00:44:33 -0800 (PST) MIME-Version: 1.0 References: <20221118133547.1203417-1-tomasz.zawadzki@intel.com> In-Reply-To: <20221118133547.1203417-1-tomasz.zawadzki@intel.com> From: David Marchand Date: Mon, 21 Nov 2022 09:44:21 +0100 Message-ID: Subject: Re: [PATCH] bus/pci: fix bus info memleak during PCI scan To: Tomasz Zawadzki Cc: Bruce Richardson , dev@dpdk.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Fri, Nov 18, 2022 at 2:36 PM Tomasz Zawadzki wrote: > > During pci_scan_one() for devices that were already registered > the pci_common_set() is called to set some of the fields again. > > This resulted in bus_info allocation leaking, so this patch > ensures they are always freed beforehand. > > Fixes: 8f4de2dba9b9 ("bus/pci: fill bus specific information") > > Signed-off-by: Tomasz Zawadzki > --- > drivers/bus/pci/pci_common.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c > index 9901c34f4e..9a866055e8 100644 > --- a/drivers/bus/pci/pci_common.c > +++ b/drivers/bus/pci/pci_common.c > @@ -114,6 +114,7 @@ pci_common_set(struct rte_pci_device *dev) > /* Otherwise, it uses the internal, canonical form. */ > dev->device.name = dev->name; > > + free(dev->bus_info); > if (asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16, > dev->id.vendor_id, dev->id.device_id) != -1) > dev->device.bus_info = dev->bus_info; Indeed, good catch. The bus_info content is constant for a given device, there is no need to free and reallocate. WDYT of: @@ -114,8 +114,9 @@ pci_common_set(struct rte_pci_device *dev) /* Otherwise, it uses the internal, canonical form. */ dev->device.name = dev->name; - if (asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16, - dev->id.vendor_id, dev->id.device_id) != -1) + if (dev->bus_info != NULL || + asprintf(&dev->bus_info, "vendor_id=%"PRIx16", device_id=%"PRIx16, + dev->id.vendor_id, dev->id.device_id) != -1) dev->device.bus_info = dev->bus_info; } -- David Marchand