From patchwork Thu Apr 24 10:36:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 884174 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 709BD2367A2 for ; Thu, 24 Apr 2025 10:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491031; cv=none; b=eK9rEjKwVoEgx8GirBAL87BjgjN1rfTyVG+zwF5DDq1ez3euOdV4sP5mjM9j2N8bCFEjRfq+80xcFeGx1vCyHLNawhKhW/GtTez4lWtq9ozJM0kL4mOkW7WvImhsBJT8bZ5C/59GscoBh8tYNIMtamzqdfufwWLHQgBw8mtv6Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491031; c=relaxed/simple; bh=XV8ObqiVVogtjO5N873sKSFmTsTaRcd1IBSPiFBNL38=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VqAj4VkhV715DkDCD/upTiQyoOw6EUGDJx721h9JkmJl8BR4kV3vWJfaRWr5QIWJ+ZoTUbdvep4N+Xu2fNnUa2ArNjLnPuKMqnG0Q9el1mpvXtpIjmmoQTh5KNCQq/F+6yLnA+Qzi7roc6uJIpKVtpyGTPCrlBm1dYD98GXIIfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=AiOEEFyg; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AiOEEFyg" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-22409077c06so12562685ad.1 for ; Thu, 24 Apr 2025 03:37:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745491029; x=1746095829; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XiIG8WEszkc/dlu2pYPwLwPCyzJuamBVIXLOR35LVRk=; b=AiOEEFygzlPo0eLE6UUqd/uIuZaUZxcwFIR8mf/BpHB/flO+IF3k66YIuhIeABrUEq vgk4gd5/62JzimuXwtL0sMXNE6ZVxvuMcclxdq/1kWcLqkfv5IgcuNc0ajnzro5344Em tPvt6ZJmOFP+ynyEMmh9XjdQtNQYMc72RVUA1+aKYLeaimpE7X3+guyArJ6/3i/uQuD0 H7EzrhbyMOxL8XkiesLsRTtwX3lbMzG7vGSCxAikYDeGCO/R8XK3VlnHkXdUYCFBjmZf s2lbU0zfqrUGETZpRmwXkn3OMvAi/zPFSeBkJFkQ69toXFL461VCTzqM7C1m4yKB9ikn Ctdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745491029; x=1746095829; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XiIG8WEszkc/dlu2pYPwLwPCyzJuamBVIXLOR35LVRk=; b=d0/QPb72bjmBKHGEpVPAClT0WOqPlWpFOd7bvAmK8YAa1wMxehklXTdJvS075EjBV0 MeeWuCL6lwFuuRVE3yr1YWf3BC4mTeNs6My0xhCxj5WKalf5l4CJ6C1EW2y1Q8MT2L2T rFvfWDsaA3dWvA9FmNiOzSr5l8D4AoEd6Mtmd2iVU0Xo4IwnKtlZITwlHH8TiFvUDOGx 6j+WqqufrQKg9Z/BA32CfS5uCke6SXcEiHlw90JKgzm5HNqNl4fAllxCBJ8sndPPhfD2 KA+DXBKvCUCfkrT9+35tnXbXhVTmFOGJbypduMCz7izhUequo+AYr9W1hSjaxBtzdU04 ok5A== X-Forwarded-Encrypted: i=1; AJvYcCW9mko1opJscVYYyDgjwj4actOJPoDegqRPZ/64IiUcU7IyyIWazDrDpWj4To0xhDrdKbCu5Y5Tpw==@vger.kernel.org X-Gm-Message-State: AOJu0YxD0XncTQ+WGQB2EwqYnBe+cFsOom95fAqtdji4iYywYbdyV2OE 49lTxHs6p1swkGuDz0Dcrb5CXLX5LA2qwGX3wj0oohxsSxGPxTT677NdvPGKndu42dGzllUmI6X 3 X-Gm-Gg: ASbGncuWFdtMqJImUrO0vSiMCAr1ttcuxyh+PzisdxYWnGKblAa/8rPRo5Fmo/QU4Dk w96grMbA7NCYvDagdiGni/F+lSHE605lMrUfHW+h797q1K24hxaMm8zagHH48EeoA7VBy7XoNzA HT6WqD5h0QGLlbKrZ8Ep8BN+oDnNGnc0XddGGru88TF/jZ5w+kRNmTqh+5RhSOzj6VAv27fZKoV u5wCceMAzrzrQFMrFB8h+U6Q4ufsst8okRCifc4GE0O2MmW0Ne1YG9/y5A/3BIaMW4tYtTwYpTi JWcBJdvMoblxYAUH2LUeYDYnH6Cvk5wq8T85NgAdjA== X-Google-Smtp-Source: AGHT+IEg3HiY1hRFa0sd4VmP7cYuftC34v8NrLnxhQq8aERPS7VCcuo9i6ofali9iKtAnB6B35F9CQ== X-Received: by 2002:a17:902:e5c6:b0:224:1219:934b with SMTP id d9443c01a7336-22db3de966dmr28392755ad.50.1745491028769; Thu, 24 Apr 2025 03:37:08 -0700 (PDT) Received: from localhost ([122.172.83.32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db4d77ee3sm9945165ad.2.2025.04.24.03.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 03:37:08 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 2/6] OPP: Return opp from dev_pm_opp_get() Date: Thu, 24 Apr 2025 16:06:45 +0530 Message-Id: <7a3be00771aa9786c7bb4cdb0ee36fee45f67d69.1745490980.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For convenience of users, return back the pointer to the opp from dev_pm_opp_get(), so they can do: opp = dev_pm_opp_get(tmp_opp); No intentional functional impact. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 13 ++++++------- include/linux/pm_opp.h | 7 +++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index e63a9b009df1..150439a18b87 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1188,8 +1188,8 @@ static void _find_current_opp(struct device *dev, struct opp_table *opp_table) */ if (IS_ERR(opp)) { mutex_lock(&opp_table->lock); - opp = list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node); - dev_pm_opp_get(opp); + opp = dev_pm_opp_get(list_first_entry(&opp_table->opp_list, + struct dev_pm_opp, node)); mutex_unlock(&opp_table->lock); } @@ -1329,8 +1329,7 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table, dev_pm_opp_put(old_opp); /* Make sure current_opp doesn't get freed */ - dev_pm_opp_get(opp); - opp_table->current_opp = opp; + opp_table->current_opp = dev_pm_opp_get(opp); return ret; } @@ -1724,9 +1723,10 @@ static void _opp_kref_release(struct kref *kref) kfree(opp); } -void dev_pm_opp_get(struct dev_pm_opp *opp) +struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp) { kref_get(&opp->kref); + return opp; } EXPORT_SYMBOL_GPL(dev_pm_opp_get); @@ -2706,8 +2706,7 @@ struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, list_for_each_entry(opp, &src_table->opp_list, node) { if (opp == src_opp) { - dest_opp = opp->required_opps[i]; - dev_pm_opp_get(dest_opp); + dest_opp = dev_pm_opp_get(opp->required_opps[i]); break; } } diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index c247317aae38..5e4c3428b139 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -161,7 +161,7 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, unsigned int *bw, int index); -void dev_pm_opp_get(struct dev_pm_opp *opp); +struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp); void dev_pm_opp_put(struct dev_pm_opp *opp); int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp); @@ -345,7 +345,10 @@ static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } -static inline void dev_pm_opp_get(struct dev_pm_opp *opp) {} +static inline struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp) +{ + return opp; +} static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} From patchwork Thu Apr 24 10:36:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 884173 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 075DC23A989 for ; Thu, 24 Apr 2025 10:37:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491041; cv=none; b=YXkqiMUvTqapHxq0BFKv/ioO/4L67RgHxSQZIh9h2FgIXZRn8zu8zjSOsubAZ0IBbY43CAKp4rbWrquZ8vyyNv3z1SrXtuvL1m/QPkNXnj/eq68RJFNwady5hnRe6Tgv0qWzmPxmZqnbS2jtamTwG/Xa4KFMUSJwvcmGbejgd8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491041; c=relaxed/simple; bh=VOa1T0aKJkkd4ubCM8nPBYNfRfmMW9NmHBOvyIP9zM8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YdFnTCapNwuPXkwPXXPTldO9WvNUkmmwE7ODZ4RoZq8JLq6ILNV05JpV2qJKz+u/oCSlbyKdajpi1MzooWyTRU0nCqRec9EZRx8cusDMR3fl3QeglpIy/so5/oJ2fPl6wEh9QCmqDV4kC4PCEa+ahRp4vs7yjXwXxYwLdgnpn5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=o+RKelrJ; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="o+RKelrJ" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-22c33677183so8026995ad.2 for ; Thu, 24 Apr 2025 03:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745491036; x=1746095836; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YnM7BGuhRXgKktziblZErpXUgiY+CFGwBppN4UGtJmo=; b=o+RKelrJSB0Hcm/82QHhpHUV/kOnwmEBGQXXoaWYXFG+YO+UkNXSFYV+UPFed5AFBu NXCtLEu2TZtL5pUpB4LosL+UvvfYULrOQfo9w6TxUhbPTaHgLqUzUCCi6mK0gScBRm0l NWdM9mA+NTEjz5wahG2+vjIRDOJ2J2B1KCPcsUt1bPMQzucDWEBWVCPB9eU5aepjRlDy i6DUd4zigbVH5dJYpqWR5dh+mp4jh0JNSZ0423yffi1B7FB2eUhJMtUOl2c5QGzvbl2r YopOMzlxYmUf8cYBIqq2yb6zTWox749rSuOO3iwZkk0Iw6verOv7fxvFCmx6KVDir0bK 8Vrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745491036; x=1746095836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YnM7BGuhRXgKktziblZErpXUgiY+CFGwBppN4UGtJmo=; b=USmfTirZAT6EuJqJd08Yudgic9aZDilA/vNpej4PepuDjCGzJYZuH85YIv365YnFJi 2IHYn4koyyRsS+bAEPsisH/iMj/py6zYnUrlkh/mgsCALAdAYyju4V/yWRkEV3t6nDU3 Sd4NBTVwBGDuNtdoFVh+eQjb3bu7NPdTQXk84tx4U7rJFFadG/qHqHjcEbO2kHC58lb1 5oDobfwWydzR44HpNejVM0UwhtS78LhHYnqTQPBs5jmoT8ob2yQsMVz/gKNNNmt+xclO y/0Rf2RZEZnp+X1STwBE1JBT++T9KFMYae/aczlE8kb4XAwTMWAZdOVLu0/EQubRX0Jo DFXQ== X-Forwarded-Encrypted: i=1; AJvYcCW9TZ7214M/eiCRuwarJeC7DB8OiXGpxOZQnG2YSCJeRIeEe1mhY3vlqbY0UcBjc1k2gZr454VGMg==@vger.kernel.org X-Gm-Message-State: AOJu0YyzYLPOgDuJ9tpdg3+rQOzWDHGo6gWyIycieaPIFWXSxeEDQoC3 VIKVr+wWGy9dqYGB+clGJ8uTCU2mGfSVLH/Plb80pQXq/tbxk2rGBdDa/fj9WDw= X-Gm-Gg: ASbGncsKmNd6hWjJ8kJ18JGpjCA5zCiP6EHZbiSFGBQjTn1b9pzfiee+tghMJt/M2nk z/qb50D1sNeavAiWNx8C5iKydVk2UAXkr0eQdNyb90YrJzxznh561Z3PRcKOg3jd8Rz4jUhLCM+ K0dqptEhwWAmtYDrsdJBcLP4WrnryNhv8csTnGCHf+p1o9jkPu+BveBvzNwhTmD1KIQm1aHKXd4 GEmWTfht5nZpq2rDL+kX2EuBRqMr2OCi7GbMjb/RZT5ycSsfcASyekLZPOEU+ePNfMBlCkaTgR/ r8YW9Mh5QRYCs/T5ov9GunhhYrY+KpjSzYzaBdTIMLUE4PjTl31n X-Google-Smtp-Source: AGHT+IH07Yj9Qvao1dL/i/uJ11l1+IF+hLKC6pC8RZiwmzbA3oxsha39/3dVJTGMAck9cT2f2/d5Tw== X-Received: by 2002:a17:903:1b23:b0:223:53fb:e1dd with SMTP id d9443c01a7336-22db3bb2ce3mr29840195ad.9.1745491036240; Thu, 24 Apr 2025 03:37:16 -0700 (PDT) Received: from localhost ([122.172.83.32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db51021a8sm9782395ad.172.2025.04.24.03.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 03:37:15 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH 4/6] OPP: Use scope-based OF cleanup helpers Date: Thu, 24 Apr 2025 16:06:47 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the OF scope-based cleanup helpers for the OPP core. No intentional functional impact. Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 111 +++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 71 deletions(-) diff --git a/drivers/opp/of.c b/drivers/opp/of.c index c240acc81a8d..aa43fbfa3e50 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -45,7 +45,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node); struct opp_table *_managed_opp(struct device *dev, int index) { struct opp_table *opp_table, *managed_table = NULL; - struct device_node *np; + struct device_node *np __free(device_node); np = _opp_of_get_opp_desc_node(dev->of_node, index); if (!np) @@ -67,8 +67,6 @@ struct opp_table *_managed_opp(struct device *dev, int index) } } - of_node_put(np); - return managed_table; } @@ -102,16 +100,13 @@ static struct device_node *of_parse_required_opp(struct device_node *np, /* The caller must call dev_pm_opp_put_opp_table() after the table is used */ static struct opp_table *_find_table_of_opp_np(struct device_node *opp_np) { + struct device_node *opp_table_np __free(device_node); struct opp_table *opp_table; - struct device_node *opp_table_np; opp_table_np = of_get_parent(opp_np); if (!opp_table_np) goto err; - /* It is safe to put the node now as all we need now is its address */ - of_node_put(opp_table_np); - mutex_lock(&opp_table_lock); list_for_each_entry(opp_table, &opp_tables, node) { if (opp_table_np == opp_table->np) { @@ -161,7 +156,7 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, struct device_node *opp_np) { struct opp_table **required_opp_tables; - struct device_node *required_np, *np; + struct device_node *np __free(device_node); bool lazy = false; int count, i, size; @@ -169,30 +164,32 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, np = of_get_next_available_child(opp_np, NULL); if (!np) { dev_warn(dev, "Empty OPP table\n"); - return; } count = of_count_phandle_with_args(np, "required-opps", NULL); if (count <= 0) - goto put_np; + return; size = sizeof(*required_opp_tables) + sizeof(*opp_table->required_devs); required_opp_tables = kcalloc(count, size, GFP_KERNEL); if (!required_opp_tables) - goto put_np; + return; opp_table->required_opp_tables = required_opp_tables; opp_table->required_devs = (void *)(required_opp_tables + count); opp_table->required_opp_count = count; for (i = 0; i < count; i++) { + struct device_node *required_np __free(device_node); + required_np = of_parse_required_opp(np, i); - if (!required_np) - goto free_required_tables; + if (!required_np) { + _opp_table_free_required_tables(opp_table); + return; + } required_opp_tables[i] = _find_table_of_opp_np(required_np); - of_node_put(required_np); if (IS_ERR(required_opp_tables[i])) lazy = true; @@ -208,19 +205,12 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, list_add(&opp_table->lazy, &lazy_opp_tables); mutex_unlock(&opp_table_lock); } - - goto put_np; - -free_required_tables: - _opp_table_free_required_tables(opp_table); -put_np: - of_node_put(np); } void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) { - struct device_node *np, *opp_np; + struct device_node *np __free(device_node), *opp_np; u32 val; /* @@ -241,8 +231,6 @@ void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, /* Get OPP table node */ opp_np = _opp_of_get_opp_desc_node(np, index); - of_node_put(np); - if (!opp_np) return; @@ -296,15 +284,13 @@ void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp) static int _link_required_opps(struct dev_pm_opp *opp, struct opp_table *required_table, int index) { - struct device_node *np; + struct device_node *np __free(device_node); np = of_parse_required_opp(opp->np, index); if (unlikely(!np)) return -ENODEV; opp->required_opps[index] = _find_opp_of_np(required_table, np); - of_node_put(np); - if (!opp->required_opps[index]) { pr_err("%s: Unable to find required OPP node: %pOF (%d)\n", __func__, opp->np, index); @@ -368,19 +354,22 @@ static int lazy_link_required_opps(struct opp_table *opp_table, static void lazy_link_required_opp_table(struct opp_table *new_table) { struct opp_table *opp_table, *temp, **required_opp_tables; - struct device_node *required_np, *opp_np, *required_table_np; struct dev_pm_opp *opp; int i, ret; mutex_lock(&opp_table_lock); list_for_each_entry_safe(opp_table, temp, &lazy_opp_tables, lazy) { + struct device_node *opp_np __free(device_node); bool lazy = false; /* opp_np can't be invalid here */ opp_np = of_get_next_available_child(opp_table->np, NULL); for (i = 0; i < opp_table->required_opp_count; i++) { + struct device_node *required_np __free(device_node) = NULL; + struct device_node *required_table_np __free(device_node) = NULL; + required_opp_tables = opp_table->required_opp_tables; /* Required opp-table is already parsed */ @@ -391,9 +380,6 @@ static void lazy_link_required_opp_table(struct opp_table *new_table) required_np = of_parse_required_opp(opp_np, i); required_table_np = of_get_parent(required_np); - of_node_put(required_table_np); - of_node_put(required_np); - /* * Newly added table isn't the required opp-table for * opp_table. @@ -414,8 +400,6 @@ static void lazy_link_required_opp_table(struct opp_table *new_table) } } - of_node_put(opp_np); - /* All required opp-tables found, remove from lazy list */ if (!lazy) { list_del_init(&opp_table->lazy); @@ -430,16 +414,18 @@ static void lazy_link_required_opp_table(struct opp_table *new_table) static int _bandwidth_supported(struct device *dev, struct opp_table *opp_table) { - struct device_node *np, *opp_np; + struct device_node *opp_np __free(device_node) = NULL; + struct device_node *np __free(device_node) = NULL; struct property *prop; if (!opp_table) { + struct device_node *np __free(device_node); + np = of_node_get(dev->of_node); if (!np) return -ENODEV; opp_np = _opp_of_get_opp_desc_node(np, 0); - of_node_put(np); } else { opp_np = of_node_get(opp_table->np); } @@ -450,15 +436,12 @@ static int _bandwidth_supported(struct device *dev, struct opp_table *opp_table) /* Checking only first OPP is sufficient */ np = of_get_next_available_child(opp_np, NULL); - of_node_put(opp_np); if (!np) { dev_err(dev, "OPP table empty\n"); return -EINVAL; } prop = of_find_property(np, "opp-peak-kBps", NULL); - of_node_put(np); - if (!prop || !prop->length) return 0; @@ -468,7 +451,7 @@ static int _bandwidth_supported(struct device *dev, struct opp_table *opp_table) int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table) { - struct device_node *np; + struct device_node *np __free(device_node) = of_node_get(dev->of_node); int ret, i, count, num_paths; struct icc_path **paths; @@ -478,15 +461,13 @@ int dev_pm_opp_of_find_icc_paths(struct device *dev, else if (ret <= 0) return ret; - ret = 0; - - np = of_node_get(dev->of_node); if (!np) return 0; + ret = 0; + count = of_count_phandle_with_args(np, "interconnects", "#interconnect-cells"); - of_node_put(np); if (count < 0) return 0; @@ -1303,8 +1284,8 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table); int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) { - struct device_node *np, *tmp_np, *cpu_np; - int cpu, ret = 0; + struct device_node *np __free(device_node); + int cpu; /* Get OPP descriptor node */ np = dev_pm_opp_of_get_opp_desc_node(cpu_dev); @@ -1317,9 +1298,12 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, /* OPPs are shared ? */ if (!of_property_read_bool(np, "opp-shared")) - goto put_cpu_node; + return 0; for_each_possible_cpu(cpu) { + struct device_node *cpu_np __free(device_node) = NULL; + struct device_node *tmp_np __free(device_node) = NULL; + if (cpu == cpu_dev->id) continue; @@ -1327,29 +1311,22 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, if (!cpu_np) { dev_err(cpu_dev, "%s: failed to get cpu%d node\n", __func__, cpu); - ret = -ENOENT; - goto put_cpu_node; + return -ENOENT; } /* Get OPP descriptor node */ tmp_np = _opp_of_get_opp_desc_node(cpu_np, 0); - of_node_put(cpu_np); if (!tmp_np) { pr_err("%pOF: Couldn't find opp node\n", cpu_np); - ret = -ENOENT; - goto put_cpu_node; + return -ENOENT; } /* CPUs are sharing opp node */ if (np == tmp_np) cpumask_set_cpu(cpu, cpumask); - - of_node_put(tmp_np); } -put_cpu_node: - of_node_put(np); - return ret; + return 0; } EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus); @@ -1366,9 +1343,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus); */ int of_get_required_opp_performance_state(struct device_node *np, int index) { - struct dev_pm_opp *opp; - struct device_node *required_np; + struct device_node *required_np __free(device_node); struct opp_table *opp_table; + struct dev_pm_opp *opp; int pstate = -EINVAL; required_np = of_parse_required_opp(np, index); @@ -1379,13 +1356,13 @@ int of_get_required_opp_performance_state(struct device_node *np, int index) if (IS_ERR(opp_table)) { pr_err("%s: Failed to find required OPP table %pOF: %ld\n", __func__, np, PTR_ERR(opp_table)); - goto put_required_np; + return PTR_ERR(opp_table); } /* The OPP tables must belong to a genpd */ if (unlikely(!opp_table->is_genpd)) { pr_err("%s: Performance state is only valid for genpds.\n", __func__); - goto put_required_np; + return -EINVAL; } opp = _find_opp_of_np(opp_table, required_np); @@ -1401,10 +1378,6 @@ int of_get_required_opp_performance_state(struct device_node *np, int index) } dev_pm_opp_put_opp_table(opp_table); - -put_required_np: - of_node_put(required_np); - return pstate; } EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state); @@ -1421,7 +1394,7 @@ EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state); */ bool dev_pm_opp_of_has_required_opp(struct device *dev) { - struct device_node *opp_np, *np; + struct device_node *np __free(device_node) = NULL, *opp_np __free(device_node); int count; opp_np = _opp_of_get_opp_desc_node(dev->of_node, 0); @@ -1429,14 +1402,12 @@ bool dev_pm_opp_of_has_required_opp(struct device *dev) return false; np = of_get_next_available_child(opp_np, NULL); - of_node_put(opp_np); if (!np) { dev_warn(dev, "Empty OPP table\n"); return false; } count = of_count_phandle_with_args(np, "required-opps", NULL); - of_node_put(np); return count > 0; } @@ -1513,8 +1484,8 @@ _get_dt_power(struct device *dev, unsigned long *uW, unsigned long *kHz) int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW, unsigned long *kHz) { + struct device_node *np __free(device_node); struct dev_pm_opp *opp; - struct device_node *np; unsigned long mV, Hz; u32 cap; u64 tmp; @@ -1525,7 +1496,6 @@ int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW, return -EINVAL; ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); - of_node_put(np); if (ret) return -EINVAL; @@ -1581,8 +1551,8 @@ static bool _of_has_opp_microwatt_property(struct device *dev) */ int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus) { + struct device_node *np __free(device_node) = NULL; struct em_data_callback em_cb; - struct device_node *np; int ret, nr_opp; u32 cap; @@ -1617,7 +1587,6 @@ int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus) * user about the inconsistent configuration. */ ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); - of_node_put(np); if (ret || !cap) { dev_dbg(dev, "Couldn't find proper 'dynamic-power-coefficient' in DT\n"); ret = -EINVAL; From patchwork Thu Apr 24 10:36:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 884172 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26DDE23D283 for ; Thu, 24 Apr 2025 10:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491047; cv=none; b=b9iiHjCIv9jblLndLfh6QpEA2kqPcMJqiWduAZoSyhemwplejVi+YA3PCMqBSrx1wabZ9PMVbLcb1gEhLRqarULrrezmmgMB69gVcTRovhe7lyd6SoXkoVTDqHCi0v9IpCsviPygr1xZWWKKujHBbezWTZ0BzOQWPMgaaNOFT+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491047; c=relaxed/simple; bh=TmOGFV0w7v62MJ6x8MwidOrdpKY+8DJsmTGwPxqGrNo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DYJv7VnB2RSP2FMB3+c61EX0fgViCLEUFWa/Hmqzl6iE5ium0ZYYbJOdiewuZwIKwl7aSOIX60kKy01NDAaYEXtFrES1ReqXdf5CkQtwMBsQTvrI24tpwlCIh6vEbvheFSQsExRYLtZbbUQC04YvfEGOLQkwH8W3YJEtj975csg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Vp2ggoii; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Vp2ggoii" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2243803b776so13840355ad.0 for ; Thu, 24 Apr 2025 03:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745491044; x=1746095844; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iBwTEXhNABTCQyq0u1UG76AK2UVABOzq6NwLkHUAp5g=; b=Vp2ggoiivVf0XCFeNd31Q4L7yILXFVinhCqydSUDyl5zachVO/GIusHto53YTjd8bE 5qLMnP40afg9Fe3jABFM+j9xJgZV1LUi/voiyBxJgPA2D0uvAOLhUYnAZ4xJIGAMIaJw gN45pvxF1Sfx7Ub0ZpwQ5j09C/X+B01oQzk7R0ozVtzKIUU3M/TQOcSyG026mZyRp7cX ZRScYjMafxaoUHP3R8HPdqY+51RjTlL1zaQDhdOYMe3aQoRvsMbAKawh6hPO721DJGzZ qwlXiAjmffr8P/M3E1/Bk6S2q6vCsRWsfVBB0vXSefWLyw4fc6r1qw8bMTETeLqyqXau zvSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745491044; x=1746095844; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iBwTEXhNABTCQyq0u1UG76AK2UVABOzq6NwLkHUAp5g=; b=M/vRlN+ZxPJ3dZf+ISAhOVpSV/dDbWE3M/Yjf33sJSY+knxGwmEwCOmdE3D73x66E4 TZpFk82TZbE5mBzLG6vOMXe5aaRX1IZBQB4+0rakW5TsCcoDQZJSCnxRpKkerUWTf+Rq 1Rd5grvIPYaEERsFzUWbZSHU/ypzzpQCbSm+Bse8tV3/m9MQiq25Q8xUbNBw95K+HcUX 6C7CTguMvaJtUhFF2JxVONgqniUk9XMhbsaUei3jrEDtgqXTo2vo93JpC9p4uPMig84W 9J6CbN8hC/uZfiCflfXOWZN3o8/IQL2J4omyy0XEM1v4FM+L0Ld9uKB1z6up6awpxOGy 9vtQ== X-Forwarded-Encrypted: i=1; AJvYcCXlc5WUZQNjQhyjSl9AAoDWqgkObSWCaAsE8HsutGXds4aQv5swGD5sfchjiZ2rB/0xiLDD+KPq+A==@vger.kernel.org X-Gm-Message-State: AOJu0Yxq+pQoLQ338Abps+8M3+2gZJqhj+72MrTSzzPuMW6A7kGZsDFt GwZ3h63LogJ7Q2SBuY6yRbr1A76/o8W4gyPa/xq+1I9LAHL6t94ou4rqd+9TV3I= X-Gm-Gg: ASbGncvO7jKi5dlSCkQAosIO4ERSE7RbCtmnNhf5MPuqJ3UIxXo47vKQn7VkKhu5C+B gqdkFyfXn2oYh9H9MfkyviFNRgKWGbAl+NAp/3U13xMubqZWDVpph0Z4KLHKbDr4m4FWMvvG4Xn G4zRpFqQ6Sb/UzUYBPb/91RENR2cNcBoo94IY2xWZ9Td3Yn3BvuJb+HqP3TPK2Ar97SC/zxvASk pt4utb6W6DPqhslbn3jkYhS2WJIg+TWxv0hAQHN2MipgxDPWXHjz11/kdsDf3XHY1olPf59vhp3 xv8c30sju4EaInUAGUhbz4aNEpOInwILZJTudGX6u9xf/78j/gj+ X-Google-Smtp-Source: AGHT+IFsvSHzdGeWlWocErZ1QgNQTv5wJHcxn0cYwaK4A27pHPX0GIC28/2OjZnhyv7cYx3YbtgU6Q== X-Received: by 2002:a17:902:d2ce:b0:21b:d105:26b8 with SMTP id d9443c01a7336-22db3bb1e1cmr24994525ad.7.1745491044394; Thu, 24 Apr 2025 03:37:24 -0700 (PDT) Received: from localhost ([122.172.83.32]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22db50e7681sm9868985ad.119.2025.04.24.03.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 03:37:23 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH 6/6] OPP: Use mutex locking guards Date: Thu, 24 Apr 2025 16:06:49 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use mutex locking guard in the OPP core. No intentional functional impact. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 201 ++++++++++++++++++--------------------------- drivers/opp/cpu.c | 3 +- drivers/opp/of.c | 65 ++++++--------- 3 files changed, 105 insertions(+), 164 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 87d27132cd87..fc9874946453 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -40,17 +40,14 @@ static DEFINE_XARRAY_ALLOC1(opp_configs); static bool _find_opp_dev(const struct device *dev, struct opp_table *opp_table) { struct opp_device *opp_dev; - bool found = false; - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); + list_for_each_entry(opp_dev, &opp_table->dev_list, node) - if (opp_dev->dev == dev) { - found = true; - break; - } + if (opp_dev->dev == dev) + return true; - mutex_unlock(&opp_table->lock); - return found; + return false; } static struct opp_table *_find_opp_table_unlocked(struct device *dev) @@ -78,18 +75,13 @@ static struct opp_table *_find_opp_table_unlocked(struct device *dev) */ struct opp_table *_find_opp_table(struct device *dev) { - struct opp_table *opp_table; - if (IS_ERR_OR_NULL(dev)) { pr_err("%s: Invalid parameters\n", __func__); return ERR_PTR(-EINVAL); } - mutex_lock(&opp_table_lock); - opp_table = _find_opp_table_unlocked(dev); - mutex_unlock(&opp_table_lock); - - return opp_table; + guard(mutex)(&opp_table_lock); + return _find_opp_table_unlocked(dev); } /* @@ -359,25 +351,23 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) if (!uV) return 0; - mutex_lock(&opp_table->lock); - - for (i = 0; i < count; i++) { - uV[i].min = ~0; - uV[i].max = 0; + scoped_guard(mutex, &opp_table->lock) { + for (i = 0; i < count; i++) { + uV[i].min = ~0; + uV[i].max = 0; - list_for_each_entry(opp, &opp_table->opp_list, node) { - if (!opp->available) - continue; + list_for_each_entry(opp, &opp_table->opp_list, node) { + if (!opp->available) + continue; - if (opp->supplies[i].u_volt_min < uV[i].min) - uV[i].min = opp->supplies[i].u_volt_min; - if (opp->supplies[i].u_volt_max > uV[i].max) - uV[i].max = opp->supplies[i].u_volt_max; + if (opp->supplies[i].u_volt_min < uV[i].min) + uV[i].min = opp->supplies[i].u_volt_min; + if (opp->supplies[i].u_volt_max > uV[i].max) + uV[i].max = opp->supplies[i].u_volt_max; + } } } - mutex_unlock(&opp_table->lock); - /* * The caller needs to ensure that opp_table (and hence the regulator) * isn't freed, while we are executing this routine. @@ -438,15 +428,13 @@ int _get_opp_count(struct opp_table *opp_table) struct dev_pm_opp *opp; int count = 0; - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); list_for_each_entry(opp, &opp_table->opp_list, node) { if (opp->available) count++; } - mutex_unlock(&opp_table->lock); - return count; } @@ -535,7 +523,7 @@ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table, if (assert && !assert(opp_table, index)) return ERR_PTR(-EINVAL); - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); list_for_each_entry(temp_opp, &opp_table->opp_list, node) { if (temp_opp->available == available) { @@ -550,8 +538,6 @@ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table, dev_pm_opp_get(opp); } - mutex_unlock(&opp_table->lock); - return opp; } @@ -1166,10 +1152,9 @@ static void _find_current_opp(struct device *dev, struct opp_table *opp_table) * make special checks to validate current_opp. */ if (IS_ERR(opp)) { - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); opp = dev_pm_opp_get(list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node)); - mutex_unlock(&opp_table->lock); } opp_table->current_opp = opp; @@ -1426,9 +1411,8 @@ struct opp_device *_add_opp_dev(const struct device *dev, /* Initialize opp-dev */ opp_dev->dev = dev; - mutex_lock(&opp_table->lock); - list_add(&opp_dev->node, &opp_table->dev_list); - mutex_unlock(&opp_table->lock); + scoped_guard(mutex, &opp_table->lock) + list_add(&opp_dev->node, &opp_table->dev_list); /* Create debugfs entries for the opp_table */ opp_debug_register(opp_dev, opp_table); @@ -1721,17 +1705,15 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) if (!assert_single_clk(opp_table, 0)) return; - mutex_lock(&opp_table->lock); - - list_for_each_entry(iter, &opp_table->opp_list, node) { - if (iter->rates[0] == freq) { - opp = iter; - break; + scoped_guard(mutex, &opp_table->lock) { + list_for_each_entry(iter, &opp_table->opp_list, node) { + if (iter->rates[0] == freq) { + opp = iter; + break; + } } } - mutex_unlock(&opp_table->lock); - if (opp) { dev_pm_opp_put(opp); @@ -1747,22 +1729,20 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_remove); static struct dev_pm_opp *_opp_get_next(struct opp_table *opp_table, bool dynamic) { - struct dev_pm_opp *opp = NULL, *temp; + struct dev_pm_opp *opp; - mutex_lock(&opp_table->lock); - list_for_each_entry(temp, &opp_table->opp_list, node) { + guard(mutex)(&opp_table->lock); + + list_for_each_entry(opp, &opp_table->opp_list, node) { /* * Refcount must be dropped only once for each OPP by OPP core, * do that with help of "removed" flag. */ - if (!temp->removed && dynamic == temp->dynamic) { - opp = temp; - break; - } + if (!opp->removed && dynamic == opp->dynamic) + return opp; } - mutex_unlock(&opp_table->lock); - return opp; + return NULL; } /* @@ -1786,20 +1766,14 @@ static void _opp_remove_all(struct opp_table *opp_table, bool dynamic) bool _opp_remove_all_static(struct opp_table *opp_table) { - mutex_lock(&opp_table->lock); - - if (!opp_table->parsed_static_opps) { - mutex_unlock(&opp_table->lock); - return false; - } + scoped_guard(mutex, &opp_table->lock) { + if (!opp_table->parsed_static_opps) + return false; - if (--opp_table->parsed_static_opps) { - mutex_unlock(&opp_table->lock); - return true; + if (--opp_table->parsed_static_opps) + return true; } - mutex_unlock(&opp_table->lock); - _opp_remove_all(opp_table, false); return true; } @@ -2003,17 +1977,15 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct list_head *head; int ret; - mutex_lock(&opp_table->lock); - head = &opp_table->opp_list; + scoped_guard(mutex, &opp_table->lock) { + head = &opp_table->opp_list; - ret = _opp_is_duplicate(dev, new_opp, opp_table, &head); - if (ret) { - mutex_unlock(&opp_table->lock); - return ret; - } + ret = _opp_is_duplicate(dev, new_opp, opp_table, &head); + if (ret) + return ret; - list_add(&new_opp->node, head); - mutex_unlock(&opp_table->lock); + list_add(&new_opp->node, head); + } new_opp->opp_table = opp_table; kref_init(&new_opp->kref); @@ -2660,17 +2632,16 @@ struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, return ERR_PTR(-EBUSY); for (i = 0; i < src_table->required_opp_count; i++) { - if (src_table->required_opp_tables[i] == dst_table) { - mutex_lock(&src_table->lock); + if (src_table->required_opp_tables[i] != dst_table) + continue; + scoped_guard(mutex, &src_table->lock) { list_for_each_entry(opp, &src_table->opp_list, node) { if (opp == src_opp) { dest_opp = dev_pm_opp_get(opp->required_opps[i]); break; } } - - mutex_unlock(&src_table->lock); break; } } @@ -2702,7 +2673,6 @@ int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, unsigned int pstate) { struct dev_pm_opp *opp; - int dest_pstate = -EINVAL; int i; /* @@ -2736,22 +2706,17 @@ int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, return -EINVAL; } - mutex_lock(&src_table->lock); + guard(mutex)(&src_table->lock); list_for_each_entry(opp, &src_table->opp_list, node) { - if (opp->level == pstate) { - dest_pstate = opp->required_opps[i]->level; - goto unlock; - } + if (opp->level == pstate) + return opp->required_opps[i]->level; } pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__, src_table, dst_table); -unlock: - mutex_unlock(&src_table->lock); - - return dest_pstate; + return -EINVAL; } /** @@ -2820,26 +2785,22 @@ static int _opp_set_availability(struct device *dev, unsigned long freq, if (!assert_single_clk(opp_table, 0)) return -EINVAL; - mutex_lock(&opp_table->lock); + scoped_guard(mutex, &opp_table->lock) { + /* Do we have the frequency? */ + list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { + if (tmp_opp->rates[0] == freq) { + opp = dev_pm_opp_get(tmp_opp); - /* Do we have the frequency? */ - list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { - if (tmp_opp->rates[0] == freq) { - opp = dev_pm_opp_get(tmp_opp); + /* Is update really needed? */ + if (opp->available == availability_req) + return 0; - /* Is update really needed? */ - if (opp->available == availability_req) { - mutex_unlock(&opp_table->lock); - return 0; + opp->available = availability_req; + break; } - - opp->available = availability_req; - break; } } - mutex_unlock(&opp_table->lock); - if (IS_ERR(opp)) return PTR_ERR(opp); @@ -2886,29 +2847,25 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, if (!assert_single_clk(opp_table, 0)) return -EINVAL; - mutex_lock(&opp_table->lock); - - /* Do we have the frequency? */ - list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { - if (tmp_opp->rates[0] == freq) { - opp = dev_pm_opp_get(tmp_opp); + scoped_guard(mutex, &opp_table->lock) { + /* Do we have the frequency? */ + list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { + if (tmp_opp->rates[0] == freq) { + opp = dev_pm_opp_get(tmp_opp); - /* Is update really needed? */ - if (opp->supplies->u_volt == u_volt) { - mutex_unlock(&opp_table->lock); - return 0; - } + /* Is update really needed? */ + if (opp->supplies->u_volt == u_volt) + return 0; - opp->supplies->u_volt = u_volt; - opp->supplies->u_volt_min = u_volt_min; - opp->supplies->u_volt_max = u_volt_max; + opp->supplies->u_volt = u_volt; + opp->supplies->u_volt_min = u_volt_min; + opp->supplies->u_volt_max = u_volt_max; - break; + break; + } } } - mutex_unlock(&opp_table->lock); - if (IS_ERR(opp)) return PTR_ERR(opp); diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 330a1753fb22..97989d4fe336 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -214,10 +214,9 @@ int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) cpumask_clear(cpumask); if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) { - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); list_for_each_entry(opp_dev, &opp_table->dev_list, node) cpumask_set_cpu(opp_dev->dev->id, cpumask); - mutex_unlock(&opp_table->lock); } else { cpumask_set_cpu(cpu_dev->id, cpumask); } diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 54109e813d4f..505d79821584 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -76,18 +76,13 @@ static struct dev_pm_opp *_find_opp_of_np(struct opp_table *opp_table, { struct dev_pm_opp *opp; - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); list_for_each_entry(opp, &opp_table->opp_list, node) { - if (opp->np == opp_np) { - dev_pm_opp_get(opp); - mutex_unlock(&opp_table->lock); - return opp; - } + if (opp->np == opp_np) + return dev_pm_opp_get(opp); } - mutex_unlock(&opp_table->lock); - return NULL; } @@ -105,19 +100,15 @@ static struct opp_table *_find_table_of_opp_np(struct device_node *opp_np) opp_table_np = of_get_parent(opp_np); if (!opp_table_np) - goto err; + return ERR_PTR(-ENODEV); + + guard(mutex)(&opp_table_lock); - mutex_lock(&opp_table_lock); list_for_each_entry(opp_table, &opp_tables, node) { - if (opp_table_np == opp_table->np) { - dev_pm_opp_get_opp_table_ref(opp_table); - mutex_unlock(&opp_table_lock); - return opp_table; - } + if (opp_table_np == opp_table->np) + return dev_pm_opp_get_opp_table_ref(opp_table); } - mutex_unlock(&opp_table_lock); -err: return ERR_PTR(-ENODEV); } @@ -142,9 +133,8 @@ static void _opp_table_free_required_tables(struct opp_table *opp_table) opp_table->required_opp_count = 0; opp_table->required_opp_tables = NULL; - mutex_lock(&opp_table_lock); + guard(mutex)(&opp_table_lock); list_del(&opp_table->lazy); - mutex_unlock(&opp_table_lock); } /* @@ -201,9 +191,8 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table, * The OPP table is not held while allocating the table, take it * now to avoid corruption to the lazy_opp_tables list. */ - mutex_lock(&opp_table_lock); + guard(mutex)(&opp_table_lock); list_add(&opp_table->lazy, &lazy_opp_tables); - mutex_unlock(&opp_table_lock); } } @@ -357,7 +346,7 @@ static void lazy_link_required_opp_table(struct opp_table *new_table) struct dev_pm_opp *opp; int i, ret; - mutex_lock(&opp_table_lock); + guard(mutex)(&opp_table_lock); list_for_each_entry_safe(opp_table, temp, &lazy_opp_tables, lazy) { struct device_node *opp_np __free(device_node); @@ -408,8 +397,6 @@ static void lazy_link_required_opp_table(struct opp_table *new_table) _required_opps_available(opp, opp_table->required_opp_count); } } - - mutex_unlock(&opp_table_lock); } static int _bandwidth_supported(struct device *dev, struct opp_table *opp_table) @@ -970,15 +957,14 @@ static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table) struct dev_pm_opp *opp; /* OPP table is already initialized for the device */ - mutex_lock(&opp_table->lock); - if (opp_table->parsed_static_opps) { - opp_table->parsed_static_opps++; - mutex_unlock(&opp_table->lock); - return 0; - } + scoped_guard(mutex, &opp_table->lock) { + if (opp_table->parsed_static_opps) { + opp_table->parsed_static_opps++; + return 0; + } - opp_table->parsed_static_opps = 1; - mutex_unlock(&opp_table->lock); + opp_table->parsed_static_opps = 1; + } /* We have opp-table node now, iterate over it and add OPPs */ for_each_available_child_of_node(opp_table->np, np) { @@ -1018,15 +1004,14 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table) const __be32 *val; int nr, ret = 0; - mutex_lock(&opp_table->lock); - if (opp_table->parsed_static_opps) { - opp_table->parsed_static_opps++; - mutex_unlock(&opp_table->lock); - return 0; - } + scoped_guard(mutex, &opp_table->lock) { + if (opp_table->parsed_static_opps) { + opp_table->parsed_static_opps++; + return 0; + } - opp_table->parsed_static_opps = 1; - mutex_unlock(&opp_table->lock); + opp_table->parsed_static_opps = 1; + } prop = of_find_property(dev->of_node, "operating-points", NULL); if (!prop) {