Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2691301ybk; Tue, 12 May 2020 05:56:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWP3w4pq/h2KLJixBpGRt83iEpuZe/S8yl4KOttusWqkNCeLfFdZD6RqM85lkMZK8M7LRq X-Received: by 2002:a17:906:a29a:: with SMTP id i26mr7194162ejz.199.1589288165140; Tue, 12 May 2020 05:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589288165; cv=none; d=google.com; s=arc-20160816; b=j3vU7b4qHDjDQgfHNQ3GN1sZC4x4ZaDF9ADfgGWksF+rkOaAocHXJ9lfaGjKBsojwL Pdw36sFY4L1MIQeXK0gfwHn9slh/1LFnvsvy1W0CF/XFEOrfDBormMLeGa0w3HMRL+5A GgdhlO6gN+VmNZr5NB/4m0ztjnDQ1R2qYMc8/wEchvO791KURJql+jtfzQ6tippUIC29 HmaasXx+i6BjqW6SIfA0zCiHLUvHBAoiiwPYlOh8MIFki98PQuOkSTwdXpkafXNd+JJ9 QYWWGVXFfvXsGwIjsd/2Tlw4zO+uYmgL7nfZVKlA55F+lYB9lICOQzzhRRvIyttNZEsI YG/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=b24wWlVcAI5WtF67gfQ7lrjlIMYnj1RJeDLHmrXEYY0=; b=oFX3ARE11DM4YZ8iX6BrL8H+ayj6ikmgrPezTzAuckY7pC5wNE5O0kRXt/HmjI862R RJkEZPR4PWl/EeanvryQ76I5HV2yx5Zsao6n4lZxKGJFKieraZcMOQNnCLOhhSSZS8MQ SnYZqd8Gr8vBCxQveuBn89W4hA0zsfj4enicC8i+lMdVCS8Cw69HNyHLiQTwLcJApoSP UkBAJyyWyoq+nETgTLWp5FlbfHXigHslyl0MZ0r8UMn/4XPvJzmv86gCkTy8xG7thwCg D6e6YlOeCA6bXoavW5F0/gJbS0LiaL8g6YsHuX2jL6uE+JBXT1X2E7DqL9nPv0lXkOLv gkgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bp9y1iYj; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si7971494edm.113.2020.05.12.05.55.42; Tue, 12 May 2020 05:56:05 -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=@linaro.org header.s=google header.b=Bp9y1iYj; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729920AbgELMyG (ORCPT + 99 others); Tue, 12 May 2020 08:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729900AbgELMyE (ORCPT ); Tue, 12 May 2020 08:54:04 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F399C061A0E for ; Tue, 12 May 2020 05:54:04 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id h4so21623883wmb.4 for ; Tue, 12 May 2020 05:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=b24wWlVcAI5WtF67gfQ7lrjlIMYnj1RJeDLHmrXEYY0=; b=Bp9y1iYjiq7ye/soNQOoI0zgGM05UpR/YwVIWWyyEltiDcIOoAGDYxVDyrDRrvoh0O daBFFibX2WNQ2n4W5P7mhIcxYCnoHunw/ZHAgIJfRZeNwwKd/+4yY6j2RSUCcAO2oKcG SlfmAbhoI/WUOA16HyPwEuIj1qRrpMFdx/6fH+Dv5VKckYOsA70pKQD7sY6ocNbpEILX xIEK/cd4VbYgamr0IAvzmZgRzZEWeNyStR5Lyqvf7wpEZ/3sclOwgm73VYOhveGK1FZm Ocaj1mJlJ2z1Vu6Fid4ZF3lE7fTtiybksa2rITo9zqBwvMuPmmswX2vTdUeFj+9Na6YF ms/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=b24wWlVcAI5WtF67gfQ7lrjlIMYnj1RJeDLHmrXEYY0=; b=o42Sa86OsQKo14i+5X4htAllCDo+txiNjVjzPBd7p9vn+i2inyeCrdZSTPYBIHxacW UAbitQMLEVthkfHQSrQGPdRT8g5Hhfjw+7HoCudHrwLDBb+FapTDWj7r4iBKk7mMWOwO s+/OkhzX3YjnE/7AhbVJHCq5+ZyZ42Wg7NxwfZ+9EMlp9Lr+1kTj/5YSkRp4Wj+4Dvaq 1P1dyzHddxoUnKX2dtVOYHVUqZV+5cDOyXHL+pU6yr4A1C3W+QnhLRg+PjXxQ72D3DW8 oXn2rWSZWv/3SCs4+oJiu9rkaea9Y6PNAw3+GszL7JXgdKdcOeS1BZnEYdGYjDV6V2kr OkSw== X-Gm-Message-State: AGi0PuYCvFofQGr96I+v/B6qoGB5qhaKMso4yo1WSZbWXEpevpnpN0RM CWc6+9c9ZmnoKYS0Emeh12SEZg== X-Received: by 2002:a1c:3884:: with SMTP id f126mr39071056wma.91.1589288042966; Tue, 12 May 2020 05:54:02 -0700 (PDT) Received: from localhost.localdomain (212-39-89-66.ip.btc-net.bg. [212.39.89.66]) by smtp.googlemail.com with ESMTPSA id n13sm2433938wrs.2.2020.05.12.05.54.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 May 2020 05:54:02 -0700 (PDT) From: Georgi Djakov To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, rjw@rjwysocki.net, saravanak@google.com, sibis@codeaurora.org, mka@chromium.org Cc: 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, georgi.djakov@linaro.org Subject: [PATCH v8 05/10] OPP: Add sanity checks in _read_opp_key() Date: Tue, 12 May 2020 15:53:22 +0300 Message-Id: <20200512125327.1868-6-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200512125327.1868-1-georgi.djakov@linaro.org> References: <20200512125327.1868-1-georgi.djakov@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we read the OPP keys, it would be nice to do some sanity checks of the values we get from DT and see if they match with the information that is populated in the OPP table. Let's pass a pointer of the table, so that we can do some validation. Reviewed-by: Matthias Kaehlcke Reviewed-by: Sibi Sankar Signed-off-by: Georgi Djakov --- v8: * Picked reviewed-by tags. drivers/opp/of.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index d139ad8c8f4f..3a64f2aa0f86 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -573,8 +573,8 @@ void dev_pm_opp_of_remove_table(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); -static int _read_opp_key(struct dev_pm_opp *new_opp, struct device_node *np, - bool *rate_not_available) +static int _read_opp_key(struct dev_pm_opp *new_opp, struct opp_table *table, + struct device_node *np, bool *rate_not_available) { struct property *peak, *avg; u32 *peak_bw, *avg_bw; @@ -602,6 +602,12 @@ static int _read_opp_key(struct dev_pm_opp *new_opp, struct device_node *np, * opp-avg-kBps = ; */ count = peak->length / sizeof(u32); + if (table->path_count != count) { + pr_err("%s: Mismatch between opp-peak-kBps and paths (%d %d)\n", + __func__, count, table->path_count); + return -EINVAL; + } + peak_bw = kmalloc_array(count, sizeof(*peak_bw), GFP_KERNEL); if (!peak_bw) return -ENOMEM; @@ -624,6 +630,13 @@ static int _read_opp_key(struct dev_pm_opp *new_opp, struct device_node *np, avg = of_find_property(np, "opp-avg-kBps", NULL); if (peak && avg) { count = avg->length / sizeof(u32); + if (table->path_count != count) { + pr_err("%s: Mismatch between opp-avg-kBps and paths (%d %d)\n", + __func__, count, table->path_count); + ret = -EINVAL; + goto free_peak_bw; + } + avg_bw = kmalloc_array(count, sizeof(*avg_bw), GFP_KERNEL); if (!avg_bw) { ret = -ENOMEM; @@ -697,7 +710,7 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, if (!new_opp) return ERR_PTR(-ENOMEM); - ret = _read_opp_key(new_opp, np, &rate_not_available); + ret = _read_opp_key(new_opp, opp_table, np, &rate_not_available); /* The key is optional for devices like power domains. */ if (ret < 0 && !opp_table->is_genpd) { dev_err(dev, "%s: opp key field not found\n", __func__);