Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp42510ybk; Tue, 12 May 2020 14:50:48 -0700 (PDT) X-Google-Smtp-Source: APiQypLpxMMydALB3DtMTs+CcQ+hXc5/NQDDuvaT26b7R//3xBFy3nlKwifPtShdZxC23oAyss0x X-Received: by 2002:a17:906:7c0c:: with SMTP id t12mr20135215ejo.2.1589320247782; Tue, 12 May 2020 14:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589320247; cv=none; d=google.com; s=arc-20160816; b=igplGEuKzTjZmmSc3DjA+4Wje7mbYliiq4en6iJD4jeW5gxOIONa5w/LFxRVIG7vfI yGzH/MxeWnIjBGtMNlM1qz4qQv8ksO6FhMZrT0VQ+Qm0xaQoLp+qE3IcLxjg1R21Mpcm eJOfZHsM/8WsUVhBxgziA9ODfQhZGjNbunHbYhh6zrSBTB0VCVNESHXpaUDUgap4uWOb zROjx5jIeMx0GdNkLb3lO7FhXPRnoHEpTEK+caxC6J/kfQ5FhWkC36KQzFb4OW/mCNKc KRsdMppIFdaYjQEfn64wMUP5PN9CVSPICSpXhx+uH/siXKIqXl80f9XoBKV5dswf60On xrRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Uv52gchuUhEIM8QP1BdGMzRp2+Ut2TatOyzveq7OlWs=; b=y0WsPJ8jMLxUkXqSDDsVdtXTij5PFqnwLj/gpf86/oL4umm+22slJZIrN8xk/iQA47 UvCwIcyFfWemDAomghnWn9RIne34FbceyqGBVQG+JcE1p+JOljjtxgRDDOg1gxLULQYA lTb5yM+t3M4GM80cIF5WusS81EBzhr/DfRZ6n4ugb8I79fCs3xHIa50xAklo0bRDMJrt bVAe9EA+vaNhWqVX31XSQIwMR9zL70JPD9VjVWyuGbmU51YFpVo4SoaSi9PMJeEHsfNr gdS6HcsvDpihAObPWq4+/+GgWCefRRKyCB6um92/iPRWMN3COwZqWGryZ8Gjlzs16S1B JPRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jkxjg0T2; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rl12si8335741ejb.199.2020.05.12.14.50.23; Tue, 12 May 2020 14:50:47 -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=@chromium.org header.s=google header.b=jkxjg0T2; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731569AbgELVr5 (ORCPT + 99 others); Tue, 12 May 2020 17:47:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731329AbgELVrz (ORCPT ); Tue, 12 May 2020 17:47:55 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C50DDC061A0E for ; Tue, 12 May 2020 14:47:55 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id l73so949647pjb.1 for ; Tue, 12 May 2020 14:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Uv52gchuUhEIM8QP1BdGMzRp2+Ut2TatOyzveq7OlWs=; b=jkxjg0T2haVmUpTShuETFu1Wq++3MwjgbyneltOHIfk8XQsJNKxt922t1Ytvkm8wYD RuA4OJxZWBa/vXJiaIIZHvY9Y6cbdCyREuLDwkiTLEgkpxB1w1x5Blst/fjWuwf3ERc/ bjUma8IUpfYR5TD4vtu6DAmnX6ipRd9lYuxZ8= 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:in-reply-to; bh=Uv52gchuUhEIM8QP1BdGMzRp2+Ut2TatOyzveq7OlWs=; b=ZzieIi/Ymr+jolqk9gYl19xncwAH49OcpIXdsJ6PByJBxTZecioOylO92F+u0iJcP4 ISVQlghBjFEnGFt0NNPI7Y5Et2ndvKP0C8dEYZG4kXhGwwcQ1gZIR4e+wU6dQwzRKMlY VeDX8+nEst2Nl7kS/ydLCKAdS7lOPX967ZoLqoThT5A0OEaw63fQCPi/0XiDfgzI+lEW 5RNLplRAFhlVw8/QHgAaHMibl5y5Nktz+xrsCVVAoajbZkweg1kzmaipakeUG/pwYYl1 wtekwd+P9xQKgZkENaytg0ryGGWt8/jJyMV4m88413OB4JEJEW5rMaeSNJV97ovpLx9J jcEA== X-Gm-Message-State: AGi0Pua7JhPddKXRcirU6cEKIKCa8ufagEMNH4wdcbGajq5aOQTnSA1/ ilt2LtVBWldulglkgmWMXEzvYQ== X-Received: by 2002:a17:90b:957:: with SMTP id dw23mr31666614pjb.101.1589320075184; Tue, 12 May 2020 14:47:55 -0700 (PDT) Received: from localhost ([2620:15c:202:1:4fff:7a6b:a335:8fde]) by smtp.gmail.com with ESMTPSA id 135sm12786295pfu.125.2020.05.12.14.47.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 May 2020 14:47:54 -0700 (PDT) Date: Tue, 12 May 2020 14:47:53 -0700 From: Matthias Kaehlcke To: Georgi Djakov Cc: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, rjw@rjwysocki.net, saravanak@google.com, sibis@codeaurora.org, robh+dt@kernel.org, rnayak@codeaurora.org, bjorn.andersson@linaro.org, vincent.guittot@linaro.org, jcrouse@codeaurora.org, evgreen@chromium.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 08/10] cpufreq: dt: Validate all interconnect paths Message-ID: <20200512214753.GJ4525@google.com> References: <20200512125327.1868-1-georgi.djakov@linaro.org> <20200512125327.1868-9-georgi.djakov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200512125327.1868-9-georgi.djakov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Georgi, On Tue, May 12, 2020 at 03:53:25PM +0300, Georgi Djakov wrote: > Currently when we check for the available resources, we assume that there > is only one interconnect path, but in fact it could be more than one. Do > some validation to determine the number of paths and verify if each one > of them is available. > > Signed-off-by: Georgi Djakov > --- > v8: > * New patch. > > drivers/cpufreq/cpufreq-dt.c | 49 ++++++++++++++++++++++++++++++++---- > 1 file changed, 44 insertions(+), 5 deletions(-) > > diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c > index 4ecef3257532..3dd28c2c1633 100644 > --- a/drivers/cpufreq/cpufreq-dt.c > +++ b/drivers/cpufreq/cpufreq-dt.c > @@ -91,12 +91,54 @@ static const char *find_supply_name(struct device *dev) > return name; > } > > +static int find_icc_paths(struct device *dev) > +{ > + struct device_node *np; > + struct icc_path **paths; > + int i, count, num_paths; > + int ret = 0; > + > + np = of_node_get(dev->of_node); > + if (!np) > + return 0; > + > + count = of_count_phandle_with_args(np, "interconnects", > + "#interconnect-cells"); > + of_node_put(np); > + if (count < 0) > + return 0; > + > + /* two phandles when #interconnect-cells = <1> */ > + if (count % 2) { > + dev_err(dev, "%s: Invalid interconnects values\n", __func__); > + return -EINVAL; > + } > + > + num_paths = count / 2; > + paths = kcalloc(num_paths, sizeof(*paths), GFP_KERNEL); > + if (!paths) > + return -ENOMEM; > + > + for (i = 0; i < num_paths; i++) { > + paths[i] = of_icc_get_by_index(dev, i); > + ret = PTR_ERR_OR_ZERO(paths[i]); > + if (ret) > + break; > + } > + > + while (i--) > + icc_put(paths[i]); Since the function only does a validation and throws the paths away afterwards you don't really need the dynamic allocation and 'icc_put' loop. Just have a single 'struct icc_path' pointer and call icc_put() inside the for loop.