Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2574053imu; Sun, 13 Jan 2019 05:20:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN4vuRTByjDGYOlTyWDoVF0FNoqfu1wqSvwcVtoBbxSiEe5GPA+16zNhFVD9+9Skro0ThL96 X-Received: by 2002:a63:cf48:: with SMTP id b8mr19963359pgj.17.1547385623503; Sun, 13 Jan 2019 05:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547385623; cv=none; d=google.com; s=arc-20160816; b=VhuSgtlm0phB68GAZd5yCzZ9IOLwbuH150inqUY+tWnvbakOUkcxLwA16yQ7ZLoxp1 pjGWIL7/Didyo70XDbSxQfVtZAlwaX4lL90s6oMqsY8bX+4SI/J3XLqKCVwlcL9OwpLg Ch+teyU1XpIi75Jsd8c5g5uYgn8wh8DcPizy8P2PY88i6gaZldl1VQoSAa3oIgt2jzJi tOfzS/t9MLau89V36jv58liZZO9R+yI9fCN/1Ividjf2YIFZ1tV6WghaoIDVKO+5W74U KZad9bibP/uGcmJKxWUQoVqX4T+4QpXEj3OG1C4QmTa8LlDUFg+oyin1OVR7AV0za9zM FE1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=sj2yl12XwnlmuTBSUD39ITwnN4hJNRs0KZpiRmJxOSo=; b=O5BahkwlLJM9VnCngkMUkyxXmofexbMmsCTDFkxfw2dNh+yXsobu5iB43emuzgylSt kvMMEqTNeqEYQPco2BDOpefEAx5eivF5NH+JccHepfjYT/kjsYqNpeKZmgTsE26l8yYu 7nFwi/LnUyM1IB/DCOVSTjaNx5dNdnZ6gSUbnrsH50Bz9f4HXGXQm/gh1xn+PqI2+i/u LFM75AhHAj/N1qSk9kf1hJ3dIB9ZfVuh1q+DfvTD8DBMf6Kc7g+uCJ3fWD10JcADXu5J x/V0Cot0xkcHyjZEO0k7+DbHeW36D9bW02FKyXQDsQSyMj3ViVWNWLmbYxvd1PeOXL0b RkJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t13si30671857pgm.175.2019.01.13.05.19.52; Sun, 13 Jan 2019 05:20:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726599AbfAMNQa convert rfc822-to-8bit (ORCPT + 99 others); Sun, 13 Jan 2019 08:16:30 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:36893 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbfAMNQa (ORCPT ); Sun, 13 Jan 2019 08:16:30 -0500 Received: by mail-ed1-f65.google.com with SMTP id h15so16599904edb.4; Sun, 13 Jan 2019 05:16:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=JjL7eeMXMIM7Zm7I/VKfxBqNJX9ibDYcknfQzbkZmdU=; b=uYfuE1kRL77UDB/tFt/p8qItSE71w0lCTaohrMncXYm3PFpyys1ePqRxkvJ9Q/ZrkV 4MSvpoYpFk2wel0w4Osio6UpJ2SwSx8XOyLlzsIjcm9xjOdFjLqgdYj0vTxECG3+WXqs ST1Wp0TWCzMJ5uqv/4uRsXlSkG9epqHemvybJEg024RBQHN1rWkNg5hvijbWIzAfqk61 SvJHQnmD4nW7yZ+i/GCeVQfYN5i8/Cf5WC0g0uhOZxje5aKztr8fcXw/R/amiy3RxeV7 H5m7m6z3cH+r822tUxHZbh1iNNkXLdFTD8itX7NTJlfSaoifl+3Y+t2Nc1OXAiYM4npT bq2g== X-Gm-Message-State: AJcUukek3c8K+XVVEPUYzCIvyU5vKaiuHYjaNHcA05tcnNe8EcpsYJ9q eQT/G9ArrXgeCxqwtccbASc= X-Received: by 2002:a50:a3d1:: with SMTP id t17mr20083256edb.238.1547385387362; Sun, 13 Jan 2019 05:16:27 -0800 (PST) Received: from kozik-lap ([194.230.155.148]) by smtp.googlemail.com with ESMTPSA id r18-v6sm2065927ejz.22.2019.01.13.05.16.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Jan 2019 05:16:26 -0800 (PST) Date: Sun, 13 Jan 2019 14:16:24 +0100 From: Krzysztof Kozlowski To: =?utf-8?B?UGF3ZcWC?= Chmiel Cc: kgene@kernel.org, viresh.kumar@linaro.org, rjw@rjwysocki.net, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] cpufreq: s5pv210: Defer probe if getting regulators fail Message-ID: <20190113131624.GA2672@kozik-lap> References: <20190111194244.2439-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20190111194244.2439-1-pawel.mikolaj.chmiel@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 11, 2019 at 08:42:44PM +0100, Paweł Chmiel wrote: > There is possibility, that when probing driver, regulators are not yet > initialized. In this case we should return EPROBE_DEFER and wait till > they're initialized, since they're required currently for cpufreq driver > to work. Also move regulator initialization code at beginning of probe, > so we can defer as fast as posibble. > > Signed-off-by: Paweł Chmiel > --- > Changes from v2: > - Handle all error paths in probe > > Changes from v1: > - Fix compilation error > - Reorganize code so it's smaller > --- > drivers/cpufreq/s5pv210-cpufreq.c | 68 ++++++++++++++++++++++--------- > 1 file changed, 49 insertions(+), 19 deletions(-) > > diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c > index f51697f1e0b3..627b132e3e61 100644 > --- a/drivers/cpufreq/s5pv210-cpufreq.c > +++ b/drivers/cpufreq/s5pv210-cpufreq.c > @@ -584,7 +584,7 @@ static struct notifier_block s5pv210_cpufreq_reboot_notifier = { > static int s5pv210_cpufreq_probe(struct platform_device *pdev) > { > struct device_node *np; > - int id; > + int id, result = 0; > > /* > * HACK: This is a temporary workaround to get access to clock > @@ -594,18 +594,40 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev) > * this whole driver as soon as S5PV210 gets migrated to use > * cpufreq-dt driver. > */ > + arm_regulator = regulator_get(NULL, "vddarm"); > + if (IS_ERR(arm_regulator)) { > + if (PTR_ERR(arm_regulator) == -EPROBE_DEFER) > + pr_debug("vddarm regulator not ready, defer\n"); > + else > + pr_err("failed to get regulator vddarm\n"); > + result = PTR_ERR(arm_regulator); > + goto err_arm_regulator; Just return here. > + } > + > + int_regulator = regulator_get(NULL, "vddint"); > + if (IS_ERR(int_regulator)) { > + if (PTR_ERR(int_regulator) == -EPROBE_DEFER) > + pr_debug("vddint regulator not ready, defer\n"); > + else > + pr_err("failed to get regulator vddint\n"); > + result = PTR_ERR(int_regulator); > + goto err_int_regulator; > + } > + > np = of_find_compatible_node(NULL, NULL, "samsung,s5pv210-clock"); > if (!np) { > pr_err("%s: failed to find clock controller DT node\n", > __func__); > - return -ENODEV; > + result = -ENODEV; > + goto err_clock; > } > > clk_base = of_iomap(np, 0); > of_node_put(np); > if (!clk_base) { > pr_err("%s: failed to map clock registers\n", __func__); > - return -EFAULT; > + result = -EFAULT; > + goto err_clock; > } > > for_each_compatible_node(np, NULL, "samsung,s5pv210-dmc") { > @@ -614,7 +636,8 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev) > pr_err("%s: failed to get alias of dmc node '%pOFn'\n", > __func__, np); > of_node_put(np); > - return id; > + result = id; > + goto err_clk_base; > } > > dmc_base[id] = of_iomap(np, 0); > @@ -622,33 +645,40 @@ static int s5pv210_cpufreq_probe(struct platform_device *pdev) > pr_err("%s: failed to map dmc%d registers\n", > __func__, id); > of_node_put(np); > - return -EFAULT; > + result = -EFAULT; > + goto err_dmc; > } > } > > for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) { > if (!dmc_base[id]) { > pr_err("%s: failed to find dmc%d node\n", __func__, id); > - return -ENODEV; > + result = -ENODEV; > + goto err_dmc; > } > } > > - arm_regulator = regulator_get(NULL, "vddarm"); > - if (IS_ERR(arm_regulator)) { > - pr_err("failed to get regulator vddarm\n"); > - return PTR_ERR(arm_regulator); > - } > - > - int_regulator = regulator_get(NULL, "vddint"); > - if (IS_ERR(int_regulator)) { > - pr_err("failed to get regulator vddint\n"); > - regulator_put(arm_regulator); > - return PTR_ERR(int_regulator); > - } > - > register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier); > > return cpufreq_register_driver(&s5pv210_driver); > + > +err_dmc: > + for (id = 0; id < ARRAY_SIZE(dmc_base); ++id) > + if (dmc_base[id]) > + iounmap(dmc_base[id]); You will iounmap the same pointer twice, if first device bind failed while following this error path and someone tries to bind second time (again with error leading to this error path). You zero the pointer either at beginning of probe or after iounmapping. Best regards, Krzysztof > + > +err_clk_base: > + iounmap(clk_base); > + > +err_clock: > + regulator_put(int_regulator); > + > +err_int_regulator: > + regulator_put(arm_regulator); > + > +err_arm_regulator: > + > + return result; > } > > static struct platform_driver s5pv210_cpufreq_platdrv = { > -- > 2.17.1 >