aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorAndrey Gelman <andreyg@compulab.co.il>2013-01-27 15:16:33 -0500
committerAnton Vorontsov <anton@enomsg.org>2013-03-18 22:27:31 -0400
commit9239ebcffb9301eab75c638dcb702688884cc5d6 (patch)
tree49d7c52c0abf730b9035de5d2a899400c3df1f91 /drivers/power
parent6f8da5df8c451103e0043f73a00c90676da6be9e (diff)
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>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/test_power.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/drivers/power/test_power.c b/drivers/power/test_power.c
index b99a452a4fda..0152f35dca5c 100644
--- a/drivers/power/test_power.c
+++ b/drivers/power/test_power.c
@@ -30,6 +30,8 @@ static int battery_technology = POWER_SUPPLY_TECHNOLOGY_LION;
30static int battery_capacity = 50; 30static int battery_capacity = 50;
31static int battery_voltage = 3300; 31static int battery_voltage = 3300;
32 32
33static bool module_initialized;
34
33static int test_power_get_ac_property(struct power_supply *psy, 35static int test_power_get_ac_property(struct power_supply *psy,
34 enum power_supply_property psp, 36 enum power_supply_property psp,
35 union power_supply_propval *val) 37 union power_supply_propval *val)
@@ -185,6 +187,7 @@ static int __init test_power_init(void)
185 } 187 }
186 } 188 }
187 189
190 module_initialized = true;
188 return 0; 191 return 0;
189failed: 192failed:
190 while (--i >= 0) 193 while (--i >= 0)
@@ -209,6 +212,8 @@ static void __exit test_power_exit(void)
209 212
210 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) 213 for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++)
211 power_supply_unregister(&test_power_supplies[i]); 214 power_supply_unregister(&test_power_supplies[i]);
215
216 module_initialized = false;
212} 217}
213module_exit(test_power_exit); 218module_exit(test_power_exit);
214 219
@@ -221,8 +226,8 @@ struct battery_property_map {
221}; 226};
222 227
223static struct battery_property_map map_ac_online[] = { 228static struct battery_property_map map_ac_online[] = {
224 { 0, "on" }, 229 { 0, "off" },
225 { 1, "off" }, 230 { 1, "on" },
226 { -1, NULL }, 231 { -1, NULL },
227}; 232};
228 233
@@ -295,10 +300,16 @@ static const char *map_get_key(struct battery_property_map *map, int value,
295 return def_key; 300 return def_key;
296} 301}
297 302
303static inline void signal_power_supply_changed(struct power_supply *psy)
304{
305 if (module_initialized)
306 power_supply_changed(psy);
307}
308
298static int param_set_ac_online(const char *key, const struct kernel_param *kp) 309static int param_set_ac_online(const char *key, const struct kernel_param *kp)
299{ 310{
300 ac_online = map_get_value(map_ac_online, key, ac_online); 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 return 0; 313 return 0;
303} 314}
304 315
@@ -311,7 +322,7 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
311static int param_set_usb_online(const char *key, const struct kernel_param *kp) 322static int param_set_usb_online(const char *key, const struct kernel_param *kp)
312{ 323{
313 usb_online = map_get_value(map_ac_online, key, usb_online); 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 return 0; 326 return 0;
316} 327}
317 328
@@ -325,7 +336,7 @@ static int param_set_battery_status(const char *key,
325 const struct kernel_param *kp) 336 const struct kernel_param *kp)
326{ 337{
327 battery_status = map_get_value(map_status, key, battery_status); 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 return 0; 340 return 0;
330} 341}
331 342
@@ -339,7 +350,7 @@ static int param_set_battery_health(const char *key,
339 const struct kernel_param *kp) 350 const struct kernel_param *kp)
340{ 351{
341 battery_health = map_get_value(map_health, key, battery_health); 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 return 0; 354 return 0;
344} 355}
345 356
@@ -353,7 +364,7 @@ static int param_set_battery_present(const char *key,
353 const struct kernel_param *kp) 364 const struct kernel_param *kp)
354{ 365{
355 battery_present = map_get_value(map_present, key, battery_present); 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 return 0; 368 return 0;
358} 369}
359 370
@@ -369,7 +380,7 @@ static int param_set_battery_technology(const char *key,
369{ 380{
370 battery_technology = map_get_value(map_technology, key, 381 battery_technology = map_get_value(map_technology, key,
371 battery_technology); 382 battery_technology);
372 power_supply_changed(&test_power_supplies[1]); 383 signal_power_supply_changed(&test_power_supplies[1]);
373 return 0; 384 return 0;
374} 385}
375 386
@@ -390,7 +401,7 @@ static int param_set_battery_capacity(const char *key,
390 return -EINVAL; 401 return -EINVAL;
391 402
392 battery_capacity = tmp; 403 battery_capacity = tmp;
393 power_supply_changed(&test_power_supplies[1]); 404 signal_power_supply_changed(&test_power_supplies[1]);
394 return 0; 405 return 0;
395} 406}
396 407
@@ -405,7 +416,7 @@ static int param_set_battery_voltage(const char *key,
405 return -EINVAL; 416 return -EINVAL;
406 417
407 battery_voltage = tmp; 418 battery_voltage = tmp;
408 power_supply_changed(&test_power_supplies[1]); 419 signal_power_supply_changed(&test_power_supplies[1]);
409 return 0; 420 return 0;
410} 421}
411 422