From patchwork Wed Jun 10 14:39:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustav Wiklander X-Patchwork-Id: 211827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69135C433E0 for ; Wed, 10 Jun 2020 14:39:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CCF62078C for ; Wed, 10 Jun 2020 14:39:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=axis.com header.i=@axis.com header.b="Jrxs9pdq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726793AbgFJOjy (ORCPT ); Wed, 10 Jun 2020 10:39:54 -0400 Received: from smtp1.axis.com ([195.60.68.17]:53322 "EHLO smtp1.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726560AbgFJOjx (ORCPT ); Wed, 10 Jun 2020 10:39:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; l=1996; q=dns/txt; s=axis-central1; t=1591799993; x=1623335993; h=from:to:cc:subject:date:message-id:mime-version; bh=f9LZRbq2gqRPTsVfTL7+SZEhrzzg5RLrAM5dHzD/5ZM=; b=Jrxs9pdqpfOdH9pwx39FJiqRgunPVWkmeGAigoTdTwGru1ppKjtjy/Nc 27/qUV0Y5l1xzOS06nVSkNPajE2Y46g9hVrhmk06d7ljioaMko10fhWmo jexTMpgerh1cT+LvCRhdHbcCER1iIetTQOjs7zJfhMNphxG3/MqhCxteQ xZrs6rrTta/sxORNsdjRW5V4t/qyFACiCKNl3GuuhnU/MCDQkLhpAagXe Vfx9WNGTCyV1XvfqKFq4KEnXOV95gTztYmgrVVcQzXXbW0YY2x5n9DfNY ko5WfgIS8WmUfkO3tupVti5UBBq4w2Xb+rNfHSJxmBjGeAOrZxfcB0eDM A==; IronPort-SDR: 0I1IasE6onjJfpU0QrIldCWQhC4jN2MveENewo1bo56iXhWsU/JyVfdRxK0fUeJk7RkWmWUPeW pUIvHTQgSdO5sk2OeoVazLOuj1KX7oT+KCaReLCd+u+5qybE0S1tJ667NIxksOmQXkTZoX/jSy THpt9IJfZ9NmfBDHRq66osGsbcC/DKqdSKMJkUr+WRIdV47A4jhxT0pHo43T/nR4tiJcVB+lAH Q5ul+yw9jzyFFrcNpfjj5GOFhgbzU2K41K1yrdl96oBNe1PmsJh3GyC7ICFOeoNREqFxbiX5Pv WxM= X-IronPort-AV: E=Sophos;i="5.73,496,1583190000"; d="scan'208";a="9667423" From: Gustav Wiklander To: CC: , , , , , , , Gustav Wiklander Subject: [PATCH] PM / Domains: Add module ref count for each consumer Date: Wed, 10 Jun 2020 16:39:43 +0200 Message-ID: <20200610143943.12548-1-gustav.wiklander@axis.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Gustav Wiklander Currently a pm_domain can be unloaded without regard for consumers. This patch adds a module dependecy for every registered consumer. Now a power domain driver can only be unloaded if no consumers are registered. Signed-off-by: Gustav Wiklander --- drivers/base/power/domain.c | 11 ++++++++++- include/linux/pm_domain.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 0a01df608849..80723f6d5e6b 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1499,11 +1499,18 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, if (IS_ERR(gpd_data)) return PTR_ERR(gpd_data); + if (!try_module_get(genpd->owner)) { + ret = -ENODEV; + goto out; + } + gpd_data->cpu = genpd_get_cpu(genpd, base_dev); ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; - if (ret) + if (ret) { + module_put(genpd->owner); goto out; + } genpd_lock(genpd); @@ -1579,6 +1586,8 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, genpd_free_dev_data(dev, gpd_data); + module_put(genpd->owner); + return 0; out: diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 9ec78ee53652..777c1b30e5af 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -9,6 +9,7 @@ #define _LINUX_PM_DOMAIN_H #include +#include #include #include #include @@ -93,6 +94,7 @@ struct opp_table; struct generic_pm_domain { struct device dev; + struct module *owner; /* Module owner of the PM domain */ struct dev_pm_domain domain; /* PM domain operations */ struct list_head gpd_list_node; /* Node in the global PM domains list */ struct list_head master_links; /* Links with PM domain as a master */