Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
power: test_power: Use enum as index for array of supplies
Browse files Browse the repository at this point in the history
Replace hard-coded numbers for indices of power supply array with enum.
This improves a little the readability as one does not have to guess
which power supply is associated with number.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
  • Loading branch information
krzk authored and sre committed Jan 23, 2015
1 parent 24d3b15 commit a30067b
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions drivers/power/test_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
#include <linux/delay.h>
#include <linux/vermagic.h>

enum test_power_id {
TEST_AC,
TEST_BATTERY,
TEST_USB,
TEST_POWER_NUM,
};

static int ac_online = 1;
static int usb_online = 1;
static int battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
Expand Down Expand Up @@ -147,21 +154,23 @@ static char *test_power_ac_supplied_to[] = {
};

static struct power_supply test_power_supplies[] = {
{
[TEST_AC] = {
.name = "test_ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.supplied_to = test_power_ac_supplied_to,
.num_supplicants = ARRAY_SIZE(test_power_ac_supplied_to),
.properties = test_power_ac_props,
.num_properties = ARRAY_SIZE(test_power_ac_props),
.get_property = test_power_get_ac_property,
}, {
},
[TEST_BATTERY] = {
.name = "test_battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
.properties = test_power_battery_props,
.num_properties = ARRAY_SIZE(test_power_battery_props),
.get_property = test_power_get_battery_property,
}, {
},
[TEST_USB] = {
.name = "test_usb",
.type = POWER_SUPPLY_TYPE_USB,
.supplied_to = test_power_ac_supplied_to,
Expand All @@ -178,6 +187,8 @@ static int __init test_power_init(void)
int i;
int ret;

BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_supplies));

for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
ret = power_supply_register(NULL, &test_power_supplies[i]);
if (ret) {
Expand Down Expand Up @@ -309,7 +320,7 @@ static inline void signal_power_supply_changed(struct power_supply *psy)
static int param_set_ac_online(const char *key, const struct kernel_param *kp)
{
ac_online = map_get_value(map_ac_online, key, ac_online);
signal_power_supply_changed(&test_power_supplies[0]);
signal_power_supply_changed(&test_power_supplies[TEST_AC]);
return 0;
}

Expand All @@ -322,7 +333,7 @@ static int param_get_ac_online(char *buffer, const struct kernel_param *kp)
static int param_set_usb_online(const char *key, const struct kernel_param *kp)
{
usb_online = map_get_value(map_ac_online, key, usb_online);
signal_power_supply_changed(&test_power_supplies[2]);
signal_power_supply_changed(&test_power_supplies[TEST_USB]);
return 0;
}

Expand All @@ -336,7 +347,7 @@ static int param_set_battery_status(const char *key,
const struct kernel_param *kp)
{
battery_status = map_get_value(map_status, key, battery_status);
signal_power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}

Expand All @@ -350,7 +361,7 @@ static int param_set_battery_health(const char *key,
const struct kernel_param *kp)
{
battery_health = map_get_value(map_health, key, battery_health);
signal_power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}

Expand All @@ -364,7 +375,7 @@ static int param_set_battery_present(const char *key,
const struct kernel_param *kp)
{
battery_present = map_get_value(map_present, key, battery_present);
signal_power_supply_changed(&test_power_supplies[0]);
signal_power_supply_changed(&test_power_supplies[TEST_AC]);
return 0;
}

Expand All @@ -380,7 +391,7 @@ static int param_set_battery_technology(const char *key,
{
battery_technology = map_get_value(map_technology, key,
battery_technology);
signal_power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}

Expand All @@ -401,7 +412,7 @@ static int param_set_battery_capacity(const char *key,
return -EINVAL;

battery_capacity = tmp;
signal_power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}

Expand All @@ -416,7 +427,7 @@ static int param_set_battery_voltage(const char *key,
return -EINVAL;

battery_voltage = tmp;
signal_power_supply_changed(&test_power_supplies[1]);
signal_power_supply_changed(&test_power_supplies[TEST_BATTERY]);
return 0;
}

Expand Down

0 comments on commit a30067b

Please sign in to comment.