Commit 9239ebcffb9301eab75c638dcb702688884cc5d6
Committed by
Anton Vorontsov
1 parent
6f8da5df8c
Exists in
master
and in
20 other branches
test_power: Fix a bug in setting module parameter values
When the kernel loads a module, module params are processed prior to calling module_init. As a result, setting module param value should not have side effects, at least as long as the module has not been initialized. Signed-off-by: Andrey Gelman <andreyg@compulab.co.il> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Showing 1 changed file with 21 additions and 10 deletions Side-by-side Diff
drivers/power/test_power.c
... | ... | @@ -30,6 +30,8 @@ |
30 | 30 | static int battery_capacity = 50; |
31 | 31 | static int battery_voltage = 3300; |
32 | 32 | |
33 | +static bool module_initialized; | |
34 | + | |
33 | 35 | static int test_power_get_ac_property(struct power_supply *psy, |
34 | 36 | enum power_supply_property psp, |
35 | 37 | union power_supply_propval *val) |
... | ... | @@ -185,6 +187,7 @@ |
185 | 187 | } |
186 | 188 | } |
187 | 189 | |
190 | + module_initialized = true; | |
188 | 191 | return 0; |
189 | 192 | failed: |
190 | 193 | while (--i >= 0) |
... | ... | @@ -209,6 +212,8 @@ |
209 | 212 | |
210 | 213 | for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) |
211 | 214 | power_supply_unregister(&test_power_supplies[i]); |
215 | + | |
216 | + module_initialized = false; | |
212 | 217 | } |
213 | 218 | module_exit(test_power_exit); |
214 | 219 | |
... | ... | @@ -221,8 +226,8 @@ |
221 | 226 | }; |
222 | 227 | |
223 | 228 | static struct battery_property_map map_ac_online[] = { |
224 | - { 0, "on" }, | |
225 | - { 1, "off" }, | |
229 | + { 0, "off" }, | |
230 | + { 1, "on" }, | |
226 | 231 | { -1, NULL }, |
227 | 232 | }; |
228 | 233 | |
229 | 234 | |
... | ... | @@ -295,10 +300,16 @@ |
295 | 300 | return def_key; |
296 | 301 | } |
297 | 302 | |
303 | +static inline void signal_power_supply_changed(struct power_supply *psy) | |
304 | +{ | |
305 | + if (module_initialized) | |
306 | + power_supply_changed(psy); | |
307 | +} | |
308 | + | |
298 | 309 | static int param_set_ac_online(const char *key, const struct kernel_param *kp) |
299 | 310 | { |
300 | 311 | ac_online = map_get_value(map_ac_online, key, ac_online); |
301 | - power_supply_changed(&test_power_supplies[0]); | |
312 | + signal_power_supply_changed(&test_power_supplies[0]); | |
302 | 313 | return 0; |
303 | 314 | } |
304 | 315 | |
... | ... | @@ -311,7 +322,7 @@ |
311 | 322 | static int param_set_usb_online(const char *key, const struct kernel_param *kp) |
312 | 323 | { |
313 | 324 | usb_online = map_get_value(map_ac_online, key, usb_online); |
314 | - power_supply_changed(&test_power_supplies[2]); | |
325 | + signal_power_supply_changed(&test_power_supplies[2]); | |
315 | 326 | return 0; |
316 | 327 | } |
317 | 328 | |
... | ... | @@ -325,7 +336,7 @@ |
325 | 336 | const struct kernel_param *kp) |
326 | 337 | { |
327 | 338 | battery_status = map_get_value(map_status, key, battery_status); |
328 | - power_supply_changed(&test_power_supplies[1]); | |
339 | + signal_power_supply_changed(&test_power_supplies[1]); | |
329 | 340 | return 0; |
330 | 341 | } |
331 | 342 | |
... | ... | @@ -339,7 +350,7 @@ |
339 | 350 | const struct kernel_param *kp) |
340 | 351 | { |
341 | 352 | battery_health = map_get_value(map_health, key, battery_health); |
342 | - power_supply_changed(&test_power_supplies[1]); | |
353 | + signal_power_supply_changed(&test_power_supplies[1]); | |
343 | 354 | return 0; |
344 | 355 | } |
345 | 356 | |
... | ... | @@ -353,7 +364,7 @@ |
353 | 364 | const struct kernel_param *kp) |
354 | 365 | { |
355 | 366 | battery_present = map_get_value(map_present, key, battery_present); |
356 | - power_supply_changed(&test_power_supplies[0]); | |
367 | + signal_power_supply_changed(&test_power_supplies[0]); | |
357 | 368 | return 0; |
358 | 369 | } |
359 | 370 | |
... | ... | @@ -369,7 +380,7 @@ |
369 | 380 | { |
370 | 381 | battery_technology = map_get_value(map_technology, key, |
371 | 382 | battery_technology); |
372 | - power_supply_changed(&test_power_supplies[1]); | |
383 | + signal_power_supply_changed(&test_power_supplies[1]); | |
373 | 384 | return 0; |
374 | 385 | } |
375 | 386 | |
... | ... | @@ -390,7 +401,7 @@ |
390 | 401 | return -EINVAL; |
391 | 402 | |
392 | 403 | battery_capacity = tmp; |
393 | - power_supply_changed(&test_power_supplies[1]); | |
404 | + signal_power_supply_changed(&test_power_supplies[1]); | |
394 | 405 | return 0; |
395 | 406 | } |
396 | 407 | |
... | ... | @@ -405,7 +416,7 @@ |
405 | 416 | return -EINVAL; |
406 | 417 | |
407 | 418 | battery_voltage = tmp; |
408 | - power_supply_changed(&test_power_supplies[1]); | |
419 | + signal_power_supply_changed(&test_power_supplies[1]); | |
409 | 420 | return 0; |
410 | 421 | } |
411 | 422 |