linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] powercap/drivers/dtpm: Constify static ops structs
@ 2021-12-02 14:37 Rikard Falkeborn
  2021-12-02 14:37 ` [PATCH 1/2] powercap/drivers/dtpm: Constify powercap_zone_{,constraint_}ops Rikard Falkeborn
  2021-12-02 14:37 ` [PATCH 2/2] powercap/drivers/dtpm: Constify dtpm_ops Rikard Falkeborn
  0 siblings, 2 replies; 3+ messages in thread
From: Rikard Falkeborn @ 2021-12-02 14:37 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: linux-pm, linux-kernel, Rikard Falkeborn

Constify a couple of static ops structs that are never modified, to allow
the compiler to put them in read-only memory.

The first patch constifies one powercap_zone_constraint_ops and one
powercap_zone_ops. These are only passed to powercap_register_zone()
which accepts const pointers.

The second patch constifies dtpm_ops. In order to do that, we need to add
const to an init function and in the dtpm struct, which is ok since noone
modifies the struct.

Rikard Falkeborn (2):
  powercap/drivers/dtpm: Constify powercap_zone_{,constraint_}ops
  powercap/drivers/dtpm: Constify dtpm_ops

 drivers/powercap/dtpm.c     | 6 +++---
 drivers/powercap/dtpm_cpu.c | 2 +-
 include/linux/dtpm.h        | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] powercap/drivers/dtpm: Constify powercap_zone_{,constraint_}ops
  2021-12-02 14:37 [PATCH 0/2] powercap/drivers/dtpm: Constify static ops structs Rikard Falkeborn
@ 2021-12-02 14:37 ` Rikard Falkeborn
  2021-12-02 14:37 ` [PATCH 2/2] powercap/drivers/dtpm: Constify dtpm_ops Rikard Falkeborn
  1 sibling, 0 replies; 3+ messages in thread
From: Rikard Falkeborn @ 2021-12-02 14:37 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: linux-pm, linux-kernel, Rikard Falkeborn

These are only passed as input to powercap_register_zone() which takes
pointers to const powercap_zone_ops and powercap_zone_constraint_ops.
Make them const to allow the compiler to put them in read-only memory.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
---
 drivers/powercap/dtpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/powercap/dtpm.c b/drivers/powercap/dtpm.c
index b9fac786246a..d7ac5e79fee1 100644
--- a/drivers/powercap/dtpm.c
+++ b/drivers/powercap/dtpm.c
@@ -341,7 +341,7 @@ static int get_max_power_uw(struct powercap_zone *pcz, int id, u64 *max_power)
 	return 0;
 }
 
-static struct powercap_zone_constraint_ops constraint_ops = {
+static const struct powercap_zone_constraint_ops constraint_ops = {
 	.set_power_limit_uw = set_power_limit_uw,
 	.get_power_limit_uw = get_power_limit_uw,
 	.set_time_window_us = set_time_window_us,
@@ -350,7 +350,7 @@ static struct powercap_zone_constraint_ops constraint_ops = {
 	.get_name = get_constraint_name,
 };
 
-static struct powercap_zone_ops zone_ops = {
+static const struct powercap_zone_ops zone_ops = {
 	.get_max_power_range_uw = get_max_power_range_uw,
 	.get_power_uw = get_power_uw,
 	.release = dtpm_release_zone,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] powercap/drivers/dtpm: Constify dtpm_ops
  2021-12-02 14:37 [PATCH 0/2] powercap/drivers/dtpm: Constify static ops structs Rikard Falkeborn
  2021-12-02 14:37 ` [PATCH 1/2] powercap/drivers/dtpm: Constify powercap_zone_{,constraint_}ops Rikard Falkeborn
@ 2021-12-02 14:37 ` Rikard Falkeborn
  1 sibling, 0 replies; 3+ messages in thread
From: Rikard Falkeborn @ 2021-12-02 14:37 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: linux-pm, linux-kernel, Rikard Falkeborn

dtpm_ops is never modified, so update functions and structs to reflect
that, and constify the one static instance to allow the compiler to put
it in read-only memory.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
---
 drivers/powercap/dtpm.c     | 2 +-
 drivers/powercap/dtpm_cpu.c | 2 +-
 include/linux/dtpm.h        | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/powercap/dtpm.c b/drivers/powercap/dtpm.c
index d7ac5e79fee1..07e4dec604de 100644
--- a/drivers/powercap/dtpm.c
+++ b/drivers/powercap/dtpm.c
@@ -361,7 +361,7 @@ static const struct powercap_zone_ops zone_ops = {
  * @dtpm: The dtpm struct pointer to be initialized
  * @ops: The dtpm device specific ops, NULL for a virtual node
  */
-void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops)
+void dtpm_init(struct dtpm *dtpm, const struct dtpm_ops *ops)
 {
 	if (dtpm) {
 		INIT_LIST_HEAD(&dtpm->children);
diff --git a/drivers/powercap/dtpm_cpu.c b/drivers/powercap/dtpm_cpu.c
index b740866b228d..2eeff292ffbe 100644
--- a/drivers/powercap/dtpm_cpu.c
+++ b/drivers/powercap/dtpm_cpu.c
@@ -157,7 +157,7 @@ static void pd_release(struct dtpm *dtpm)
 	kfree(dtpm_cpu);
 }
 
-static struct dtpm_ops dtpm_ops = {
+static const struct dtpm_ops dtpm_ops = {
 	.set_power_uw	 = set_pd_power_limit,
 	.get_power_uw	 = get_pd_power_uw,
 	.update_power_uw = update_pd_power_uw,
diff --git a/include/linux/dtpm.h b/include/linux/dtpm.h
index 2890f6370eb9..883f5ab213f3 100644
--- a/include/linux/dtpm.h
+++ b/include/linux/dtpm.h
@@ -17,7 +17,7 @@ struct dtpm {
 	struct dtpm *parent;
 	struct list_head sibling;
 	struct list_head children;
-	struct dtpm_ops *ops;
+	const struct dtpm_ops *ops;
 	unsigned long flags;
 	u64 power_limit;
 	u64 power_max;
@@ -64,7 +64,7 @@ int dtpm_update_power(struct dtpm *dtpm);
 
 int dtpm_release_zone(struct powercap_zone *pcz);
 
-void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops);
+void dtpm_init(struct dtpm *dtpm, const struct dtpm_ops *ops);
 
 void dtpm_unregister(struct dtpm *dtpm);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-02 14:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-02 14:37 [PATCH 0/2] powercap/drivers/dtpm: Constify static ops structs Rikard Falkeborn
2021-12-02 14:37 ` [PATCH 1/2] powercap/drivers/dtpm: Constify powercap_zone_{,constraint_}ops Rikard Falkeborn
2021-12-02 14:37 ` [PATCH 2/2] powercap/drivers/dtpm: Constify dtpm_ops Rikard Falkeborn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).