Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp305936pxb; Tue, 19 Oct 2021 03:21:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOVg4o4vAghyL3lNVrWa40ryZhOFuuxGYG9K4fXX0E6XC/jcr44yldV7drkKAyhhmglu9S X-Received: by 2002:aa7:86d9:0:b0:44d:a354:b803 with SMTP id h25-20020aa786d9000000b0044da354b803mr23303345pfo.21.1634638885598; Tue, 19 Oct 2021 03:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634638885; cv=none; d=google.com; s=arc-20160816; b=f1btH1aOJMPiSomw7ZQp+CrTdYqifoB16GcurGymvE/wn859GbgouNtFGgJ7k4NpSS RXaV+3QdbbYb94SCbkCAM+o2vK3yMHDAczNV+De0HtoHv4z0q0lSDSVxHhio9dFNSi2K j+HxS2XG0A/JnfTatq5rwqv5J351MSidzR2DKDcoN8gljLHc2enDmqkkNcjOg714uYG0 lL0rL5P9Us69V2kzLygiseUFj3z2gyzz2oeYt9+r7M+QBJmP43Z86BuUyU40b5/07oS9 vssLedMKlYcmM9UguemNnBrb8RXNF0d/nTajnhN7hyxXz7oryiMNwkLgcGF69xsiLJIh s71w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=p6OZFW3ezrlsvIWoQgzoCARmyBJqP61SO2gxRkAy/uo=; b=SRgGwkAWQj3p54HOaFoDuCCFdwM7zdbEC8Pxi8RBkEhIRem19BGBMg9vnNC1cAkv5v m9BUZ+KTBLdY5U/QBr9sR3orFcpVaUwDjkXaJlPu1x3dBGVn5OjXM3FljbqC3TflSAgh opgvjEEqhdoJuK3Dux3ZUgXZjnkiN8H3BU17zkbgg6ThRBiGGuK8iGqMzazCpgwQJDmA enRZm6emFpFXh70iggql94Lb0w1LLfWMi/A+DNOgdVzYXAMmIeW7STV1o/jjT2/V9jGP dk54yQoJOBnV+3hahY1leOJkD8JDYZ9/6KxFhf7EdSjg/kbloi44Zqwg7Rr8LCt3OZpf NceA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x3si28022006pfh.86.2021.10.19.03.21.12; Tue, 19 Oct 2021 03:21:25 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235194AbhJSKWM (ORCPT + 99 others); Tue, 19 Oct 2021 06:22:12 -0400 Received: from mail-ua1-f48.google.com ([209.85.222.48]:43634 "EHLO mail-ua1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbhJSKWL (ORCPT ); Tue, 19 Oct 2021 06:22:11 -0400 Received: by mail-ua1-f48.google.com with SMTP id i22so2753367ual.10; Tue, 19 Oct 2021 03:19:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=p6OZFW3ezrlsvIWoQgzoCARmyBJqP61SO2gxRkAy/uo=; b=CMv4MSCjHqRUSlfvIzI1QNel+7CTWtK7AByjbxm29PMGppkQIcIA14ayL/rooAj8Ha m5EzkDAa5Ec1PjKqAihtn7DE4boAbVk+pCU3yDc7fAOP+VwmDCppjF1xoFz/2ELI1gI1 le+0JJMILhETO/xw9m277ba0BjXj/6laCvuryXJI90ryw+bV0aUHXpx/zH/LVB+AHcXC KKOvBZ+xOO3yqogtmc589H5P6/CdOwGoVy7a/9JFD5c4qZeypO9016N5VJxCDcZ+OXJI AxyWyyEJAiK/mw2dm+VGmqDbPXxlxCL82XCXyHBQp5LX8Ejkhs8jZG8md6Jm+9NnykSk wDJQ== X-Gm-Message-State: AOAM5331/NSAKzZ4bmFqfxtTRtGkZK3Qo3Vnq5pcye7STWOnWLjcAoEt WvDqODtsoeJgON1zrlRRr77JqtnJz1QWmA== X-Received: by 2002:a67:d51a:: with SMTP id l26mr33813660vsj.29.1634638797600; Tue, 19 Oct 2021 03:19:57 -0700 (PDT) Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com. [209.85.222.44]) by smtp.gmail.com with ESMTPSA id u75sm10778783vke.29.2021.10.19.03.19.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Oct 2021 03:19:57 -0700 (PDT) Received: by mail-ua1-f44.google.com with SMTP id i22so2753205ual.10; Tue, 19 Oct 2021 03:19:56 -0700 (PDT) X-Received: by 2002:a9f:29a5:: with SMTP id s34mr26300307uas.122.1634638796170; Tue, 19 Oct 2021 03:19:56 -0700 (PDT) MIME-Version: 1.0 References: <20211019095858.21316-1-Meng.Li@windriver.com> In-Reply-To: <20211019095858.21316-1-Meng.Li@windriver.com> From: Geert Uytterhoeven Date: Tue, 19 Oct 2021 12:19:45 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] pci: pcie-rcar: add regulators support To: Meng Li Cc: Magnus Damm , Rob Herring , Marek Vasut , Yoshihiro Shimoda , Lorenzo Pieralisi , =?UTF-8?Q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , Liam Girdwood , Mark Brown , Linux-Renesas , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux Kernel Mailing List , linux-pci Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Meng, On Tue, Oct 19, 2021 at 11:59 AM Meng Li wrote: > From: Andrey Gusakov > > Add PCIe regulators for KingFisher board. > > Signed-off-by: Meng Li Thanks for your patch! > arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 47 +++++++++++++++++ > drivers/pci/controller/pcie-rcar-host.c | 64 ++++++++++++++++++++++++ Please split patches touching both DT and driver sources. > --- a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi > +++ b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi > @@ -259,6 +303,9 @@ > > &pciec1 { > status = "okay"; > + > + pcie3v3-supply = <&mpcie_3v3>; > + pcie1v8-supply = <&mpcie_1v8>; This needs an update to the R-Car PCIe DT bindings first. > --- a/drivers/pci/controller/pcie-rcar-host.c > +++ b/drivers/pci/controller/pcie-rcar-host.c > @@ -893,6 +896,36 @@ static const struct of_device_id rcar_pcie_of_match[] = { > {}, > }; > > +static int rcar_pcie_set_vpcie(struct rcar_pcie_host *host) > +{ > + struct device *dev = host->pcie.dev; > + int err; > + > + if (!IS_ERR(host->pcie3v3)) { > + err = regulator_enable(host->pcie3v3); This will crash if host->pcie3v3 is NULL (optional regulator not present). Probably you just want to check for non-NULL (see below). > + if (err) { > + dev_err(dev, "fail to enable vpcie3v3 regulator\n"); > + goto err_out; > + } > + } > + > + if (!IS_ERR(host->pcie1v8)) { > + err = regulator_enable(host->pcie1v8); Likewise. > + if (err) { > + dev_err(dev, "fail to enable vpcie1v8 regulator\n"); > + goto err_disable_3v3; > + } > + } > + > + return 0; > + > +err_disable_3v3: > + if (!IS_ERR(host->pcie3v3)) Likewise. > + regulator_disable(host->pcie3v3); > +err_out: > + return err; > +} > + > static int rcar_pcie_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -911,6 +944,31 @@ static int rcar_pcie_probe(struct platform_device *pdev) > pcie->dev = dev; > platform_set_drvdata(pdev, host); > > + host->pcie3v3 = devm_regulator_get_optional(dev, "pcie3v3"); > + if (IS_ERR(host->pcie3v3)) { > + if (PTR_ERR(host->pcie3v3) == -EPROBE_DEFER) { > + pci_free_host_bridge(bridge); Please drop this. As the bridge was allocated using devm_pci_alloc_host_bridge(), freeing it manually will cause a double free. > + return -EPROBE_DEFER; > + } > + dev_info(dev, "no pcie3v3 regulator found\n"); devm_regulator_get_optional() returns NULL if the regulator was not found. Hence if IS_ERR() is true, this indicates a real error, which you should handle: if (IS_ERR(host->pcie3v3)) return PTR_ERR(host->pcie3v3); > + } > + > + host->pcie1v8 = devm_regulator_get_optional(dev, "pcie1v8"); > + if (IS_ERR(host->pcie1v8)) { > + if (PTR_ERR(host->pcie1v8) == -EPROBE_DEFER) { > + pci_free_host_bridge(bridge); > + return -EPROBE_DEFER; > + } > + dev_info(dev, "no pcie1v8 regulator found\n"); Likewise. > + } > + > + err = rcar_pcie_set_vpcie(host); > + if (err) { > + dev_err(dev, "failed to set pcie regulators\n"); > + pci_free_host_bridge(bridge); Please drop this to avoid double free. > + return err; > + } > + > pm_runtime_enable(pcie->dev); > err = pm_runtime_get_sync(pcie->dev); > if (err < 0) { > @@ -985,6 +1043,12 @@ static int rcar_pcie_probe(struct platform_device *pdev) > irq_dispose_mapping(host->msi.irq1); > > err_pm_put: > + if(!IS_ERR(host->pcie3v3)) if (host->pcie3v3) > + if (regulator_is_enabled(host->pcie3v3)) If you get here, the regulator should be enabled? > + regulator_disable(host->pcie3v3); > + if(!IS_ERR(host->pcie1v8)) if (host->pcie1v8) > + if (regulator_is_enabled(host->pcie1v8)) > + regulator_disable(host->pcie1v8); Please move this below the call to pm_runtime_disable(), to preserve symmetry. > pm_runtime_put(dev); > pm_runtime_disable(dev); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds