Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5138588imm; Wed, 12 Sep 2018 01:30:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaXpt2tYJVkXd/gKoH/1Y75d0Ov2yfCLMZn84vPYX+C/W7Ptcp6rAWo0dhvi0YLsBjMIbtl X-Received: by 2002:a63:1e0b:: with SMTP id e11-v6mr882400pge.44.1536741045661; Wed, 12 Sep 2018 01:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741045; cv=none; d=google.com; s=arc-20160816; b=EccmydSyeMnSYPlcIGJoQrkBBIg2npf9BrxQP6rkhbwsf6nbT575ObGa984HQmsu7+ m3JlOHVYmeaCrAVNE+NbHmOU+HKf3uRGBRYc5lw/xL0bV0eKyjd0zH4Uxh4859LDxce8 9ziUHEp0GpV1LHTJwYmdot5V8GZnP3zWrfouLkh7rgJgUNwYxfr03JUOB6Wc8NBYQZKL MEQhSKs0kk0IyMHik4VghszU2KZmNSjqBZXKk/s2h6149cjJb0Izdcs7SSAxalXmpr7I F5jmBfVKmY0BbXo9VQKenM7QrrKyh++cx532RNMKUqw2CENnEd4fGKYg34bsIw+0PltB x9tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=jPGAIL3sdk1Aa+qVaM14yKId1VZA9MbnVLCDYEKFuXg=; b=mzex9AgA9HFzEyzux2lL6WFaf/qX0dz9pPspaQPeB1KIT99KJAPpzmUf2JM4osyxUL u68QEJ+fpFpWHnupAWlH18OI4UJx9GHGt7ATLEv+DdMvReBINQifOp1ZpkV/ypD1BVKj glij7jlQ2Hio/QG9XbEKUARTuV+A9ZkmoQY+MeJXaZr/w9PqDKMBZ626id+h+okSIlYj IlCn1fzGiCuRAiEm7eWOf9gy77O+2OvZ3kPmXsuOm6N+TaTd0kBmpubfH8aCL8lxmiRz /1niHgNxJAzWiUlmrRkf3fzeVSUE6M0zseUP4y95uRwUIQUqUtQXj4vnEgUrdnO5Jntw TPig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MdZ588XX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id n65-v6si356658pfn.320.2018.09.12.01.30.30; Wed, 12 Sep 2018 01:30:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MdZ588XX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728080AbeILNdb (ORCPT + 99 others); Wed, 12 Sep 2018 09:33:31 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37386 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727789AbeILNda (ORCPT ); Wed, 12 Sep 2018 09:33:30 -0400 Received: by mail-pf1-f196.google.com with SMTP id h69-v6so652898pfd.4 for ; Wed, 12 Sep 2018 01:30:03 -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; bh=jPGAIL3sdk1Aa+qVaM14yKId1VZA9MbnVLCDYEKFuXg=; b=MdZ588XXa/wpGdUAt4Ygq+BCWjnFwYVNL5v3gbPoGfNpZ10R8QGd1gS6l7AFo1hziz Am6Tm7Y9f9SpD319PLWMdd519oGNHaY5n1uNYr0Y291U6IFIuHvUT3rQJGxRH/eFYeR5 EgKbamcC9lN1n059MA6tx938cPi+3WYav74r4= 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; bh=jPGAIL3sdk1Aa+qVaM14yKId1VZA9MbnVLCDYEKFuXg=; b=Vf+BJRnWotNN2YKfQK2/e3M/9Edtmiz3NowkE/gQrhiyJ9JthXuUaenHLbE0dV3hRR DM9ro0Y9fWujh3mVrlOTJgE1FmLdpfj+enxFj2/6j7K/++BXYo9zj05f/gunBUzJKdpJ Nuzb36vAkbEYuX0rSseHa3UKuQd8nzbrmv/mu/qYmN6rLTOThR8uI58waQBsnv2LNPjP 8RC8uUK2PDH2WPXxLP8uUoGxNhNcjsf3wesj6aWQB/r0sQe29ZUdYREwXfefhexoIior M4LiP4lZMp94pW3jp+NE168dWukOFf+Psmbtw7SoPqlvhX9d4C9lqtxQC6XFe3k6GzPR 2MZw== X-Gm-Message-State: APzg51Da5aFJK9cA+K41XRi9KT6ckscUY5q2DC8buOKLtzyY4GWEKYqa hmxulgkCa+45I69mMxqdhRp7Iw== X-Received: by 2002:a62:2744:: with SMTP id n65-v6mr920713pfn.125.1536741002527; Wed, 12 Sep 2018 01:30:02 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id g25-v6sm1079645pfd.23.2018.09.12.01.30.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:30:02 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 05/11] OPP: Don't take OPP table's kref for static OPPs Date: Wed, 12 Sep 2018 13:58:44 +0530 Message-Id: <08942a9ab06dd76034242cb70dd2446020a2efe0.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The reference count is only required to be incremented for every call that may lead to adding the OPP table. For static OPPs the same should be done from the parent routine which adds all static OPPs together and so only one refcount for all static OPPs. Update code to reflect that. The refcount is incremented every time a dynamic OPP is created (as that can lead to creating the OPP table) and the same is dropped when the OPP is removed. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 332748adc262..2a6976265580 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -919,7 +919,6 @@ static void _opp_kref_release(struct kref *kref) kfree(opp); mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); } void dev_pm_opp_get(struct dev_pm_opp *opp) @@ -963,11 +962,15 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) if (found) { dev_pm_opp_put(opp); + + /* Drop the reference taken by dev_pm_opp_add() */ + dev_pm_opp_put_opp_table(opp_table); } else { dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n", __func__, freq); } + /* Drop the reference taken by _find_opp_table() */ dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove); @@ -1085,9 +1088,6 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, new_opp->opp_table = opp_table; kref_init(&new_opp->kref); - /* Get a reference to the OPP table */ - _get_opp_table_kref(opp_table); - ret = opp_debug_create_one(new_opp, opp_table); if (ret) dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n", @@ -1566,8 +1566,9 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) return -ENOMEM; ret = _opp_add_v1(opp_table, dev, freq, u_volt, true); + if (ret) + dev_pm_opp_put_opp_table(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_add); -- 2.18.0.rc1.242.g61856ae69a2c