From patchwork Mon Jan 2 09:10:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 9493233 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5739A60414 for ; Mon, 2 Jan 2017 09:13:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DD97223B2 for ; Mon, 2 Jan 2017 09:13:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30552267EC; Mon, 2 Jan 2017 09:13:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1927223B2 for ; Mon, 2 Jan 2017 09:13:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932091AbdABJLU (ORCPT ); Mon, 2 Jan 2017 04:11:20 -0500 Received: from mail-pg0-f54.google.com ([74.125.83.54]:35626 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754829AbdABJLS (ORCPT ); Mon, 2 Jan 2017 04:11:18 -0500 Received: by mail-pg0-f54.google.com with SMTP id i5so137277016pgh.2 for ; Mon, 02 Jan 2017 01:11:18 -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=Xo1GtKtrdvkZTGtobSb3qajz0S6hJDa4DBKqsQxMqiw=; b=agBnQQCiEAAZOc/rtSYHgYDAgcLEXSy5WDwPFJkjK8EmggrytbQJbBQSTQ//EcxfjY dkr6pnvfOzECJUqrMx5YFhPiGkF9zu0qoxQ6NMax6uIfSPXs3VEelMU7od1DnVHG4v00 8ZjXvZVhGwm83VOyJECDrk+zyo8nrguzMphzA= 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:in-reply-to:references; bh=Xo1GtKtrdvkZTGtobSb3qajz0S6hJDa4DBKqsQxMqiw=; b=OP1kJN6r3FnRZilsYrdTIbYrqx9TerI8OBWUZsyYGYHkuuigyWSpyjuQ4+LwesocaI ZKcTsz7DIaGiRMRfiwuym9AnuIchrlFIE/H+6HigFFEF/+ntuZeuUnm1UbUIDh5Cv+db uVxfxm4StTpHScZmtxQeEOJE/Dn8kEDO18p1g8svrtGF/2rUaJ87GZ21WtdirfIszS1g nb4rIAUvIIrOYYjYhCGpFug7/23fTq4tPE3bveuusIf0s44GfdLwcCETW8XoGgqIwMV9 TBTIdM5eU/Ew2CzQQFNDBVaIH0Po+eQ6FzSU21KiXm7DFddFrUh46jKahwE5tnOJ62r2 qBaQ== X-Gm-Message-State: AIkVDXJsDSzBI+pTdCkunyIPNhbiP5HolNdz80MNeTn0kjQhOJnh8d4SrvFMAvvC2K4knopE X-Received: by 10.84.128.67 with SMTP id 61mr51164021pla.153.1483348277556; Mon, 02 Jan 2017 01:11:17 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id w5sm130474958pfl.31.2017.01.02.01.11.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Jan 2017 01:11:16 -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, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar Subject: [PATCH V3 01/10] PM / OPP: Fix memory leak while adding duplicate OPPs Date: Mon, 2 Jan 2017 14:40:55 +0530 Message-Id: <83cb1a5f9d4b8e957a6e875e2391d6349b158dae.1483348138.git.viresh.kumar@linaro.org> 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 X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Stephen Boyd --- drivers/base/power/opp/core.c | 18 ++++++++++++++++-- drivers/base/power/opp/of.c | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index 35ff06283738..a8a5e01b7756 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -1067,6 +1067,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) { @@ -1099,7 +1109,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; @@ -1173,8 +1183,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")) {