Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal/drivers/loongson2: Constify struct thermal_zone_device_ops

'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>
Link: https://lore.kernel.org/r/5f5f815f85a9450bca7848c6d47a1fee840f47e5.1748176328.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Christophe JAILLET and committed by
Daniel Lezcano
eb514766 97d4d774

+11 -4
+11 -4
drivers/thermal/loongson2_thermal.c
··· 112 112 return loongson2_thermal_set(data, low/MILLI, high/MILLI, true); 113 113 } 114 114 115 - static struct thermal_zone_device_ops loongson2_of_thermal_ops = { 115 + static const struct thermal_zone_device_ops loongson2_2k1000_of_thermal_ops = { 116 116 .get_temp = loongson2_2k1000_get_temp, 117 + .set_trips = loongson2_thermal_set_trips, 118 + }; 119 + 120 + static const struct thermal_zone_device_ops loongson2_2k2000_of_thermal_ops = { 121 + .get_temp = loongson2_2k2000_get_temp, 117 122 .set_trips = loongson2_thermal_set_trips, 118 123 }; 119 124 120 125 static int loongson2_thermal_probe(struct platform_device *pdev) 121 126 { 127 + const struct thermal_zone_device_ops *thermal_ops; 122 128 struct device *dev = &pdev->dev; 123 129 struct loongson2_thermal_data *data; 124 130 struct thermal_zone_device *tzd; ··· 146 140 if (IS_ERR(data->temp_reg)) 147 141 return PTR_ERR(data->temp_reg); 148 142 149 - loongson2_of_thermal_ops.get_temp = loongson2_2k2000_get_temp; 143 + thermal_ops = &loongson2_2k2000_of_thermal_ops; 144 + } else { 145 + thermal_ops = &loongson2_2k1000_of_thermal_ops; 150 146 } 151 147 152 148 irq = platform_get_irq(pdev, 0); ··· 160 152 loongson2_thermal_set(data, 0, 0, false); 161 153 162 154 for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) { 163 - tzd = devm_thermal_of_zone_register(dev, i, data, 164 - &loongson2_of_thermal_ops); 155 + tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops); 165 156 166 157 if (!IS_ERR(tzd)) 167 158 break;