From patchwork Tue Dec 6 09:15:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 86713 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1917114qgi; Tue, 6 Dec 2016 01:16:56 -0800 (PST) X-Received: by 10.99.125.24 with SMTP id y24mr106828635pgc.27.1481015816692; Tue, 06 Dec 2016 01:16:56 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si18742786plo.92.2016.12.06.01.16.56; Tue, 06 Dec 2016 01:16:56 -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 S1751762AbcLFJQz (ORCPT + 13 others); Tue, 6 Dec 2016 04:16:55 -0500 Received: from mail-pg0-f50.google.com ([74.125.83.50]:33273 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751798AbcLFJQv (ORCPT ); Tue, 6 Dec 2016 04:16:51 -0500 Received: by mail-pg0-f50.google.com with SMTP id 3so147454608pgd.0 for ; Tue, 06 Dec 2016 01:16:15 -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=ze6DUNiT4L3KsyFqaCS/dXyhAesn5Dtklq8pHkQbSKc=; b=BJdFahKTnvc6V/Riboa/Gag83UkiDwiOMSkEU71MFnsUncKy+tu2TH5hc/X4afamQs KBRF+EaPVvxRPuRZp7e/vgRhSyFnbWCgLWfO+fhx6hWF9h2XRPGd8fBObOb1DeMpm8hh 32e7XDlqrt8fiqzrkV9/WaRVaJqfub3V7V7Cs= 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=ze6DUNiT4L3KsyFqaCS/dXyhAesn5Dtklq8pHkQbSKc=; b=d4LHBdASM88POPCvjBiHx+1KxRRetUrG112Qlg2i2l5r0VQPIcEOMSa1J3kHBPHw63 Ci9Wp7FLBJ8BaBc4Nlyrh3isUi4lv8ccBSGUvINJ0IVK5UbVftMXG+CeA6c/EcGeSEy2 Z9B3JqA6nPyST45bxj1IDbsu37e617LZqCKlX93UFyYA3q3MP2/DUWxPMtQaGGv2gYiq Tj40e2Fpr2u1uzq7S/N1fEcmm5FaGaTMSkl0sS++uyUl8Cb7ISgjqbyQigHJjlfJTy7N /UbEJBpXfMSzw0i28SkcJG73L4mAUPHy6lrfck5rxCNZFIkzbBZKboY6Uw3uMuxi0HCY 6Bsw== X-Gm-Message-State: AKaTC02fiuBUOre9fChvhW2ZoozCs8i8ZhH0/ZBGi2Zw+wzTV6bsUMbOMKEkAGs5LOjEUnXy X-Received: by 10.84.169.36 with SMTP id g33mr136095190plb.174.1481015775127; Tue, 06 Dec 2016 01:16:15 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id x26sm6115887pge.24.2016.12.06.01.16.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Dec 2016 01:16:14 -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 01/10] PM / OPP: Fix memory leak while adding duplicate OPPs Date: Tue, 6 Dec 2016 14:45:53 +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 | 14 ++++++++++++-- drivers/base/power/opp/of.c | 6 +++++- 2 files changed, 17 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 diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index a0e6294baf1d..cc69f903fd34 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -1080,6 +1080,12 @@ 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. + * -EEXIST: For OPP with same freq but different volt or is unavailable. + */ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table) { @@ -1112,7 +1118,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 +1192,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")) {