Skip to content

Commit eb51476

Browse files
tititiou36dlezcano
authored andcommitted
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 734b5de ("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>
1 parent 97d4d77 commit eb51476

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

drivers/thermal/loongson2_thermal.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,19 @@ static int loongson2_thermal_set_trips(struct thermal_zone_device *tz, int low,
112112
return loongson2_thermal_set(data, low/MILLI, high/MILLI, true);
113113
}
114114

115-
static struct thermal_zone_device_ops loongson2_of_thermal_ops = {
115+
static const struct thermal_zone_device_ops loongson2_2k1000_of_thermal_ops = {
116116
.get_temp = loongson2_2k1000_get_temp,
117117
.set_trips = loongson2_thermal_set_trips,
118118
};
119119

120+
static const struct thermal_zone_device_ops loongson2_2k2000_of_thermal_ops = {
121+
.get_temp = loongson2_2k2000_get_temp,
122+
.set_trips = loongson2_thermal_set_trips,
123+
};
124+
120125
static int loongson2_thermal_probe(struct platform_device *pdev)
121126
{
127+
const struct thermal_zone_device_ops *thermal_ops;
122128
struct device *dev = &pdev->dev;
123129
struct loongson2_thermal_data *data;
124130
struct thermal_zone_device *tzd;
@@ -140,7 +146,9 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
140146
if (IS_ERR(data->temp_reg))
141147
return PTR_ERR(data->temp_reg);
142148

143-
loongson2_of_thermal_ops.get_temp = loongson2_2k2000_get_temp;
149+
thermal_ops = &loongson2_2k2000_of_thermal_ops;
150+
} else {
151+
thermal_ops = &loongson2_2k1000_of_thermal_ops;
144152
}
145153

146154
irq = platform_get_irq(pdev, 0);
@@ -152,8 +160,7 @@ static int loongson2_thermal_probe(struct platform_device *pdev)
152160
loongson2_thermal_set(data, 0, 0, false);
153161

154162
for (i = 0; i <= LOONGSON2_MAX_SENSOR_SEL_NUM; i++) {
155-
tzd = devm_thermal_of_zone_register(dev, i, data,
156-
&loongson2_of_thermal_ops);
163+
tzd = devm_thermal_of_zone_register(dev, i, data, thermal_ops);
157164

158165
if (!IS_ERR(tzd))
159166
break;

0 commit comments

Comments
 (0)