From patchwork Mon Aug 19 16:51:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 1973915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Q0W7pAVE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-pci+bounces-11822-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WndzK23Wzz1yXf for ; Tue, 20 Aug 2024 02:56:29 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 26B411C2319D for ; Mon, 19 Aug 2024 16:56:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58EBD18A6AB; Mon, 19 Aug 2024 16:53:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q0W7pAVE" X-Original-To: linux-pci@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B682A18A92F for ; Mon, 19 Aug 2024 16:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724086394; cv=none; b=PhabgDpmsd7O6CcgmmFjpDmU86BrPFAei7y+0voDVjBmE4VKfnZ/AZ4VUF2C/2ev2OoNKIioCNCTN3icNwlQZi3VKRGIwm1TfyAAzbSurH5+vobYvUevd0Dv7vRzwMDsnacdtWOeQ6dWppxKefHOXA31aTTQiUaQAR9s4FgW53Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724086394; c=relaxed/simple; bh=kigVrUGzwAc3Gfl0QApPC++gUgBQlYDwvJKklnpQh/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EUneSjPv8k6SwdwM3mQJ2mogSS9/m+6k8FpF/umkBkNcSUg8EsT8v1t6V4PRakbFLF4Z00YmYOqWTj09EHQiIMl4whY+gYr4FA+bomDK8cWDv8verjkph/RcTBwtnC3jdE/ptOnJaUDI//E12gXvU8f8s4uyY+ah4W0gH6XbruM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q0W7pAVE; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724086391; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FEnCsYi4V2PnChy33tc28SWivSiMlK/Z32Tet3XvGFE=; b=Q0W7pAVEXSbEZ/DqGWpW54MEYdZ2mkCLJ+jCo5kCByCa5Lubg6cz68lNx3s6Hi9IR8dDve R16lX5Q3zWA1kQPCZSfHUNJ7isBlXKexFp+d6Es/+X+e5eNLVcMQ89oG5uvdlHqc0J7Hl9 IskR43jowaL1ummc8V/FEmGWOAFKTww= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-mF06Xk4qObaS646XdQWGkA-1; Mon, 19 Aug 2024 12:53:07 -0400 X-MC-Unique: mF06Xk4qObaS646XdQWGkA-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4502562fc7eso3230421cf.0 for ; Mon, 19 Aug 2024 09:53:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724086387; x=1724691187; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FEnCsYi4V2PnChy33tc28SWivSiMlK/Z32Tet3XvGFE=; b=bdK09HVJNQ2LiGeWc5IH7xA40gqLRWP2OP061DwXRxhON48u6QuIlyqNSk9UoLAdtI uct7oiX7DYbfhdQ+SdLxMcu+afA4NdkylElEnifa0xHkOj1aAZDindghsUaPRNJqmILo zWatz0Q/o3UO3CIaBjOx9078o5914k3XLbd8eTaVJFxPScJisCaKAK2sjR3D9fnMMJRv qlC/GEjYlRai2ty4gPqzvKj+XpZ0xz+KJYYGqin8XcB9AO0JrDLF46Cw8ubxt7LR9S8/ BNDjTQDQBFudXdaSQRyPMRTbkH7jJSTtsLs988N8mOiJDjOeSnE3xwvfFs5hkLSJIIFf rZSQ== X-Forwarded-Encrypted: i=1; AJvYcCWDRP8iHzew6FoLunXpD0CEsT74Ge4kUNUJlr0FezdQxXu69YFFHi92sjFxGSb49PKTgqQEyvlfGtA=@vger.kernel.org X-Gm-Message-State: AOJu0YzY6yCiu3JkaWqVdbkAA+JIO5PDELSmwpvdJ8Jm9HsVPAzp/kkE O3R7iiyNjC3NSrW/zfBg8W0Mu0T6cUPIGnQjMTRmAfaTbqZTvl9FrEH3n9LqU2uQc7M4eeDctT/ 7oOjMOAgGW5Z8nMN8EAxCw3f5hamyd/mj8vV3/fzIBNOOWYi+RKnYtFRsFg== X-Received: by 2002:a05:620a:3d08:b0:7a6:63fb:4303 with SMTP id af79cd13be357-7a663fb45efmr80661585a.10.1724086387013; Mon, 19 Aug 2024 09:53:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwAS0GQz5LBMkiUgj/6m4b5lAyO39MsqxfVGWbhZ8+Xeosey0/oxXphrfuUeFGVc2AzYTAHA== X-Received: by 2002:a05:620a:3d08:b0:7a6:63fb:4303 with SMTP id af79cd13be357-7a663fb45efmr80656985a.10.1724086386639; Mon, 19 Aug 2024 09:53:06 -0700 (PDT) Received: from eisenberg.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7a4ff01e293sm446579885a.26.2024.08.19.09.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 09:53:06 -0700 (PDT) From: Philipp Stanner To: onathan Corbet , Jens Axboe , Wu Hao , Tom Rix , Moritz Fischer , Xu Yilun , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Bjorn Helgaas , Alvaro Karsz , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Richard Cochran , Mark Brown , David Lechner , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jonathan Cameron , Philipp Stanner , Hannes Reinecke , Damien Le Moal , Chaitanya Kulkarni , "Martin K. Petersen" Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fpga@vger.kernel.org, linux-gpio@vger.kernel.org, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH 7/9] ethernet: stmicro: Simplify PCI devres usage Date: Mon, 19 Aug 2024 18:51:47 +0200 Message-ID: <20240819165148.58201-9-pstanner@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240819165148.58201-2-pstanner@redhat.com> References: <20240819165148.58201-2-pstanner@redhat.com> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 stmicro uses PCI devres in the wrong way. Resources requested through pcim_* functions don't need to be cleaned up manually in the remove() callback or in the error unwind path of a probe() function. Moreover, there is an unnecessary loop which only requests and ioremaps BAR 0, but iterates over all BARs nevertheless. Furthermore, pcim_iomap_regions() and pcim_iomap_table() have been deprecated by the PCI subsystem in commit e354bb84a4c1 ("PCI: Deprecate pcim_iomap_table(), pcim_iomap_regions_request_all()"). Replace these functions with pcim_iomap_region(). Remove the unnecessary manual pcim_* cleanup calls. Remove the unnecessary loop over all BARs. Signed-off-by: Philipp Stanner --- .../ethernet/stmicro/stmmac/dwmac-loongson.c | 25 +++++-------------- .../net/ethernet/stmicro/stmmac/stmmac_pci.c | 18 +++++-------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c index 9e40c28d453a..5d42a9fad672 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c @@ -50,7 +50,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id struct plat_stmmacenet_data *plat; struct stmmac_resources res; struct device_node *np; - int ret, i, phy_mode; + int ret, phy_mode; np = dev_of_node(&pdev->dev); @@ -88,14 +88,11 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id goto err_put_node; } - /* Get the base address of device */ - for (i = 0; i < PCI_STD_NUM_BARS; i++) { - if (pci_resource_len(pdev, i) == 0) - continue; - ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev)); - if (ret) - goto err_disable_device; - break; + memset(&res, 0, sizeof(res)); + res.addr = pcim_iomap_region(pdev, 0, pci_name(pdev)); + if (IS_ERR(res.addr)) { + ret = PTR_ERR(res.addr); + goto err_disable_device; } plat->bus_id = of_alias_get_id(np, "ethernet"); @@ -116,8 +113,6 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id loongson_default_data(plat); pci_enable_msi(pdev); - memset(&res, 0, sizeof(res)); - res.addr = pcim_iomap_table(pdev)[0]; res.irq = of_irq_get_byname(np, "macirq"); if (res.irq < 0) { @@ -158,18 +153,10 @@ static void loongson_dwmac_remove(struct pci_dev *pdev) { struct net_device *ndev = dev_get_drvdata(&pdev->dev); struct stmmac_priv *priv = netdev_priv(ndev); - int i; of_node_put(priv->plat->mdio_node); stmmac_dvr_remove(&pdev->dev); - for (i = 0; i < PCI_STD_NUM_BARS; i++) { - if (pci_resource_len(pdev, i) == 0) - continue; - pcim_iounmap_regions(pdev, BIT(i)); - break; - } - pci_disable_msi(pdev); pci_disable_device(pdev); } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c index 352b01678c22..f89a8a54c4e8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c @@ -188,11 +188,11 @@ static int stmmac_pci_probe(struct pci_dev *pdev, return ret; } - /* Get the base address of device */ + /* Request the base address BAR of device */ for (i = 0; i < PCI_STD_NUM_BARS; i++) { if (pci_resource_len(pdev, i) == 0) continue; - ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev)); + ret = pcim_request_region(pdev, i, pci_name(pdev)); if (ret) return ret; break; @@ -205,7 +205,10 @@ static int stmmac_pci_probe(struct pci_dev *pdev, return ret; memset(&res, 0, sizeof(res)); - res.addr = pcim_iomap_table(pdev)[i]; + /* Get the base address of device */ + res.addr = pcim_iomap(pdev, i, 0); + if (!res.addr) + return -ENOMEM; res.wol_irq = pdev->irq; res.irq = pdev->irq; @@ -231,16 +234,7 @@ static int stmmac_pci_probe(struct pci_dev *pdev, */ static void stmmac_pci_remove(struct pci_dev *pdev) { - int i; - stmmac_dvr_remove(&pdev->dev); - - for (i = 0; i < PCI_STD_NUM_BARS; i++) { - if (pci_resource_len(pdev, i) == 0) - continue; - pcim_iounmap_regions(pdev, BIT(i)); - break; - } } static int __maybe_unused stmmac_pci_suspend(struct device *dev)