From nobody Mon Feb 9 07:19:43 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 0012C2356C7 for ; Thu, 24 Apr 2025 10:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491028; cv=none; b=a3NdBxDDS/+i/aC1z9JmvSFtOw5S9Bi3MQVq2WWPkfejBKmQLcdUo+xB5BeghHjg0JCiwiULGlk2yaog52zhBV/yOHWgCEHcmj4lu9m8J92+ckSV+uCeTFHkfSdXYXeisVNHeKJ0nk9v95ekUlxNsmhVIezpODGLhhGC8wNdo8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491028; c=relaxed/simple; bh=TmyMfVSZePGbf+pWUXHYOQIK/ZRvODD/YG8yNgg3Q9M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fXdtSZtMOCZJD4WzhOE46/s2UA6K2AtCNGff4jEMz2BA5GgV6yqVGy0srw0BNMmqsKoThaaZ2bnFiDk1nZX/ANbBkff/DfmcF6F/c6CZJ5WEcBVnuMXLxme4D1a5dWRyBxNlOVe2eXAxX9WjCa7VwpsMXOyjwkZXZHfjSzh537Q= 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=Cp5Y7h2G; arc=none smtp.client-ip=209.85.216.46 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="Cp5Y7h2G" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-301302a328bso1144121a91.2 for ; Thu, 24 Apr 2025 03:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745491025; x=1746095825; 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=vb0kshWFEdfqSwCojCAxnGSpz+cJLNiZV1M7W+IRDC4=; b=Cp5Y7h2GxkpjrgXRzFMOBTzp1lSRycew8uUsbpHj1B3ROGv4lV/ncm3TL0hv+5o0BE ymGlHI3Ikm6WseiGvuUFyJV3Tw3qfQrXDuc0NqM9LI6LN/o1zP5zxnlmmJHdEbbh8mpe 6PzWVq3uIn3pTtC+BTpoekbgINR2fBToumDdEI1QvhaLNoA/0MrH6KNK8DN/3E17ZRro RuOAIKRtFFNrXDV0WCfAxXpzmyuHooJyQt4hWFpRVZ2k0yDRpvG5x8f2iaT6kYjqbDyL donVxSG3DCxO/9w3VWS16bCuEiCE9I9cQYjxFCyl4U5SQ+LbGD59sabuYDFnIzrlQwuj qndQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745491025; x=1746095825; 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=vb0kshWFEdfqSwCojCAxnGSpz+cJLNiZV1M7W+IRDC4=; b=O/xdvBEqosbI8Ztz34Svyzth618PlHUOp9+/uUWSCLFVfYklRw01UmLPfPL+PcEbbi Nwx/vtGmm6eufUNMsPTM9xhKpSEL9ooBRhM4aWV73bon6K8qO4sXm7qX6PeM6CDqfKGY RTND/yu8ahFoIxi+sJhe3PN4mclpw5DKOvQOTlyfBuIKmXv18YOsV3FNS/kJPbYf2tiu eK+m7wHDDUeEIZZ3j48OfRHagIxhnN04ybaPkauy05i+Tjh20km4DkK8m3G/Csa2sLZ0 /mqoHzNJpTJk9YJg5m7fKJrT6AvTlSq2XfYNlDgYc2sHk5Km9FpDXBZAkNRL+LrXG6P9 Z9xQ== X-Forwarded-Encrypted: i=1; AJvYcCWt8WUU/yIcpAMBgIVrjYGIO2TOc5s2EbHd3iOm/qKSrQ2kfBfTCp0a9mk5V/bow2WNIhaW+zDK03efJno=@vger.kernel.org X-Gm-Message-State: AOJu0YzDbCPQ7LyD0BEbMR7vfHNrv+CsnUK/92Q1keQQch3m8zThod9w Q8qT1dhWebR8m2aDmrcexPFA/ynQFeZz8jdVDfu1mZQQ+w6OYNh9/zyiYIgc4A4= X-Gm-Gg: ASbGncsG286XtKFaBz2WKBP5a8ZgRcZV56asHY8V0PHXbKY/lUkQTvmn3CiQXGKHk5k gBgcKKWpyrogDp6R1VL5k2YlrDtD9+CxwivOpOXxPAOFXhjdiWZENvt1Gpt75BuhJ2MC8TAP0EW V3pp28EtCCdn7LSrRMcbrYqjKRQ+mhJjEPqzvQC71iUVDXiYFhb+JtQADBjdw1ZOUyvAQsJL9mZ 5tZkYqToC7h4uXXN1OAhW9PCqLV7DSm5g01UJTER/TRgC6QdxtL27O0fEzPEV3aSBxy8Gj/PktG nxMh48YYdUVHnuJhMQUakw7MhlRpKK3BdP6WewLN1w== X-Google-Smtp-Source: AGHT+IFZZsVLcW4BUe+ZrSM6uW6Wa2ikYA0R9RA3RPc1tiMPNWk4codtXgnN6tMcSgjrfAqGLXPdIA== X-Received: by 2002:a17:90a:f945:b0:2f6:be57:49d2 with SMTP id 98e67ed59e1d1-309ed29c8d8mr3487943a91.17.1745491025233; Thu, 24 Apr 2025 03:37:05 -0700 (PDT) Received: from localhost ([122.172.83.32]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-309ef0d5c72sm987560a91.43.2025.04.24.03.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 03:37:04 -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 1/6] OPP: Remove _get_opp_table_kref() Date: Thu, 24 Apr 2025 16:06:44 +0530 Message-Id: <4cb1383f9522a3d2f5e26b70688417187c7d48e4.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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use dev_pm_opp_get_opp_table_ref() directly instead. No intentional functional impact. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 9 ++------- drivers/opp/of.c | 6 +++--- drivers/opp/opp.h | 1 - 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 73e9a3b2f29b..e63a9b009df1 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -59,7 +59,7 @@ static struct opp_table *_find_opp_table_unlocked(struct = device *dev) =20 list_for_each_entry(opp_table, &opp_tables, node) { if (_find_opp_dev(dev, opp_table)) { - _get_opp_table_kref(opp_table); + dev_pm_opp_get_opp_table_ref(opp_table); return opp_table; } } @@ -1688,14 +1688,9 @@ static void _opp_table_kref_release(struct kref *kre= f) kfree(opp_table); } =20 -void _get_opp_table_kref(struct opp_table *opp_table) -{ - kref_get(&opp_table->kref); -} - void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) { - _get_opp_table_kref(opp_table); + kref_get(&opp_table->kref); } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table_ref); =20 diff --git a/drivers/opp/of.c b/drivers/opp/of.c index a24f76f5fd01..87cb6aeb49ed 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -61,7 +61,7 @@ struct opp_table *_managed_opp(struct device *dev, int in= dex) * OPP table contains a "opp-shared" property. */ if (opp_table->shared_opp =3D=3D OPP_TABLE_ACCESS_SHARED) { - _get_opp_table_kref(opp_table); + dev_pm_opp_get_opp_table_ref(opp_table); managed_table =3D opp_table; } =20 @@ -117,7 +117,7 @@ static struct opp_table *_find_table_of_opp_np(struct d= evice_node *opp_np) mutex_lock(&opp_table_lock); list_for_each_entry(opp_table, &opp_tables, node) { if (opp_table_np =3D=3D opp_table->np) { - _get_opp_table_kref(opp_table); + dev_pm_opp_get_opp_table_ref(opp_table); mutex_unlock(&opp_table_lock); return opp_table; } @@ -406,7 +406,7 @@ static void lazy_link_required_opp_table(struct opp_tab= le *new_table) } =20 required_opp_tables[i] =3D new_table; - _get_opp_table_kref(new_table); + dev_pm_opp_get_opp_table_ref(new_table); =20 /* Link OPPs now */ ret =3D lazy_link_required_opps(opp_table, new_table, i); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 5c7c81190e41..9eba63e01a9e 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -251,7 +251,6 @@ struct opp_table { =20 /* Routines internal to opp core */ bool _opp_remove_all_static(struct opp_table *opp_table); -void _get_opp_table_kref(struct opp_table *opp_table); int _get_opp_count(struct opp_table *opp_table); struct opp_table *_find_opp_table(struct device *dev); struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table= *opp_table); --=20 2.31.1.272.g89b43f80a514 From nobody Mon Feb 9 07:19:43 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 70C52235BF0 for ; Thu, 24 Apr 2025 10:37:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491031; cv=none; b=oixg/yeFEWHYp4Onfo9BlnGnf47FimOSRHDzQoZ3h+nD/xRiTeqZx/y6lWl/FpKj+dqcAkUwvOOsr0RoxYxKPRm3qeFq8hClZBi4bhCgcTatrTZyZ5xBD+HqTQA2zpyFSNYwpGirpA8R77LBjwliZ3/jdxnQfj6Ex04O9HhLjZU= 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.177 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-f177.google.com with SMTP id d9443c01a7336-22409077c06so12562695ad.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=qSafDb9vzm4Ig15W4/JxEWTR9y1Wr8ZBsWNRXxu65QfcSwlS7s12HxYxT1BAfYGiQX 76oTANXWCpxZEvv4qZZTYBjZQhU51R7GYO49EJy+04jjm5kJwV4rV3kDksInttQRWAst QTCMjvd+Z4tAXsV1aO8wT31JquRnyQnPMDcGn38XQtI9dYzoOmV0HrIcWrqqVW6WxFD+ bBA5HHytbCmCGnoVR/CVgBJ81y/aLYbZBGt3I1AOLikypiKIYHvjAeAqxFhrOIkwrMD/ e4K1ldk2J4Kjm9K7YLo2M5M9M04e5yJwvcLR9DlvCDQkOD6/h9Au6LaiP17sWcaU85QS /uKg== X-Forwarded-Encrypted: i=1; AJvYcCXQDN1+G3NxP0cLS+7a3KW7vmoHdFHOcb5AeLNKAInUpVacaFqmcu6BHLbTkBCKz//BuzldfsOX+w7rDLk=@vger.kernel.org X-Gm-Message-State: AOJu0YxlW4teiw5QG8SF2V7jaoiE0h6Qad9tbmf4NUzz1AouV+oiH/Lz 1XiNW4Ig2iaQuPXs4gsEPkuekAj/2o/WiF31FTBXn2gCtxuiVgzTipv1TdlC5a8= X-Gm-Gg: ASbGncuGzma/O1o2s/nI+jd8Tp1zFt1dNcIFDWttlSwsr8N3pZcSNaJobAlot5zPQr5 kaMSmvvj7kls6hcD5OCVeO8HAuvzi/Ks3X1PxxdN9i49yNLDIUobwcDi4GN72Fjxitym2Zmy3Kr A5iJAi9WBKFwE04WfmcagUUru4cldEDbPRwQLKNP60ieqA7Hargg0OLJokop0eVyJ/QpL7uZ4Hj CKWlDyA1AuXP+vi12+O0SfWHkD4RjUhSugC/oOzjv3ki+z2usl6IAoHldSrDTeVYBWd6039BkT6 BhB37q0O3nlqdil1ELZmiF2g1p+dzJMR5nVifNCNeA== 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For convenience of users, return back the pointer to the opp from dev_pm_opp_get(), so they can do: opp =3D 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, str= uct opp_table *opp_table) */ if (IS_ERR(opp)) { mutex_lock(&opp_table->lock); - opp =3D list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node); - dev_pm_opp_get(opp); + opp =3D dev_pm_opp_get(list_first_entry(&opp_table->opp_list, + struct dev_pm_opp, node)); mutex_unlock(&opp_table->lock); } =20 @@ -1329,8 +1329,7 @@ static int _set_opp(struct device *dev, struct opp_ta= ble *opp_table, dev_pm_opp_put(old_opp); =20 /* Make sure current_opp doesn't get freed */ - dev_pm_opp_get(opp); - opp_table->current_opp =3D opp; + opp_table->current_opp =3D dev_pm_opp_get(opp); =20 return ret; } @@ -1724,9 +1723,10 @@ static void _opp_kref_release(struct kref *kref) kfree(opp); } =20 -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); =20 @@ -2706,8 +2706,7 @@ struct dev_pm_opp *dev_pm_opp_xlate_required_opp(stru= ct opp_table *src_table, =20 list_for_each_entry(opp, &src_table->opp_list, node) { if (opp =3D=3D src_opp) { - dest_opp =3D opp->required_opps[i]; - dev_pm_opp_get(dest_opp); + dest_opp =3D 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 devic= e *dev, struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, unsigned int *bw, int index); =20 -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); =20 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_fl= oor(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } =20 -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; +} =20 static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} =20 --=20 2.31.1.272.g89b43f80a514 From nobody Mon Feb 9 07:19:43 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 58D982367D9 for ; Thu, 24 Apr 2025 10:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491035; cv=none; b=unTuuT5AnM3DraAPi+aKEZVhxegNQZXucWrbTQNtkFAuRlDc4VZd5v0lqvClLxcZL06NnhMQLw5y38liAAgKzmvU6OFPb1Ioq79nEXRZZLPMCHwJlXDKs/+3/dOgkgIIGT7ANqFsJpZDBvoa5QyAZZElyFBsiuINZrnIiI07PVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491035; c=relaxed/simple; bh=NeVKdcw8OCf4gupfY3nEEQyeD5Av5HUkByu8eDlPENE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qYltZJGbKt9TGm3CdFZDP6jSI+oHbxTS6n+ikVpuRKqeGXADDVOdQzo3avgryXfRMF7xiIoQyOCblCIOoCu9Ah8Lr7WBRfz+gqHNE8Dym0ZGV89Rlj5t2/fUsDspm6l9DMnhqCnfrOFh1hxG3ugcXe5DbG7K7BUkL/oqx5SoBuQ= 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=i03xX/0c; arc=none smtp.client-ip=209.85.210.181 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="i03xX/0c" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7399a2dc13fso1080590b3a.2 for ; Thu, 24 Apr 2025 03:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745491032; x=1746095832; 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=vscvGKi8aZQ4AtwM5RonL3qnlEsuOoWo+Mhs+nOpbME=; b=i03xX/0cbq5zQVf+tCHpDlvx9PLpM9Q1lStx+3clg+CMSTzi/fq34+L891nfwfXObW pJ1II6byoKqGQJCOdt9E7mBhoDv6ezILDu4T/aLImuo2zK0prKrVNU/6rWFqT6BLcgP3 j8kjAiqrUomXw6p+cbO1Oc3Td4hIBN7K2qB2QcoX/yqvbx4mgoY8FUm45v4FD/cuhi7j 7kSz0DdCY0rmM7NKHLswQIicCVP/HWB5vOBafo/wDWOBiec2OQBd5FuS3ZxW1zSkYLqh YX+XWHjoASa/EZl49iiFwM6OCtHthgQ8UdonZUT1xZMC48Q2X1ecsl9NY9UYeoTuY9mi aaJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745491032; x=1746095832; 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=vscvGKi8aZQ4AtwM5RonL3qnlEsuOoWo+Mhs+nOpbME=; b=SRi/hlMQb84hbfu1qqV8jaBI3Qvsc09HEcQ4GCoNqVspm7No4bFwV102JoRqFrWGgC G8WCq1AIchxwrg77O0x/XVWsZlTUZP4pMSyr6CTrQhbbjgYmoUmSWNuAMG4vGyuYIRlR MdEp1my+DolQv7IXOlRtDnw7red6rOdPW8++Y6VN4jyLEPCHuP+q0v0L62bt0TWADhTO SWApZFjlKXusQt9MrMO+yPc+uTrjzWZ2XSPeO1cVora8QPeLLFSCbScIyqDTRfkyMnfi sN9gNOvM+wW6Zlt1n16OwYBu1MNNM6oH2lpZ5pE/PHyVLT+/y5lJ7hu1jUodUL8X3Qd0 vMlQ== X-Forwarded-Encrypted: i=1; AJvYcCU1aidhZ6snjuE5m8/x8fbEi5I8nxXZ70VA2fdrDNZ2Hwb5LpbEK1wwn0ZUYx6mJyPn+U1qlZJ28R+iFts=@vger.kernel.org X-Gm-Message-State: AOJu0YyoKs261fSsxTNjVpbPW/nslh+pdbHsSwtn8R6kVye/B7L3LZja vJft1PQ8Sb631SJ2v5XqyhpYrUU15V6gAEnIAoCWYfLeVsBb86twzCWZ6WBzJlQ= X-Gm-Gg: ASbGnctJ5Rak0pAIsY8DB0mlETCeNi+b3k7daWTPAIo2jVI0ImyiPF0Ec36wYHaCfZu XarIQccVdwLDDvcjy4/MwLCmL4rCde27kMQxI83VkZSehMFw+4NPxUHvh5YWaF27uH/7Z+jw8P7 ThXLkm1KwA9/yBI+5AqVD+m49QdH/Z+CnxJlvHynRQB8W1Nw7OvWKMC7bjsWgGzeGYzG+PgW0/t bZTNnWeHQJBotgRySSvsmnjhqQIZAJd2mXz/7tAoyqkoPv4OIpKyWP7QWVCZf+mrV7aa5/IpSYA +9Kq3UR+EEMb5cUmm6bQ5uJYNO5QevFoPLEHswXw6w== X-Google-Smtp-Source: AGHT+IG2u1pypaLFiO4fsom7dy5KA1qvfxkw47AsY/FMtzeMJ0wlTMGgmr1u6k36FoY0kYO6FF+lXw== X-Received: by 2002:a05:6a00:179e:b0:73e:359:1c86 with SMTP id d2e1a72fcca58-73e247d7cb6mr2816818b3a.18.1745491032617; Thu, 24 Apr 2025 03:37:12 -0700 (PDT) Received: from localhost ([122.172.83.32]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73e259414d3sm1050286b3a.47.2025.04.24.03.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 03:37:12 -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 3/6] OPP: Return opp_table from dev_pm_opp_get_opp_table_ref() Date: Thu, 24 Apr 2025 16:06:46 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For convenience of users, return back the pointer to the opp_table from dev_pm_opp_get_opp_table_ref(), so they can do: opp_table =3D dev_pm_opp_get_opp_table_ref(tmp_table); No intentional functional impact. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 9 ++++----- drivers/opp/of.c | 9 +++------ include/linux/pm_opp.h | 7 +++++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 150439a18b87..14fb0f43cc77 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -58,10 +58,8 @@ static struct opp_table *_find_opp_table_unlocked(struct= device *dev) struct opp_table *opp_table; =20 list_for_each_entry(opp_table, &opp_tables, node) { - if (_find_opp_dev(dev, opp_table)) { - dev_pm_opp_get_opp_table_ref(opp_table); - return opp_table; - } + if (_find_opp_dev(dev, opp_table)) + return dev_pm_opp_get_opp_table_ref(opp_table); } =20 return ERR_PTR(-ENODEV); @@ -1687,9 +1685,10 @@ static void _opp_table_kref_release(struct kref *kre= f) kfree(opp_table); } =20 -void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) +struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) { kref_get(&opp_table->kref); + return opp_table; } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table_ref); =20 diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 87cb6aeb49ed..c240acc81a8d 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -60,10 +60,8 @@ struct opp_table *_managed_opp(struct device *dev, int i= ndex) * But the OPPs will be considered as shared only if the * OPP table contains a "opp-shared" property. */ - if (opp_table->shared_opp =3D=3D OPP_TABLE_ACCESS_SHARED) { - dev_pm_opp_get_opp_table_ref(opp_table); - managed_table =3D opp_table; - } + if (opp_table->shared_opp =3D=3D OPP_TABLE_ACCESS_SHARED) + managed_table =3D dev_pm_opp_get_opp_table_ref(opp_table); =20 break; } @@ -405,8 +403,7 @@ static void lazy_link_required_opp_table(struct opp_tab= le *new_table) continue; } =20 - required_opp_tables[i] =3D new_table; - dev_pm_opp_get_opp_table_ref(new_table); + required_opp_tables[i] =3D dev_pm_opp_get_opp_table_ref(new_table); =20 /* Link OPPs now */ ret =3D lazy_link_required_opps(opp_table, new_table, i); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 5e4c3428b139..0deddfa91aca 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -100,7 +100,7 @@ struct dev_pm_opp_data { #if defined(CONFIG_PM_OPP) =20 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); -void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table); +struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table= ); void dev_pm_opp_put_opp_table(struct opp_table *opp_table); =20 unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int ind= ex); @@ -207,7 +207,10 @@ static inline struct opp_table *dev_pm_opp_get_opp_tab= le_indexed(struct device * return ERR_PTR(-EOPNOTSUPP); } =20 -static inline void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_tabl= e) {} +static inline struct opp_table *dev_pm_opp_get_opp_table_ref(struct opp_ta= ble *opp_table) +{ + return opp_table; +} =20 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} =20 --=20 2.31.1.272.g89b43f80a514 From nobody Mon Feb 9 07:19:43 2026 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 EF0A0238C04 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=1745491038; cv=none; b=Eo4p5THSARrU0Q88S1tXdkdNb4UmXP7S4KfR4oV3I0s2nB3p1AgffqVQV6DZWigySeG981fe8TXOGOMyQIts1dq55ygD6eOvYTyXxAoBoUOKMvtFGIuK2euamUkJHfL7tfz1WYYQCHlrcFi7Gq49UTArZ1IHVFmvhV+4jK9nMzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491038; c=relaxed/simple; bh=VOa1T0aKJkkd4ubCM8nPBYNfRfmMW9NmHBOvyIP9zM8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DQPV7UmEORBRhoaNTAKLJs8kddh4ZDDNALJRDsL1Bh3AxTRKs7T4L4L157QYfQnkwYXSgh3qp2DrdBhvFf68ypLIg0bM8SXnlSmrAwVcdtY059lVkGZ9dUzq7zVXZBr4yH4FhEyuiVnh/zc6rdLUiQDzPHEdDfefOqZTLQoG//s= 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-2260c91576aso6461475ad.3 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=A2MGFYd0yjL1AhHqmahqWB3P5+fn1wjgVNOliy/4liQLRlXbyNETaMQBimSEm8dZlu wlxjcCBEjcjCvQv+Rjz+yh7d2dvz3i9TOvo2J7ZDJfZ9Cwfb/yeRPiaiWcRcANJ/KVky xq9q0B2lQDiNBgNXBQUvq7s7XtjvLdBtd9db84gm3RK0N5xGmzD3kdSUQ3P1zjFi/3Sd X7wdCslxMHh6z224dhp2Vf5GOtbMRiFUtLkE/EaKpXGR2jdeW8WpNC/76APcczxp3Qmj rLmtqZ0ilN07w/Mj/5As1YfVrE5+X4bbX3QOTNYxzn+VBOWHW+h9A5sUtpA7JXevOdQE 6xaw== X-Forwarded-Encrypted: i=1; AJvYcCUuvV2m4vIAxt2BYamb3dh3YPApCYIy0T1/244bRddnNpQvlsHYhRDoxK3aLmMZrar1HPp6bQeX/lVQszE=@vger.kernel.org X-Gm-Message-State: AOJu0YzzfFMuviqSKkFxPWc8ngVi0fl4cBe1TO/6XWIbPcMf2P/bnppd yI8nOlw6LK/TbY+l1CUIMu4AuIoU6MnByrj6cZm9Q/Bb+jH+IWdUUzAUSyiExDc= X-Gm-Gg: ASbGnct/WIRthyQ4nk+7/lcFTgWuDOFfmYzVNsd5w8zPcRyOaiLiIG7auooOrkZwYHw ZpFEMYbv7BxxOmJdRAwgxWlurjb+VV6IQBpQbMr/sAox8u7H4cFTNxMdgJGOp1iJAmRD5MZN8ka UdAB6FcL+HkrWqs0rMbQ3z6TMzwAuHMHDmN/8biBcVBfnvZMF8wkbcA5EeqFczzNUb65UM/ZTBQ PBuk1PRkYxZABwVNIIHf6jk2uX5r/VWIK/5rWkcuIrMuInOZZ5k86QgUxEFe/sMK6rNSeCoNKTH 7S7hqEPinQn23JPpw8w32v/6h5MbVy40ThmJwijkPphRHJQio0NS 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D NULL; - struct device_node *np; + struct device_node *np __free(device_node); =20 np =3D _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 in= dex) } } =20 - of_node_put(np); - return managed_table; } =20 @@ -102,16 +100,13 @@ static struct device_node *of_parse_required_opp(stru= ct 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; =20 opp_table_np =3D of_get_parent(opp_np); if (!opp_table_np) goto err; =20 - /* 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 =3D=3D 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 =3D false; int count, i, size; =20 @@ -169,30 +164,32 @@ static void _opp_table_alloc_required_tables(struct o= pp_table *opp_table, np =3D of_get_next_available_child(opp_np, NULL); if (!np) { dev_warn(dev, "Empty OPP table\n"); - return; } =20 count =3D of_count_phandle_with_args(np, "required-opps", NULL); if (count <=3D 0) - goto put_np; + return; =20 size =3D sizeof(*required_opp_tables) + sizeof(*opp_table->required_devs); required_opp_tables =3D kcalloc(count, size, GFP_KERNEL); if (!required_opp_tables) - goto put_np; + return; =20 opp_table->required_opp_tables =3D required_opp_tables; opp_table->required_devs =3D (void *)(required_opp_tables + count); opp_table->required_opp_count =3D count; =20 for (i =3D 0; i < count; i++) { + struct device_node *required_np __free(device_node); + required_np =3D of_parse_required_opp(np, i); - if (!required_np) - goto free_required_tables; + if (!required_np) { + _opp_table_free_required_tables(opp_table); + return; + } =20 required_opp_tables[i] =3D _find_table_of_opp_np(required_np); - of_node_put(required_np); =20 if (IS_ERR(required_opp_tables[i])) lazy =3D true; @@ -208,19 +205,12 @@ static void _opp_table_alloc_required_tables(struct o= pp_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); } =20 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; =20 /* @@ -241,8 +231,6 @@ void _of_init_opp_table(struct opp_table *opp_table, st= ruct device *dev, =20 /* Get OPP table node */ opp_np =3D _opp_of_get_opp_desc_node(np, index); - of_node_put(np); - if (!opp_np) return; =20 @@ -296,15 +284,13 @@ void _of_clear_opp(struct opp_table *opp_table, struc= t 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); =20 np =3D of_parse_required_opp(opp->np, index); if (unlikely(!np)) return -ENODEV; =20 opp->required_opps[index] =3D _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; =20 mutex_lock(&opp_table_lock); =20 list_for_each_entry_safe(opp_table, temp, &lazy_opp_tables, lazy) { + struct device_node *opp_np __free(device_node); bool lazy =3D false; =20 /* opp_np can't be invalid here */ opp_np =3D of_get_next_available_child(opp_table->np, NULL); =20 for (i =3D 0; i < opp_table->required_opp_count; i++) { + struct device_node *required_np __free(device_node) =3D NULL; + struct device_node *required_table_np __free(device_node) =3D NULL; + required_opp_tables =3D opp_table->required_opp_tables; =20 /* Required opp-table is already parsed */ @@ -391,9 +380,6 @@ static void lazy_link_required_opp_table(struct opp_tab= le *new_table) required_np =3D of_parse_required_opp(opp_np, i); required_table_np =3D of_get_parent(required_np); =20 - 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_tab= le *new_table) } } =20 - 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_t= able *new_table) =20 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) =3D NULL; + struct device_node *np __free(device_node) =3D NULL; struct property *prop; =20 if (!opp_table) { + struct device_node *np __free(device_node); + np =3D of_node_get(dev->of_node); if (!np) return -ENODEV; =20 opp_np =3D _opp_of_get_opp_desc_node(np, 0); - of_node_put(np); } else { opp_np =3D of_node_get(opp_table->np); } @@ -450,15 +436,12 @@ static int _bandwidth_supported(struct device *dev, s= truct opp_table *opp_table) =20 /* Checking only first OPP is sufficient */ np =3D of_get_next_available_child(opp_np, NULL); - of_node_put(opp_np); if (!np) { dev_err(dev, "OPP table empty\n"); return -EINVAL; } =20 prop =3D of_find_property(np, "opp-peak-kBps", NULL); - of_node_put(np); - if (!prop || !prop->length) return 0; =20 @@ -468,7 +451,7 @@ static int _bandwidth_supported(struct device *dev, str= uct 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) =3D of_node_get(dev->of_node); int ret, i, count, num_paths; struct icc_path **paths; =20 @@ -478,15 +461,13 @@ int dev_pm_opp_of_find_icc_paths(struct device *dev, else if (ret <=3D 0) return ret; =20 - ret =3D 0; - - np =3D of_node_get(dev->of_node); if (!np) return 0; =20 + ret =3D 0; + count =3D of_count_phandle_with_args(np, "interconnects", "#interconnect-cells"); - of_node_put(np); if (count < 0) return 0; =20 @@ -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 =3D 0; + struct device_node *np __free(device_node); + int cpu; =20 /* Get OPP descriptor node */ np =3D dev_pm_opp_of_get_opp_desc_node(cpu_dev); @@ -1317,9 +1298,12 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cp= u_dev, =20 /* OPPs are shared ? */ if (!of_property_read_bool(np, "opp-shared")) - goto put_cpu_node; + return 0; =20 for_each_possible_cpu(cpu) { + struct device_node *cpu_np __free(device_node) =3D NULL; + struct device_node *tmp_np __free(device_node) =3D NULL; + if (cpu =3D=3D cpu_dev->id) continue; =20 @@ -1327,29 +1311,22 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *c= pu_dev, if (!cpu_np) { dev_err(cpu_dev, "%s: failed to get cpu%d node\n", __func__, cpu); - ret =3D -ENOENT; - goto put_cpu_node; + return -ENOENT; } =20 /* Get OPP descriptor node */ tmp_np =3D _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 =3D -ENOENT; - goto put_cpu_node; + return -ENOENT; } =20 /* CPUs are sharing opp node */ if (np =3D=3D tmp_np) cpumask_set_cpu(cpu, cpumask); - - of_node_put(tmp_np); } =20 -put_cpu_node: - of_node_put(np); - return ret; + return 0; } EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus); =20 @@ -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 inde= x) { - 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 =3D -EINVAL; =20 required_np =3D of_parse_required_opp(np, index); @@ -1379,13 +1356,13 @@ int of_get_required_opp_performance_state(struct de= vice_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); } =20 /* 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; } =20 opp =3D _find_opp_of_np(opp_table, required_np); @@ -1401,10 +1378,6 @@ int of_get_required_opp_performance_state(struct dev= ice_node *np, int index) } =20 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_sta= te); */ bool dev_pm_opp_of_has_required_opp(struct device *dev) { - struct device_node *opp_np, *np; + struct device_node *np __free(device_node) =3D NULL, *opp_np __free(devic= e_node); int count; =20 opp_np =3D _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; =20 np =3D of_get_next_available_child(opp_np, NULL); - of_node_put(opp_np); if (!np) { dev_warn(dev, "Empty OPP table\n"); return false; } =20 count =3D of_count_phandle_with_args(np, "required-opps", NULL); - of_node_put(np); =20 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, unsigne= d long *uW, return -EINVAL; =20 ret =3D of_property_read_u32(np, "dynamic-power-coefficient", &cap); - of_node_put(np); if (ret) return -EINVAL; =20 @@ -1581,8 +1551,8 @@ static bool _of_has_opp_microwatt_property(struct dev= ice *dev) */ int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus) { + struct device_node *np __free(device_node) =3D NULL; struct em_data_callback em_cb; - struct device_node *np; int ret, nr_opp; u32 cap; =20 @@ -1617,7 +1587,6 @@ int dev_pm_opp_of_register_em(struct device *dev, str= uct cpumask *cpus) * user about the inconsistent configuration. */ ret =3D 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 =3D -EINVAL; --=20 2.31.1.272.g89b43f80a514 From nobody Mon Feb 9 07:19:43 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 3A1A523C390 for ; Thu, 24 Apr 2025 10:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491043; cv=none; b=Qjmg9+hyAyK56AKGBxuEzzH2KKnS/R4sueJ9P4w7N+tzYZkeDDidIRf7nyFmbqf59vSu75jXchOmfET9pdKkL6zERKQU3vWspI1dq2ucVovgFOySE1YIj+3BAZp3/wrsJwgEyiHMKw/E8uPw7HrMhN5wK8IqwZ6ihSBJ1utrBIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745491043; c=relaxed/simple; bh=UIhihO+KSlk84fI+BFSWcB1XVu68h01gI8MX+i/A85Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gHJsVvnrYPKzgFZzXFZqQHFzyXDDdy7SetcdmPe2Tyz+ti5u++AzEoTdJubbfR9VJGCLSSVFc7cVaaKnFZsG0CyYVPIsMr4qQLBgcIc54D3kyNxQkHObFeLtrqoNtRfPN7NqH/3N9tWUb3ieHICD3vm8YY2kKnp+AmJtM8zC0GY= 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=hwZy63hQ; arc=none smtp.client-ip=209.85.214.179 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="hwZy63hQ" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-22c3407a87aso13199655ad.3 for ; Thu, 24 Apr 2025 03:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745491040; x=1746095840; 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=lWVroK7uqi5IEJnUfPHoEkoDsKi7RyYwEa+CnjAgxus=; b=hwZy63hQZwUT9lz37EC6GjOLUpya01qRTYkk46zXD06Q3Q50kZ8WGvO6BqmWOPM1Qx UA7kTXW2Rc/T0Isny2VbZFVh3mob2oR5jdLgoNkd2PyxtFCYV4ReSImVFpeM5nEOR7YK qOjw2+5N86grqWJvjeNUlPvrTbVnslZmqagy4EFp7N1HE8wDwBAQs6SeJRcqQn6LItSj X0WGcLs511d/8dKtgX4NmbWbRHcC4wlpIVx63iyKyBYBPCPxOLCxgH/RRgT8ubD0jm9f RmohfKPbv67N33IsuREynPz5JxYFQi77snXJgsr3d1XXum7vCNJ1MkTsj5Bv9HAqE4Uf gqKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745491040; x=1746095840; 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=lWVroK7uqi5IEJnUfPHoEkoDsKi7RyYwEa+CnjAgxus=; b=Cn7a3pwdfhDFXQu4N7nBR/iO1U+3Uxx86l66BYmu+kVeVJlkzykspNoZ8XVORV0lzb Q2aJKlTGLwjA9xJy1bUE34zZ4P6BmDSTIDInCI1rd4TgA5MZDMa4BGYZcOWie5HJJt88 n+m8HpIeNW4n1zxm4EKEj39H6iM1jsBaq4zQ5eNMIm4HNTUFj+jNNpgVtMDskMYuMf2o O4yW2XVEw6gbRYJK62CZZFETpjBPDH20i2aC2r7qM+zVCkEo45k0hUx/UIfzWVg3ymmY T1NeDusJ26e4nL079VPFH82nghdJBr68sSj1GUGVWGj097wHcCsOtoBByvlPI0RWIvpq 6gWg== X-Forwarded-Encrypted: i=1; AJvYcCVR2RLBBweuSP0AEuWKlW+h+zgl9mB/AH208zqBCO4fMOt0M6LNIHpcQZ0knBiSHlRiG3ZxzW74Bc/uHRs=@vger.kernel.org X-Gm-Message-State: AOJu0Yyf/ZT0gcbRauGSAsCYNwslG4dvGdbX/MZ9RaCGzTZCyS2kqkx2 tH0wzl3uZsxL2u5R7KjP+GKMzTojRba8/xRDRnKF16QNpE5Wqg3b4F6Z1C0/PmE= X-Gm-Gg: ASbGncsK/+tfv8uUT99KmDj7d9IMO9A0xwifHhZyUZCNLWRjxB37ZQaWJgUEct9eAFG cxB8wTANbWvlK0GgUKOUqiMSLSJXCeTAPdVnVgjEJaQmry32WC5KpjBC6E64yLbqbokVa/KBBE2 vGj/H5kOFH6785PZ/cYdGDqLDq1uYUuSXmK+Vhp2/9GnG5NokVhsEWyShpJrWkdujAt2t9Rhvrr JtHlT4XrUPF7GWUqVVq2MxMlJu6Oyx6heWaZUZfnwhSKXlvKAo7XRd2IGZD+jnRqrGpJgB9cgTc ti1SuUX2bRMt0tpq8hZM1fbw4hMZFjeBoqw66VoXsg== X-Google-Smtp-Source: AGHT+IFtkyIv19VH4ZqdUc9coJM/UdcvKr/acvdXxMY9KrQZhZFnapOrBvqfiYotRgy3+oauDgRFTA== X-Received: by 2002:a17:903:24a:b0:223:668d:eba9 with SMTP id d9443c01a7336-22db3bb6f7dmr33678345ad.10.1745491040511; Thu, 24 Apr 2025 03:37:20 -0700 (PDT) Received: from localhost ([122.172.83.32]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b15f76f582csm908421a12.4.2025.04.24.03.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 03:37:20 -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 5/6] OPP: Define and use scope-based cleanup helpers Date: Thu, 24 Apr 2025 16:06:48 +0530 Message-Id: <5330d0dab7367f7e17911dfa82a6712de27aa968.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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define and use scope-based cleanup helpers for `struct opp` and `struct opp_table`. No intentional functional impact. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 236 ++++++++++++++--------------------------- drivers/opp/cpu.c | 27 ++--- drivers/opp/of.c | 24 ++--- include/linux/pm_opp.h | 7 ++ 4 files changed, 102 insertions(+), 192 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 14fb0f43cc77..87d27132cd87 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -317,18 +317,13 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_is_turbo); */ unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) { - struct opp_table *opp_table; - unsigned long clock_latency_ns; + struct opp_table *opp_table __free(put_opp_table); =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) return 0; =20 - clock_latency_ns =3D opp_table->clock_latency_ns_max; - - dev_pm_opp_put_opp_table(opp_table); - - return clock_latency_ns; + return opp_table->clock_latency_ns_max; } EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_clock_latency); =20 @@ -340,7 +335,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_clock_latency); */ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) { - struct opp_table *opp_table; + struct opp_table *opp_table __free(put_opp_table); struct dev_pm_opp *opp; struct regulator *reg; unsigned long latency_ns =3D 0; @@ -356,13 +351,13 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct = device *dev) =20 /* Regulator may not be required for the device */ if (!opp_table->regulators) - goto put_opp_table; + return 0; =20 count =3D opp_table->regulator_count; =20 uV =3D kmalloc_array(count, sizeof(*uV), GFP_KERNEL); if (!uV) - goto put_opp_table; + return 0; =20 mutex_lock(&opp_table->lock); =20 @@ -395,8 +390,6 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct de= vice *dev) } =20 kfree(uV); -put_opp_table: - dev_pm_opp_put_opp_table(opp_table); =20 return latency_ns; } @@ -426,7 +419,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_transition_latency= ); */ unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) { - struct opp_table *opp_table; + struct opp_table *opp_table __free(put_opp_table); unsigned long freq =3D 0; =20 opp_table =3D _find_opp_table(dev); @@ -436,8 +429,6 @@ unsigned long dev_pm_opp_get_suspend_opp_freq(struct de= vice *dev) if (opp_table->suspend_opp && opp_table->suspend_opp->available) freq =3D dev_pm_opp_get_freq(opp_table->suspend_opp); =20 - dev_pm_opp_put_opp_table(opp_table); - return freq; } EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_freq); @@ -468,21 +459,16 @@ int _get_opp_count(struct opp_table *opp_table) */ int dev_pm_opp_get_opp_count(struct device *dev) { - struct opp_table *opp_table; - int count; + struct opp_table *opp_table __free(put_opp_table); =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) { - count =3D PTR_ERR(opp_table); - dev_dbg(dev, "%s: OPP table not found (%d)\n", - __func__, count); - return count; + dev_dbg(dev, "%s: OPP table not found (%ld)\n", + __func__, PTR_ERR(opp_table)); + return PTR_ERR(opp_table); } =20 - count =3D _get_opp_count(opp_table); - dev_pm_opp_put_opp_table(opp_table); - - return count; + return _get_opp_count(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); =20 @@ -576,8 +562,7 @@ _find_key(struct device *dev, unsigned long *key, int i= ndex, bool available, unsigned long opp_key, unsigned long key), bool (*assert)(struct opp_table *opp_table, unsigned int index)) { - struct opp_table *opp_table; - struct dev_pm_opp *opp; + struct opp_table *opp_table __free(put_opp_table); =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) { @@ -586,12 +571,8 @@ _find_key(struct device *dev, unsigned long *key, int = index, bool available, return ERR_CAST(opp_table); } =20 - opp =3D _opp_table_find_key(opp_table, key, index, available, read, - compare, assert); - - dev_pm_opp_put_opp_table(opp_table); - - return opp; + return _opp_table_find_key(opp_table, key, index, available, read, + compare, assert); } =20 static struct dev_pm_opp *_find_key_exact(struct device *dev, @@ -1345,11 +1326,10 @@ static int _set_opp(struct device *dev, struct opp_= table *opp_table, */ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { - struct opp_table *opp_table; + struct opp_table *opp_table __free(put_opp_table); + struct dev_pm_opp *opp __free(put_opp) =3D NULL; unsigned long freq =3D 0, temp_freq; - struct dev_pm_opp *opp =3D NULL; bool forced =3D false; - int ret; =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) { @@ -1366,9 +1346,8 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned = long target_freq) * equivalent to a clk_set_rate() */ if (!_get_opp_count(opp_table)) { - ret =3D opp_table->config_clks(dev, opp_table, NULL, - &target_freq, false); - goto put_opp_table; + return opp_table->config_clks(dev, opp_table, NULL, + &target_freq, false); } =20 freq =3D clk_round_rate(opp_table->clk, target_freq); @@ -1383,10 +1362,9 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned= long target_freq) temp_freq =3D freq; opp =3D _find_freq_ceil(opp_table, &temp_freq); if (IS_ERR(opp)) { - ret =3D PTR_ERR(opp); - dev_err(dev, "%s: failed to find OPP for freq %lu (%d)\n", - __func__, freq, ret); - goto put_opp_table; + dev_err(dev, "%s: failed to find OPP for freq %lu (%ld)\n", + __func__, freq, PTR_ERR(opp)); + return PTR_ERR(opp); } =20 /* @@ -1399,14 +1377,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned= long target_freq) forced =3D opp_table->current_rate_single_clk !=3D freq; } =20 - ret =3D _set_opp(dev, opp_table, opp, &freq, forced); - - if (freq) - dev_pm_opp_put(opp); - -put_opp_table: - dev_pm_opp_put_opp_table(opp_table); - return ret; + return _set_opp(dev, opp_table, opp, &freq, forced); } EXPORT_SYMBOL_GPL(dev_pm_opp_set_rate); =20 @@ -1422,8 +1393,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_set_rate); */ int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp) { - struct opp_table *opp_table; - int ret; + struct opp_table *opp_table __free(put_opp_table); =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) { @@ -1431,10 +1401,7 @@ int dev_pm_opp_set_opp(struct device *dev, struct de= v_pm_opp *opp) return PTR_ERR(opp_table); } =20 - ret =3D _set_opp(dev, opp_table, opp, NULL, false); - dev_pm_opp_put_opp_table(opp_table); - - return ret; + return _set_opp(dev, opp_table, opp, NULL, false); } EXPORT_SYMBOL_GPL(dev_pm_opp_set_opp); =20 @@ -1744,15 +1711,15 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put); */ void dev_pm_opp_remove(struct device *dev, unsigned long freq) { + struct opp_table *opp_table __free(put_opp_table); struct dev_pm_opp *opp =3D NULL, *iter; - struct opp_table *opp_table; =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) return; =20 if (!assert_single_clk(opp_table, 0)) - goto put_table; + return; =20 mutex_lock(&opp_table->lock); =20 @@ -1774,10 +1741,6 @@ void dev_pm_opp_remove(struct device *dev, unsigned = long freq) dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n", __func__, freq); } - -put_table: - /* Drop the reference taken by _find_opp_table() */ - dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove); =20 @@ -1849,16 +1812,13 @@ bool _opp_remove_all_static(struct opp_table *opp_t= able) */ void dev_pm_opp_remove_all_dynamic(struct device *dev) { - struct opp_table *opp_table; + struct opp_table *opp_table __free(put_opp_table); =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) return; =20 _opp_remove_all(opp_table, true); - - /* Drop the reference taken by _find_opp_table() */ - dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove_all_dynamic); =20 @@ -2846,47 +2806,43 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_add_dynamic); static int _opp_set_availability(struct device *dev, unsigned long freq, bool availability_req) { - struct opp_table *opp_table; - struct dev_pm_opp *tmp_opp, *opp =3D ERR_PTR(-ENODEV); - int r =3D 0; + struct dev_pm_opp *opp __free(put_opp) =3D ERR_PTR(-ENODEV), *tmp_opp; + struct opp_table *opp_table __free(put_opp_table); =20 /* Find the opp_table */ opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) { - r =3D PTR_ERR(opp_table); - dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r); - return r; + dev_warn(dev, "%s: Device OPP not found (%ld)\n", __func__, + PTR_ERR(opp_table)); + return PTR_ERR(opp_table); } =20 - if (!assert_single_clk(opp_table, 0)) { - r =3D -EINVAL; - goto put_table; - } + if (!assert_single_clk(opp_table, 0)) + return -EINVAL; =20 mutex_lock(&opp_table->lock); =20 /* Do we have the frequency? */ list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { if (tmp_opp->rates[0] =3D=3D freq) { - opp =3D tmp_opp; + opp =3D dev_pm_opp_get(tmp_opp); + + /* Is update really needed? */ + if (opp->available =3D=3D availability_req) { + mutex_unlock(&opp_table->lock); + return 0; + } + + opp->available =3D availability_req; break; } } =20 - if (IS_ERR(opp)) { - r =3D PTR_ERR(opp); - goto unlock; - } - - /* Is update really needed? */ - if (opp->available =3D=3D availability_req) - goto unlock; - - opp->available =3D availability_req; - - dev_pm_opp_get(opp); mutex_unlock(&opp_table->lock); =20 + if (IS_ERR(opp)) + return PTR_ERR(opp); + /* Notify the change of the OPP availability */ if (availability_req) blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ENABLE, @@ -2895,14 +2851,7 @@ static int _opp_set_availability(struct device *dev,= unsigned long freq, blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_DISABLE, opp); =20 - dev_pm_opp_put(opp); - goto put_table; - -unlock: - mutex_unlock(&opp_table->lock); -put_table: - dev_pm_opp_put_opp_table(opp_table); - return r; + return 0; } =20 /** @@ -2922,9 +2871,9 @@ int dev_pm_opp_adjust_voltage(struct device *dev, uns= igned long freq, unsigned long u_volt_max) =20 { - struct opp_table *opp_table; - struct dev_pm_opp *tmp_opp, *opp =3D ERR_PTR(-ENODEV); - int r =3D 0; + struct dev_pm_opp *opp __free(put_opp) =3D ERR_PTR(-ENODEV), *tmp_opp; + struct opp_table *opp_table __free(put_opp_table); + int r; =20 /* Find the opp_table */ opp_table =3D _find_opp_table(dev); @@ -2934,49 +2883,40 @@ int dev_pm_opp_adjust_voltage(struct device *dev, u= nsigned long freq, return r; } =20 - if (!assert_single_clk(opp_table, 0)) { - r =3D -EINVAL; - goto put_table; - } + if (!assert_single_clk(opp_table, 0)) + return -EINVAL; =20 mutex_lock(&opp_table->lock); =20 /* Do we have the frequency? */ list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { if (tmp_opp->rates[0] =3D=3D freq) { - opp =3D tmp_opp; - break; - } - } + opp =3D dev_pm_opp_get(tmp_opp); =20 - if (IS_ERR(opp)) { - r =3D PTR_ERR(opp); - goto adjust_unlock; - } + /* Is update really needed? */ + if (opp->supplies->u_volt =3D=3D u_volt) { + mutex_unlock(&opp_table->lock); + return 0; + } =20 - /* Is update really needed? */ - if (opp->supplies->u_volt =3D=3D u_volt) - goto adjust_unlock; + opp->supplies->u_volt =3D u_volt; + opp->supplies->u_volt_min =3D u_volt_min; + opp->supplies->u_volt_max =3D u_volt_max; =20 - opp->supplies->u_volt =3D u_volt; - opp->supplies->u_volt_min =3D u_volt_min; - opp->supplies->u_volt_max =3D u_volt_max; + break; + } + } =20 - dev_pm_opp_get(opp); mutex_unlock(&opp_table->lock); =20 + if (IS_ERR(opp)) + return PTR_ERR(opp); + /* Notify the voltage change of the OPP */ blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADJUST_VOLTAGE, opp); =20 - dev_pm_opp_put(opp); - goto put_table; - -adjust_unlock: - mutex_unlock(&opp_table->lock); -put_table: - dev_pm_opp_put_opp_table(opp_table); - return r; + return 0; } EXPORT_SYMBOL_GPL(dev_pm_opp_adjust_voltage); =20 @@ -2990,9 +2930,9 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_adjust_voltage); */ int dev_pm_opp_sync_regulators(struct device *dev) { - struct opp_table *opp_table; + struct opp_table *opp_table __free(put_opp_table); struct regulator *reg; - int i, ret =3D 0; + int i; =20 /* Device may not have OPP table */ opp_table =3D _find_opp_table(dev); @@ -3001,23 +2941,18 @@ int dev_pm_opp_sync_regulators(struct device *dev) =20 /* Regulator may not be required for the device */ if (unlikely(!opp_table->regulators)) - goto put_table; + return 0; =20 /* Nothing to sync if voltage wasn't changed */ if (!opp_table->enabled) - goto put_table; + return 0; =20 for (i =3D 0; i < opp_table->regulator_count; i++) { reg =3D opp_table->regulators[i]; - ret =3D regulator_sync_voltage(reg); - if (ret) - break; + return regulator_sync_voltage(reg); } -put_table: - /* Drop reference taken by _find_opp_table() */ - dev_pm_opp_put_opp_table(opp_table); =20 - return ret; + return 0; } EXPORT_SYMBOL_GPL(dev_pm_opp_sync_regulators); =20 @@ -3069,18 +3004,13 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_disable); */ int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block= *nb) { - struct opp_table *opp_table; - int ret; + struct opp_table *opp_table __free(put_opp_table); =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) return PTR_ERR(opp_table); =20 - ret =3D blocking_notifier_chain_register(&opp_table->head, nb); - - dev_pm_opp_put_opp_table(opp_table); - - return ret; + return blocking_notifier_chain_register(&opp_table->head, nb); } EXPORT_SYMBOL(dev_pm_opp_register_notifier); =20 @@ -3094,18 +3024,13 @@ EXPORT_SYMBOL(dev_pm_opp_register_notifier); int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb) { - struct opp_table *opp_table; - int ret; + struct opp_table *opp_table __free(put_opp_table); =20 opp_table =3D _find_opp_table(dev); if (IS_ERR(opp_table)) return PTR_ERR(opp_table); =20 - ret =3D blocking_notifier_chain_unregister(&opp_table->head, nb); - - dev_pm_opp_put_opp_table(opp_table); - - return ret; + return blocking_notifier_chain_unregister(&opp_table->head, nb); } EXPORT_SYMBOL(dev_pm_opp_unregister_notifier); =20 @@ -3118,7 +3043,7 @@ EXPORT_SYMBOL(dev_pm_opp_unregister_notifier); */ void dev_pm_opp_remove_table(struct device *dev) { - struct opp_table *opp_table; + struct opp_table *opp_table __free(put_opp_table); =20 /* Check for existing table for 'dev' */ opp_table =3D _find_opp_table(dev); @@ -3139,8 +3064,5 @@ void dev_pm_opp_remove_table(struct device *dev) **/ if (_opp_remove_all_static(opp_table)) dev_pm_opp_put_opp_table(opp_table); - - /* Drop reference taken by _find_opp_table() */ - dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table); diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 12c429b407ca..330a1753fb22 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -43,7 +43,6 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev, struct cpufreq_frequency_table **opp_table) { - struct dev_pm_opp *opp; struct cpufreq_frequency_table *freq_table =3D NULL; int i, max_opps, ret =3D 0; unsigned long rate; @@ -57,6 +56,8 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev, return -ENOMEM; =20 for (i =3D 0, rate =3D 0; i < max_opps; i++, rate++) { + struct dev_pm_opp *opp __free(put_opp); + /* find next rate */ opp =3D dev_pm_opp_find_freq_ceil(dev, &rate); if (IS_ERR(opp)) { @@ -69,8 +70,6 @@ int dev_pm_opp_init_cpufreq_table(struct device *dev, /* Is Boost/turbo opp ? */ if (dev_pm_opp_is_turbo(opp)) freq_table[i].flags =3D CPUFREQ_BOOST_FREQ; - - dev_pm_opp_put(opp); } =20 freq_table[i].driver_data =3D i; @@ -155,10 +154,10 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table); int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask) { + struct opp_table *opp_table __free(put_opp_table); struct opp_device *opp_dev; - struct opp_table *opp_table; struct device *dev; - int cpu, ret =3D 0; + int cpu; =20 opp_table =3D _find_opp_table(cpu_dev); if (IS_ERR(opp_table)) @@ -186,9 +185,7 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, opp_table->shared_opp =3D OPP_TABLE_ACCESS_SHARED; } =20 - dev_pm_opp_put_opp_table(opp_table); - - return ret; + return 0; } EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus); =20 @@ -204,18 +201,15 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus); */ int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cp= umask) { + struct opp_table *opp_table __free(put_opp_table); struct opp_device *opp_dev; - struct opp_table *opp_table; - int ret =3D 0; =20 opp_table =3D _find_opp_table(cpu_dev); if (IS_ERR(opp_table)) return PTR_ERR(opp_table); =20 - if (opp_table->shared_opp =3D=3D OPP_TABLE_ACCESS_UNKNOWN) { - ret =3D -EINVAL; - goto put_opp_table; - } + if (opp_table->shared_opp =3D=3D OPP_TABLE_ACCESS_UNKNOWN) + return -EINVAL; =20 cpumask_clear(cpumask); =20 @@ -228,9 +222,6 @@ int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev,= struct cpumask *cpumask) cpumask_set_cpu(cpu_dev->id, cpumask); } =20 -put_opp_table: - dev_pm_opp_put_opp_table(opp_table); - - return ret; + return 0; } EXPORT_SYMBOL_GPL(dev_pm_opp_get_sharing_cpus); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index aa43fbfa3e50..54109e813d4f 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -1344,8 +1344,8 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus); int of_get_required_opp_performance_state(struct device_node *np, int inde= x) { struct device_node *required_np __free(device_node); - struct opp_table *opp_table; - struct dev_pm_opp *opp; + struct opp_table *opp_table __free(put_opp_table) =3D NULL; + struct dev_pm_opp *opp __free(put_opp) =3D NULL; int pstate =3D -EINVAL; =20 required_np =3D of_parse_required_opp(np, index); @@ -1373,11 +1373,8 @@ int of_get_required_opp_performance_state(struct dev= ice_node *np, int index) } else { pstate =3D opp->level; } - dev_pm_opp_put(opp); - } =20 - dev_pm_opp_put_opp_table(opp_table); return pstate; } EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state); @@ -1443,7 +1440,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node); static int __maybe_unused _get_dt_power(struct device *dev, unsigned long *uW, unsigned long *kHz) { - struct dev_pm_opp *opp; + struct dev_pm_opp *opp __free(put_opp); unsigned long opp_freq, opp_power; =20 /* Find the right frequency and related OPP */ @@ -1453,7 +1450,6 @@ _get_dt_power(struct device *dev, unsigned long *uW, = unsigned long *kHz) return -EINVAL; =20 opp_power =3D dev_pm_opp_get_power(opp); - dev_pm_opp_put(opp); if (!opp_power) return -EINVAL; =20 @@ -1484,8 +1480,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 dev_pm_opp *opp __free(put_opp) =3D NULL; struct device_node *np __free(device_node); - struct dev_pm_opp *opp; unsigned long mV, Hz; u32 cap; u64 tmp; @@ -1505,7 +1501,6 @@ int dev_pm_opp_calc_power(struct device *dev, unsigne= d long *uW, return -EINVAL; =20 mV =3D dev_pm_opp_get_voltage(opp) / 1000; - dev_pm_opp_put(opp); if (!mV) return -EINVAL; =20 @@ -1522,20 +1517,15 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_calc_power); =20 static bool _of_has_opp_microwatt_property(struct device *dev) { - unsigned long power, freq =3D 0; - struct dev_pm_opp *opp; + struct dev_pm_opp *opp __free(put_opp); + unsigned long freq =3D 0; =20 /* Check if at least one OPP has needed property */ opp =3D dev_pm_opp_find_freq_ceil(dev, &freq); if (IS_ERR(opp)) return false; =20 - power =3D dev_pm_opp_get_power(opp); - dev_pm_opp_put(opp); - if (!power) - return false; - - return true; + return !!dev_pm_opp_get_power(opp); } =20 /** diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 0deddfa91aca..e7b5c602c92f 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -11,6 +11,7 @@ #ifndef __LINUX_OPP_H__ #define __LINUX_OPP_H__ =20 +#include #include #include #include @@ -710,4 +711,10 @@ static inline unsigned long dev_pm_opp_get_freq(struct= dev_pm_opp *opp) return dev_pm_opp_get_freq_indexed(opp, 0); } =20 +/* Scope based cleanup macro for OPP reference counting */ +DEFINE_FREE(put_opp, struct dev_pm_opp *, if (!IS_ERR_OR_NULL(_T)) dev_pm_= opp_put(_T)) + +/* Scope based cleanup macro for OPP table reference counting */ +DEFINE_FREE(put_opp_table, struct opp_table *, if (!IS_ERR_OR_NULL(_T)) de= v_pm_opp_put_opp_table(_T)) + #endif /* __LINUX_OPP_H__ */ --=20 2.31.1.272.g89b43f80a514 From nobody Mon Feb 9 07:19:43 2026 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 26E7C23D294 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-22d95f0dda4so12371765ad.2 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=cUNSEO/EEcjLvcmU+bPb3M58CmhYv7pTRQgGjk/Q279MEuusSUzvqsEe8Yc8uw4sop r80d1BdrjBqOnP4+HghwfypZ4JaSYEYq+gYhJT81g0il6BcN4CuIwwnoLFajYG90xbr6 c1dwZwnEWnUHLt+Zo0kyUeqRtQ/5ITadWkpVKpF/XVvd7OqwQHRkrzO6HfzDykq7PUBy RaeoGNtZZlm52U8t3dq9GwSGcSrQYViAqjkT4IswKRbDMREz5OTgxp4dpFBjdoO0sgjj efidnRmhB/+2KNtGOBh5yiN3Uxz9A7/p2ySdOQ00pIoFVdDUZyihW9hnnKXKCDjCAEy+ eg5w== X-Forwarded-Encrypted: i=1; AJvYcCU25+qGHRAu1lp35s0SYzClPn3JD2IICuwu4lWGnQU62i9lAaj/xrCBI1G3RqDXvV20oNiJuRvxuRs1lVo=@vger.kernel.org X-Gm-Message-State: AOJu0YwWu1lV4rojqlSl3GKXSghm/bf/M2R7qQCobXMBkyJcEeeYlLr4 gp6r7Fv43fhebYxWF7A2rAPI1IaLXX7PnA7z2xrWOmxlAz7bEKx3r/7GZWXIupw= X-Gm-Gg: ASbGnctd1rLlvMXFbQdUTAVYWriLMGa95Jc/EfASc2TVkxrfUUJ2j3KEaULtAaScuUa uKmNvSY3V70VvYAwH4wZB7W4vfAgnJw0/7BsAuZYxDBmzxgTPFv4gUoHBNHOgvNbbmTGCb1rRhS mvzYhfTQTFyUi+q+kR+QdIuW1kKmH1PRnGpmWdkaVpuN5s8q5aD24SXEaWBEz6VjYrHbPrywSI5 dILpWOlwPVv+8vsT8aY6ttQ1iXRsxugmKqhtsFQVmVX0Iijae6u9QjA05IxvAzQFv3bgO7lzyo+ sAXS1X9aVpliLPdvlnX1+CFGg6LU8D7Cxxj08/DlZlq8KoLrUOTw 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D false; =20 - 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 =3D=3D dev) { - found =3D true; - break; - } + if (opp_dev->dev =3D=3D dev) + return true; =20 - mutex_unlock(&opp_table->lock); - return found; + return false; } =20 static struct opp_table *_find_opp_table_unlocked(struct device *dev) @@ -78,18 +75,13 @@ static struct opp_table *_find_opp_table_unlocked(struc= t 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); } =20 - mutex_lock(&opp_table_lock); - opp_table =3D _find_opp_table_unlocked(dev); - mutex_unlock(&opp_table_lock); - - return opp_table; + guard(mutex)(&opp_table_lock); + return _find_opp_table_unlocked(dev); } =20 /* @@ -359,25 +351,23 @@ unsigned long dev_pm_opp_get_max_volt_latency(struct = device *dev) if (!uV) return 0; =20 - mutex_lock(&opp_table->lock); - - for (i =3D 0; i < count; i++) { - uV[i].min =3D ~0; - uV[i].max =3D 0; + scoped_guard(mutex, &opp_table->lock) { + for (i =3D 0; i < count; i++) { + uV[i].min =3D ~0; + uV[i].max =3D 0; =20 - 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; =20 - if (opp->supplies[i].u_volt_min < uV[i].min) - uV[i].min =3D opp->supplies[i].u_volt_min; - if (opp->supplies[i].u_volt_max > uV[i].max) - uV[i].max =3D opp->supplies[i].u_volt_max; + if (opp->supplies[i].u_volt_min < uV[i].min) + uV[i].min =3D opp->supplies[i].u_volt_min; + if (opp->supplies[i].u_volt_max > uV[i].max) + uV[i].max =3D opp->supplies[i].u_volt_max; + } } } =20 - 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 =3D 0; =20 - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); =20 list_for_each_entry(opp, &opp_table->opp_list, node) { if (opp->available) count++; } =20 - mutex_unlock(&opp_table->lock); - return count; } =20 @@ -535,7 +523,7 @@ static struct dev_pm_opp *_opp_table_find_key(struct op= p_table *opp_table, if (assert && !assert(opp_table, index)) return ERR_PTR(-EINVAL); =20 - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); =20 list_for_each_entry(temp_opp, &opp_table->opp_list, node) { if (temp_opp->available =3D=3D available) { @@ -550,8 +538,6 @@ static struct dev_pm_opp *_opp_table_find_key(struct op= p_table *opp_table, dev_pm_opp_get(opp); } =20 - mutex_unlock(&opp_table->lock); - return opp; } =20 @@ -1166,10 +1152,9 @@ static void _find_current_opp(struct device *dev, st= ruct 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 =3D dev_pm_opp_get(list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node)); - mutex_unlock(&opp_table->lock); } =20 opp_table->current_opp =3D opp; @@ -1426,9 +1411,8 @@ struct opp_device *_add_opp_dev(const struct device *= dev, /* Initialize opp-dev */ opp_dev->dev =3D dev; =20 - 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); =20 /* 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; =20 - mutex_lock(&opp_table->lock); - - list_for_each_entry(iter, &opp_table->opp_list, node) { - if (iter->rates[0] =3D=3D freq) { - opp =3D iter; - break; + scoped_guard(mutex, &opp_table->lock) { + list_for_each_entry(iter, &opp_table->opp_list, node) { + if (iter->rates[0] =3D=3D freq) { + opp =3D iter; + break; + } } } =20 - mutex_unlock(&opp_table->lock); - if (opp) { dev_pm_opp_put(opp); =20 @@ -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 =3D NULL, *temp; + struct dev_pm_opp *opp; =20 - 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 =3D=3D temp->dynamic) { - opp =3D temp; - break; - } + if (!opp->removed && dynamic =3D=3D opp->dynamic) + return opp; } =20 - mutex_unlock(&opp_table->lock); - return opp; + return NULL; } =20 /* @@ -1786,20 +1766,14 @@ static void _opp_remove_all(struct opp_table *opp_t= able, bool dynamic) =20 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; =20 - if (--opp_table->parsed_static_opps) { - mutex_unlock(&opp_table->lock); - return true; + if (--opp_table->parsed_static_opps) + return true; } =20 - 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; =20 - mutex_lock(&opp_table->lock); - head =3D &opp_table->opp_list; + scoped_guard(mutex, &opp_table->lock) { + head =3D &opp_table->opp_list; =20 - ret =3D _opp_is_duplicate(dev, new_opp, opp_table, &head); - if (ret) { - mutex_unlock(&opp_table->lock); - return ret; - } + ret =3D _opp_is_duplicate(dev, new_opp, opp_table, &head); + if (ret) + return ret; =20 - list_add(&new_opp->node, head); - mutex_unlock(&opp_table->lock); + list_add(&new_opp->node, head); + } =20 new_opp->opp_table =3D opp_table; kref_init(&new_opp->kref); @@ -2660,17 +2632,16 @@ struct dev_pm_opp *dev_pm_opp_xlate_required_opp(st= ruct opp_table *src_table, return ERR_PTR(-EBUSY); =20 for (i =3D 0; i < src_table->required_opp_count; i++) { - if (src_table->required_opp_tables[i] =3D=3D dst_table) { - mutex_lock(&src_table->lock); + if (src_table->required_opp_tables[i] !=3D dst_table) + continue; =20 + scoped_guard(mutex, &src_table->lock) { list_for_each_entry(opp, &src_table->opp_list, node) { if (opp =3D=3D src_opp) { dest_opp =3D 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_tab= le *src_table, unsigned int pstate) { struct dev_pm_opp *opp; - int dest_pstate =3D -EINVAL; int i; =20 /* @@ -2736,22 +2706,17 @@ int dev_pm_opp_xlate_performance_state(struct opp_t= able *src_table, return -EINVAL; } =20 - mutex_lock(&src_table->lock); + guard(mutex)(&src_table->lock); =20 list_for_each_entry(opp, &src_table->opp_list, node) { - if (opp->level =3D=3D pstate) { - dest_pstate =3D opp->required_opps[i]->level; - goto unlock; - } + if (opp->level =3D=3D pstate) + return opp->required_opps[i]->level; } =20 pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__, src_table, dst_table); =20 -unlock: - mutex_unlock(&src_table->lock); - - return dest_pstate; + return -EINVAL; } =20 /** @@ -2820,26 +2785,22 @@ static int _opp_set_availability(struct device *dev= , unsigned long freq, if (!assert_single_clk(opp_table, 0)) return -EINVAL; =20 - 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] =3D=3D freq) { + opp =3D dev_pm_opp_get(tmp_opp); =20 - /* Do we have the frequency? */ - list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { - if (tmp_opp->rates[0] =3D=3D freq) { - opp =3D dev_pm_opp_get(tmp_opp); + /* Is update really needed? */ + if (opp->available =3D=3D availability_req) + return 0; =20 - /* Is update really needed? */ - if (opp->available =3D=3D availability_req) { - mutex_unlock(&opp_table->lock); - return 0; + opp->available =3D availability_req; + break; } - - opp->available =3D availability_req; - break; } } =20 - mutex_unlock(&opp_table->lock); - if (IS_ERR(opp)) return PTR_ERR(opp); =20 @@ -2886,29 +2847,25 @@ int dev_pm_opp_adjust_voltage(struct device *dev, u= nsigned long freq, if (!assert_single_clk(opp_table, 0)) return -EINVAL; =20 - 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] =3D=3D freq) { - opp =3D 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] =3D=3D freq) { + opp =3D dev_pm_opp_get(tmp_opp); =20 - /* Is update really needed? */ - if (opp->supplies->u_volt =3D=3D u_volt) { - mutex_unlock(&opp_table->lock); - return 0; - } + /* Is update really needed? */ + if (opp->supplies->u_volt =3D=3D u_volt) + return 0; =20 - opp->supplies->u_volt =3D u_volt; - opp->supplies->u_volt_min =3D u_volt_min; - opp->supplies->u_volt_max =3D u_volt_max; + opp->supplies->u_volt =3D u_volt; + opp->supplies->u_volt_min =3D u_volt_min; + opp->supplies->u_volt_max =3D u_volt_max; =20 - break; + break; + } } } =20 - mutex_unlock(&opp_table->lock); - if (IS_ERR(opp)) return PTR_ERR(opp); =20 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); =20 if (opp_table->shared_opp =3D=3D 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_ta= ble *opp_table, { struct dev_pm_opp *opp; =20 - mutex_lock(&opp_table->lock); + guard(mutex)(&opp_table->lock); =20 list_for_each_entry(opp, &opp_table->opp_list, node) { - if (opp->np =3D=3D opp_np) { - dev_pm_opp_get(opp); - mutex_unlock(&opp_table->lock); - return opp; - } + if (opp->np =3D=3D opp_np) + return dev_pm_opp_get(opp); } =20 - mutex_unlock(&opp_table->lock); - return NULL; } =20 @@ -105,19 +100,15 @@ static struct opp_table *_find_table_of_opp_np(struct= device_node *opp_np) =20 opp_table_np =3D of_get_parent(opp_np); if (!opp_table_np) - goto err; + return ERR_PTR(-ENODEV); + + guard(mutex)(&opp_table_lock); =20 - mutex_lock(&opp_table_lock); list_for_each_entry(opp_table, &opp_tables, node) { - if (opp_table_np =3D=3D opp_table->np) { - dev_pm_opp_get_opp_table_ref(opp_table); - mutex_unlock(&opp_table_lock); - return opp_table; - } + if (opp_table_np =3D=3D opp_table->np) + return dev_pm_opp_get_opp_table_ref(opp_table); } - mutex_unlock(&opp_table_lock); =20 -err: return ERR_PTR(-ENODEV); } =20 @@ -142,9 +133,8 @@ static void _opp_table_free_required_tables(struct opp_= table *opp_table) opp_table->required_opp_count =3D 0; opp_table->required_opp_tables =3D NULL; =20 - mutex_lock(&opp_table_lock); + guard(mutex)(&opp_table_lock); list_del(&opp_table->lazy); - mutex_unlock(&opp_table_lock); } =20 /* @@ -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); } } =20 @@ -357,7 +346,7 @@ static void lazy_link_required_opp_table(struct opp_tab= le *new_table) struct dev_pm_opp *opp; int i, ret; =20 - mutex_lock(&opp_table_lock); + guard(mutex)(&opp_table_lock); =20 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_tab= le *new_table) _required_opps_available(opp, opp_table->required_opp_count); } } - - mutex_unlock(&opp_table_lock); } =20 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, s= truct opp_table *opp_table) struct dev_pm_opp *opp; =20 /* 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; + } =20 - opp_table->parsed_static_opps =3D 1; - mutex_unlock(&opp_table->lock); + opp_table->parsed_static_opps =3D 1; + } =20 /* 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 =3D 0; =20 - 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; + } =20 - opp_table->parsed_static_opps =3D 1; - mutex_unlock(&opp_table->lock); + opp_table->parsed_static_opps =3D 1; + } =20 prop =3D of_find_property(dev->of_node, "operating-points", NULL); if (!prop) { --=20 2.31.1.272.g89b43f80a514