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 X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 218A2C433FE for ; Mon, 7 Dec 2020 10:38:56 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BAB4D23339 for ; Mon, 7 Dec 2020 10:38:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BAB4D23339 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.46196.81972 (Exim 4.92) (envelope-from ) id 1kmDum-0008Jw-0i; Mon, 07 Dec 2020 10:38:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 46196.81972; Mon, 07 Dec 2020 10:38:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kmDul-0008Jp-TJ; Mon, 07 Dec 2020 10:38:43 +0000 Received: by outflank-mailman (input) for mailman id 46196; Mon, 07 Dec 2020 10:38:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kmDuk-0008JN-0g for xen-devel@lists.xenproject.org; Mon, 07 Dec 2020 10:38:42 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 36e9e0d0-0900-4a11-ba07-6623289f4d0a; Mon, 07 Dec 2020 10:38:41 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F00DAAC90; Mon, 7 Dec 2020 10:38:39 +0000 (UTC) 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: 36e9e0d0-0900-4a11-ba07-6623289f4d0a X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1607337520; h=from:from:reply-to: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=eMaRwYz5dvWjnaq+mpxQL4O/edeAvh/v0+ETeYdF/Bs=; b=k52pv2vR8IpMuzkQozOyWQFM7qLtIAIPtOoBi3rDcDplqXnRKOu3hn3IUS7BWcV3Y5QNQJ +XyDanG+NWa9lyAcf5knGIkZieajrFi+GZ4O+/8YMe8ceApkfWnfEjanKygngouvO1knNn fFL1D8wVpoPsrWFCQWYv5vrM+yFmMNI= Subject: [PATCH 5/5] vPCI/MSI-X: tidy init_msix() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: Message-ID: Date: Mon, 7 Dec 2020 11:38:42 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit First of all introduce a local variable for the to be allocated struct. The compiler can't CSE all the occurrences (I'm observing 80 bytes of code saved with gcc 10). Additionally, while the caller can cope and there was no memory leak, globally "announce" the struct only once done initializing it. This also removes the dependency of the function on the caller cleaning up after it in case of an error. Signed-off-by: Jan Beulich --- I was heavily tempted to also move up the call to vpci_add_register(), such that there would be no pointless init done in case of an error coming back from there. --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -436,6 +436,7 @@ static int init_msix(struct pci_dev *pde uint8_t slot = PCI_SLOT(pdev->devfn), func = PCI_FUNC(pdev->devfn); unsigned int msix_offset, i, max_entries; uint16_t control; + struct vpci_msix *msix; int rc; msix_offset = pci_find_cap_offset(pdev->seg, pdev->bus, slot, func, @@ -447,34 +448,37 @@ static int init_msix(struct pci_dev *pde max_entries = msix_table_size(control); - pdev->vpci->msix = xzalloc_flex_struct(struct vpci_msix, entries, - max_entries); - if ( !pdev->vpci->msix ) + msix = xzalloc_flex_struct(struct vpci_msix, entries, max_entries); + if ( !msix ) return -ENOMEM; - pdev->vpci->msix->max_entries = max_entries; - pdev->vpci->msix->pdev = pdev; + msix->max_entries = max_entries; + msix->pdev = pdev; - pdev->vpci->msix->tables[VPCI_MSIX_TABLE] = + msix->tables[VPCI_MSIX_TABLE] = pci_conf_read32(pdev->sbdf, msix_table_offset_reg(msix_offset)); - pdev->vpci->msix->tables[VPCI_MSIX_PBA] = + msix->tables[VPCI_MSIX_PBA] = pci_conf_read32(pdev->sbdf, msix_pba_offset_reg(msix_offset)); - for ( i = 0; i < pdev->vpci->msix->max_entries; i++) + for ( i = 0; i < msix->max_entries; i++) { - pdev->vpci->msix->entries[i].masked = true; - vpci_msix_arch_init_entry(&pdev->vpci->msix->entries[i]); + msix->entries[i].masked = true; + vpci_msix_arch_init_entry(&msix->entries[i]); } rc = vpci_add_register(pdev->vpci, control_read, control_write, - msix_control_reg(msix_offset), 2, pdev->vpci->msix); + msix_control_reg(msix_offset), 2, msix); if ( rc ) + { + xfree(msix); return rc; + } if ( list_empty(&d->arch.hvm.msix_tables) ) register_mmio_handler(d, &vpci_msix_table_ops); - list_add(&pdev->vpci->msix->next, &d->arch.hvm.msix_tables); + pdev->vpci->msix = msix; + list_add(&msix->next, &d->arch.hvm.msix_tables); return 0; }