Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp417166pxj; Tue, 18 May 2021 06:21:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK26mxXzUTZuM3czjaujULfweRcmX2DQ2TdPkM7TzRqzJpXnFvSBPHYk0l1nS3OsIKiYs5 X-Received: by 2002:a92:b12:: with SMTP id b18mr4449651ilf.100.1621344116598; Tue, 18 May 2021 06:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621344116; cv=none; d=google.com; s=arc-20160816; b=yn5Rcc+KaNbi9jNnVhTt0sDlIA5QS5eB9Edhm/IsiYS41ivQNP4PiEnGsBMwMCkHwM MFyCGm7uOw1StqpA3k4WD5/hnDHYSD6WJG57Hy6e6DRXnmrqJzN3lOW5FS/aoo+ZRnoV BbI/47EVOPKtS7kNr3cB7ogk3blDV+ceu61zr7J91PzskZ+LbytcKXJbR1mC2Gg+07a1 cvDrxjTUe5nMIr4LhCx4yOPnfptlTTmzHC9glgP4fOT8lSomdTYCJkcApjTag9HBajG6 HeEsLdQZ+wIjOPUvRSAQYDEIeiCsngCA+M3zFQ3VGG8q8gQ3WLvlanUDsuzv6LtEnx2F RBLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UTsYE/rT1Q60HRe/rGgxsztL7vxVJpFCcBEujii0amo=; b=dsmwxGEMIIcQ13Ub+CjdI1g2NQiIdOlKMTfTRhlyoDU0bDpCTKYpnissi1Q76ghCel Tp+SaqZtITl6FFnFUIvJaw6VUwKuqqL163Hmdasdmf/Xn8A/cx1BvyXwjYDbJG5+UQ2F ed56Vh5OKSr2WJr2kgBWqcVZtqNmY411kAdusEf/wzIOV71e215JC54nfq0P3iPPKDBj +vVMsN5xBRH6pca5vuG7lbzgXkgb9QlmVaBaKBeNE0njf38D2EKdmWL2+EZmdHq9yrbI deVm7CTRqGhi/7mqE2uzUnIbu0x7iwBJOBEQ2QqkUYl6iazMVBz0GLyQIHDCzJnTuCLG Q/Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DyWUARRn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d8si8831962ilo.3.2021.05.18.06.21.44; Tue, 18 May 2021 06:21:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DyWUARRn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244770AbhEQPhb (ORCPT + 99 others); Mon, 17 May 2021 11:37:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:59456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244777AbhEQPV7 (ORCPT ); Mon, 17 May 2021 11:21:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EF2EE61C90; Mon, 17 May 2021 14:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262087; bh=W3FEbENxfXbapjFneGrNZsLEO7lZH0RT9gJOBiepoMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DyWUARRnO+vggWfxrtpk72S0Ay8Fb5B2Ohbm42Plyek1Ywy4uw36qeLx0CcAxLv0R aoZQ1cB5ky1q7atB1stjM2yfXqIR6Spk9ew6hl5mM9WTLGQqQl836KNwP+TjlLg2iK v2yJ3R6kEBWoJJHdDoGekcoJnuRVLY6UafkVjQ4I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kishon Vijay Abraham I , Lorenzo Pieralisi , Bjorn Helgaas , Sasha Levin Subject: [PATCH 5.10 109/289] PCI: endpoint: Make *_free_bar() to return error codes on failure Date: Mon, 17 May 2021 16:00:34 +0200 Message-Id: <20210517140308.850030531@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kishon Vijay Abraham I [ Upstream commit 0e27aeccfa3d1bab7c6a29fb8e6fcedbad7b09a8 ] Modify pci_epc_get_next_free_bar() and pci_epc_get_first_free_bar() to return error values if there are no free BARs available. Link: https://lore.kernel.org/r/20210201195809.7342-5-kishon@ti.com Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Lorenzo Pieralisi Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/endpoint/functions/pci-epf-test.c | 2 ++ drivers/pci/endpoint/pci-epc-core.c | 12 ++++++------ include/linux/pci-epc.h | 8 ++++---- include/linux/pci-epf.h | 1 + 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index e4e51d884553..7a1f3abfde48 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -834,6 +834,8 @@ static int pci_epf_test_bind(struct pci_epf *epf) linkup_notifier = epc_features->linkup_notifier; core_init_notifier = epc_features->core_init_notifier; test_reg_bar = pci_epc_get_first_free_bar(epc_features); + if (test_reg_bar < 0) + return -EINVAL; pci_epf_configure_bar(epf, epc_features); } diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 1afe5d9afb0d..ea7e7465ce7a 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -90,8 +90,8 @@ EXPORT_SYMBOL_GPL(pci_epc_get); * Invoke to get the first unreserved BAR that can be used by the endpoint * function. For any incorrect value in reserved_bar return '0'. */ -unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features - *epc_features) +enum pci_barno +pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features) { return pci_epc_get_next_free_bar(epc_features, BAR_0); } @@ -105,13 +105,13 @@ EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar); * Invoke to get the next unreserved BAR starting from @bar that can be used * for endpoint function. For any incorrect value in reserved_bar return '0'. */ -unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features - *epc_features, enum pci_barno bar) +enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features + *epc_features, enum pci_barno bar) { unsigned long free_bar; if (!epc_features) - return 0; + return BAR_0; /* If 'bar - 1' is a 64-bit BAR, move to the next BAR */ if ((epc_features->bar_fixed_64bit << 1) & 1 << bar) @@ -126,7 +126,7 @@ unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features free_bar = find_next_zero_bit(&free_bar, 6, bar); if (free_bar > 5) - return 0; + return NO_BAR; return free_bar; } diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index cfe9b427e6b7..88d311bad984 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -201,10 +201,10 @@ int pci_epc_start(struct pci_epc *epc); void pci_epc_stop(struct pci_epc *epc); const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc, u8 func_no); -unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features - *epc_features); -unsigned int pci_epc_get_next_free_bar(const struct pci_epc_features - *epc_features, enum pci_barno bar); +enum pci_barno +pci_epc_get_first_free_bar(const struct pci_epc_features *epc_features); +enum pci_barno pci_epc_get_next_free_bar(const struct pci_epc_features + *epc_features, enum pci_barno bar); struct pci_epc *pci_epc_get(const char *epc_name); void pci_epc_put(struct pci_epc *epc); diff --git a/include/linux/pci-epf.h b/include/linux/pci-epf.h index 6644ff3b0702..fa3aca43eb19 100644 --- a/include/linux/pci-epf.h +++ b/include/linux/pci-epf.h @@ -21,6 +21,7 @@ enum pci_notify_event { }; enum pci_barno { + NO_BAR = -1, BAR_0, BAR_1, BAR_2, -- 2.30.2