From patchwork Wed Dec 7 04:41:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 86951 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp136771qgi; Tue, 6 Dec 2016 20:42:18 -0800 (PST) X-Received: by 10.84.174.67 with SMTP id q61mr139652306plb.93.1481085738140; Tue, 06 Dec 2016 20:42:18 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h67si22465114pfe.48.2016.12.06.20.42.17; Tue, 06 Dec 2016 20:42:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751527AbcLGEmR (ORCPT + 13 others); Tue, 6 Dec 2016 23:42:17 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36141 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750825AbcLGEmQ (ORCPT ); Tue, 6 Dec 2016 23:42:16 -0500 Received: by mail-pf0-f181.google.com with SMTP id 189so74743425pfz.3 for ; Tue, 06 Dec 2016 20:42:16 -0800 (PST) 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 :in-reply-to:references; bh=zUyUhpd0gJWc6ENzLwrI9UtamVkdblvnypogsE5qDds=; b=IurVeTTvnS/Za8gKxMgFAk5SIq0ZfxxglfytV794iIEr4LUffrMd8eWBsUlcP/18Ic DTog4bUH6dBGvix3ANlGuKAvXVqIiwwCijK1giqwXfD/CO/kgu9WRQfyhXpt8JDWnTdu KcLlOzBsg4wFMQYECEXLT3m0o9ENaeOqV94kI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=zUyUhpd0gJWc6ENzLwrI9UtamVkdblvnypogsE5qDds=; b=FAsKOYl0QO0Lx93lw7OIsFhYpfhUWcUCFzVL4sJeo+oCFiRSr42zaLdK/9mvEg9jyN 0aGp7iSI0JR9BVsmZ3OFDIGzbY0E5LaAhkkU8pejvKqho0Gor879teZXg3mUu0F0hcKm W7LcW+CMACJiUEh2cJ2J714NOwJ82VJOzvz+g+WAkfR4YDSnLQoM92P/DA9sKS/k3WWT OcOhPLOw8ydIW1haXQphMFIo6ZAUCKVtSBYRohQ/PS+EOjCYb03It35zUKxgZf72PVnO asYiBlDlA3kkbd5+m1+pLcZ+o8kYZuUL2kp0S0xouo/Yenjy7ZJjvNu3exObBEcuMv1+ Jvrw== X-Gm-Message-State: AKaTC039e1QMmqkQQqVjZd6FR9o2QwDSzfa5EdU+mTdAySjI8hJGIe+9fOjTdJHef/8KxpGw X-Received: by 10.99.47.7 with SMTP id v7mr119981473pgv.39.1481085735934; Tue, 06 Dec 2016 20:42:15 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id r21sm38264498pfd.44.2016.12.06.20.42.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Dec 2016 20:42:15 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, Vincent Guittot , Viresh Kumar Subject: [PATCH V2 01/10] PM / OPP: Fix memory leak while adding duplicate OPPs Date: Wed, 7 Dec 2016 10:11:57 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There are two types of duplicate OPPs that get different behavior from the core: A). An earlier OPP is marked 'available' and has same freq/voltages as the new one. B). An earlier OPP with same frequency, but is marked 'unavailable' OR doesn't have same voltages as the new one. The OPP core returns 0 for the first one, but -EEXIST for the second. While the OPP core returns 0 for the first case, its callers don't free the newly allocated OPP structure which isn't used anymore. Fix that by returning -EBUSY instead of 0, but make the callers return 0 eventually. As this isn't a critical fix, its not getting marked for stable kernel. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 18 ++++++++++++++++-- drivers/base/power/opp/of.c | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) -- 2.7.1.410.g6faf27b -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Stephen Boyd diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index a0e6294baf1d..9ff816217c6e 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -1080,6 +1080,16 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, return true; } +/* + * Returns: + * 0: On success. And appropriate error message for duplicate OPPs. + * -EBUSY: For OPP with same freq/volt and is available. The callers of + * _opp_add() must return 0 if they receive -EBUSY from it. This is to make + * sure we don't print error messages unnecessarily if different parts of + * kernel try to initialize the OPP table. + * -EEXIST: For OPP with same freq but different volt or is unavailable. This + * should be considered an error by the callers of _opp_add(). + */ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table) { @@ -1112,7 +1122,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, /* Should we compare voltages for all regulators here ? */ return opp->available && - new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? 0 : -EEXIST; + new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST; } new_opp->opp_table = opp_table; @@ -1186,8 +1196,12 @@ int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, new_opp->dynamic = dynamic; ret = _opp_add(dev, new_opp, opp_table); - if (ret) + if (ret) { + /* Don't return error for duplicate OPPs */ + if (ret == -EBUSY) + ret = 0; goto free_opp; + } mutex_unlock(&opp_table_lock); diff --git a/drivers/base/power/opp/of.c b/drivers/base/power/opp/of.c index 3f7d2591b173..356c75edd656 100644 --- a/drivers/base/power/opp/of.c +++ b/drivers/base/power/opp/of.c @@ -327,8 +327,12 @@ static int _opp_add_static_v2(struct device *dev, struct device_node *np) goto free_opp; ret = _opp_add(dev, new_opp, opp_table); - if (ret) + if (ret) { + /* Don't return error for duplicate OPPs */ + if (ret == -EBUSY) + ret = 0; goto free_opp; + } /* OPP to select on device suspend */ if (of_property_read_bool(np, "opp-suspend")) {