From patchwork Mon Nov 21 11:12:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 119990 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 65B7AA055B; Mon, 21 Nov 2022 12:12:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 08F7040150; Mon, 21 Nov 2022 12:12:28 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C95644014F for ; Mon, 21 Nov 2022 12:12:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669029146; 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; bh=cKkxYACPp/zP071PElPb0qyv+LehklsN7XRzboyWCpw=; b=UCq01wiXuybTBaNIrmqdMwoRgaiXC2SSyRPuve7Vv2OJc4UbtWgH3wFX4+AxCIULefXOUf dZQQ465MbBQ4Ffga74Qjfs2rEEjo51BLZ6TXNNkmiASWsVd64jPw6YSjLzQ7CbiQYGtG/n Sw5ksQNKYcotTGC+O6AbOsrZ4ZAVHP4= 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-37-RWPPvae-PFmvsErf3af0EQ-1; Mon, 21 Nov 2022 06:12:20 -0500 X-MC-Unique: RWPPvae-PFmvsErf3af0EQ-1 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 B9829801585; Mon, 21 Nov 2022 11:12:19 +0000 (UTC) Received: from localhost.localdomain (ovpn-193-7.brq.redhat.com [10.40.193.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3F3B1121315; Mon, 21 Nov 2022 11:12:18 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Tomasz Zawadzki , Bruce Richardson Subject: [PATCH] bus/pci: fix leak with multiple bus scan Date: Mon, 21 Nov 2022 12:12:09 +0100 Message-Id: <20221121111209.2396341-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 The addition of the bus_info field did not account for the fact that the PCI bus can be scanned multiple times (like for device hotplug and other uses in SPDK). Indeed, during pci_scan_one() for devices that were already registered, the pci_common_set() overwrites the bus_info field, leaking the previously allocated memory. Since the bus_info content is fixed for a PCI device, we can simply skip allocation if dev->bus_info is already set. Fixes: 8f4de2dba9b9 ("bus/pci: fill bus specific information") Reported-by: Tomasz Zawadzki Signed-off-by: David Marchand --- drivers/bus/pci/pci_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 9901c34f4e..bc3a7f39fe 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -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; }