linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/loongson2: Constify struct thermal_zone_device_ops
@ 2025-05-25 12:32 Christophe JAILLET
  2025-07-15 13:24 ` Daniel Lezcano
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2025-05-25 12:32 UTC (permalink / raw)
  To: zhanghongchen, Yinbo Zhu, Rafael J. Wysocki, Daniel Lezcano,
	Zhang Rui, Lukasz Luba
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-pm

'struct thermal_zone_device_ops' could be left unmodified in this driver.

Constifying this structure moves some data to a read-only section, so
increases overall security, especially when the structure holds some
function pointers.

This partly reverts commit 734b5def91b5 ("thermal/drivers/loongson2: Add
Loongson-2K2000 support") which removed the const qualifier. Instead,
define two different structures.

On a x86_64, with allmodconfig:
Before:
======
   text	   data	    bss	    dec	    hex	filename
   5089	   1160	      0	   6249	   1869	drivers/thermal/loongson2_thermal.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
   5464	   1128	      0	   6592	   19c0	drivers/thermal/loongson2_thermal.o

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
 drivers/thermal/loongson2_thermal.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/thermal/loongson2_thermal.c b/drivers/thermal/loongson2_thermal.c
index 2d6b75b0539f..ea4dd2fb1f47 100644
--- a/drivers/thermal/loongson2_thermal.c
+++ b/drivers/thermal/loongson2_thermal.c
@@ -112,13 +112,19 @@ static int loongson2_thermal_set_trips(struct thermal_zone_device *tz, int low,
 	return loongson2_thermal_set(data, low/MILLI, high/MILLI, true);
 }
 
-static struct thermal_zone_device_ops loongson2_of_thermal_ops = {
+static const struct thermal_zone_device_ops loongson2_2k1000_of_thermal_ops = {
 	.get_temp = loongson2_2k1000_get_temp,
 	.set_trips = loongson2_thermal_set_trips,
 };
 
+static const struct thermal_zone_device_ops loongson2_2k2000_of_thermal_ops = {
+	.get_temp = loongson2_2k2000_get_temp,
+	.set_trips = loongson2_thermal_set_trips,
+};
+
 static int loongson2_thermal_probe(struct platform_device *pdev)
 {
+	const struct thermal_zone_device_ops *thermal_ops;
 	struct device *dev = &pdev->dev;
 	struct loongson2_thermal_data *data;
 	struct thermal_zone_device *tzd;
@@ -140,7 +146,9 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
 		if (IS_ERR(data->temp_reg))
 			return PTR_ERR(data->temp_reg);
 
-		loongson2_of_thermal_ops.get_temp = loongson2_2k2000_get_temp;
+		thermal_ops = &loongson2_2k2000_of_thermal_ops;
+	} else {
+		thermal_ops = &loongson2_2k1000_of_thermal_ops;
 	}
 
 	irq = platform_get_irq(pdev, 0);
@@ -152,8 +160,7 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
 	loongson2_thermal_set(data, 0, 0, false);
 
 	for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) {
-		tzd = devm_thermal_of_zone_register(dev, i, data,
-						    &loongson2_of_thermal_ops);
+		tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops);
 
 		if (!IS_ERR(tzd))
 			break;
-- 
2.49.0


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

* Re: [PATCH] thermal/drivers/loongson2: Constify struct thermal_zone_device_ops
  2025-05-25 12:32 [PATCH] thermal/drivers/loongson2: Constify struct thermal_zone_device_ops Christophe JAILLET
@ 2025-07-15 13:24 ` Daniel Lezcano
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Lezcano @ 2025-07-15 13:24 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: zhanghongchen, Yinbo Zhu, Rafael J. Wysocki, Zhang Rui,
	Lukasz Luba, linux-kernel, kernel-janitors, linux-pm

On Sun, May 25, 2025 at 02:32:30PM +0200, Christophe JAILLET wrote:
> 'struct thermal_zone_device_ops' could be left unmodified in this driver.
> 
> Constifying this structure moves some data to a read-only section, so
> increases overall security, especially when the structure holds some
> function pointers.
> 
> This partly reverts commit 734b5def91b5 ("thermal/drivers/loongson2: Add
> Loongson-2K2000 support") which removed the const qualifier. Instead,
> define two different structures.
> 
> On a x86_64, with allmodconfig:
> Before:
> ======
>    text	   data	    bss	    dec	    hex	filename
>    5089	   1160	      0	   6249	   1869	drivers/thermal/loongson2_thermal.o
> 
> After:
> =====
>    text	   data	    bss	    dec	    hex	filename
>    5464	   1128	      0	   6592	   19c0	drivers/thermal/loongson2_thermal.o
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only
> ---

Applied, thanks

-- 

 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

end of thread, other threads:[~2025-07-15 13:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-25 12:32 [PATCH] thermal/drivers/loongson2: Constify struct thermal_zone_device_ops Christophe JAILLET
2025-07-15 13:24 ` Daniel Lezcano

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).