ACPI: button: Refactor lid_init_state module parsing code
Replace the weird strncmp() calls in param_set_lid_init_state(), which look to me like they will also accept things like "opennnn" to use sysfs_match_string instead. Also rewrite param_get_lid_init_state() using the new lid_init_state_str array. Instead of doing a straightforward one line replacement, e.g. : return sprintf(buffer, lid_init_state_str[lid_init_state]); print all possible values, putting [] around the selected value, so that users can easily find out what the possible values are. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
d6d5df1db6
commit
065bd4d35b
@ -44,9 +44,17 @@
|
|||||||
#define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch"
|
#define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch"
|
||||||
#define ACPI_BUTTON_TYPE_LID 0x05
|
#define ACPI_BUTTON_TYPE_LID 0x05
|
||||||
|
|
||||||
#define ACPI_BUTTON_LID_INIT_IGNORE 0x00
|
enum {
|
||||||
#define ACPI_BUTTON_LID_INIT_OPEN 0x01
|
ACPI_BUTTON_LID_INIT_IGNORE,
|
||||||
#define ACPI_BUTTON_LID_INIT_METHOD 0x02
|
ACPI_BUTTON_LID_INIT_OPEN,
|
||||||
|
ACPI_BUTTON_LID_INIT_METHOD,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char * const lid_init_state_str[] = {
|
||||||
|
[ACPI_BUTTON_LID_INIT_IGNORE] = "ignore",
|
||||||
|
[ACPI_BUTTON_LID_INIT_OPEN] = "open",
|
||||||
|
[ACPI_BUTTON_LID_INIT_METHOD] = "method",
|
||||||
|
};
|
||||||
|
|
||||||
#define _COMPONENT ACPI_BUTTON_COMPONENT
|
#define _COMPONENT ACPI_BUTTON_COMPONENT
|
||||||
ACPI_MODULE_NAME("button");
|
ACPI_MODULE_NAME("button");
|
||||||
@ -578,36 +586,30 @@ static int acpi_button_remove(struct acpi_device *device)
|
|||||||
static int param_set_lid_init_state(const char *val,
|
static int param_set_lid_init_state(const char *val,
|
||||||
const struct kernel_param *kp)
|
const struct kernel_param *kp)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int i;
|
||||||
|
|
||||||
if (!strncmp(val, "open", sizeof("open") - 1)) {
|
i = sysfs_match_string(lid_init_state_str, val);
|
||||||
lid_init_state = ACPI_BUTTON_LID_INIT_OPEN;
|
if (i < 0)
|
||||||
pr_info("Notify initial lid state as open\n");
|
return i;
|
||||||
} else if (!strncmp(val, "method", sizeof("method") - 1)) {
|
|
||||||
lid_init_state = ACPI_BUTTON_LID_INIT_METHOD;
|
lid_init_state = i;
|
||||||
pr_info("Notify initial lid state with _LID return value\n");
|
pr_info("Initial lid state set to '%s'\n", lid_init_state_str[i]);
|
||||||
} else if (!strncmp(val, "ignore", sizeof("ignore") - 1)) {
|
return 0;
|
||||||
lid_init_state = ACPI_BUTTON_LID_INIT_IGNORE;
|
|
||||||
pr_info("Do not notify initial lid state\n");
|
|
||||||
} else
|
|
||||||
result = -EINVAL;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int param_get_lid_init_state(char *buffer,
|
static int param_get_lid_init_state(char *buf, const struct kernel_param *kp)
|
||||||
const struct kernel_param *kp)
|
|
||||||
{
|
{
|
||||||
switch (lid_init_state) {
|
int i, c = 0;
|
||||||
case ACPI_BUTTON_LID_INIT_OPEN:
|
|
||||||
return sprintf(buffer, "open");
|
for (i = 0; i < ARRAY_SIZE(lid_init_state_str); i++)
|
||||||
case ACPI_BUTTON_LID_INIT_METHOD:
|
if (i == lid_init_state)
|
||||||
return sprintf(buffer, "method");
|
c += sprintf(buf + c, "[%s] ", lid_init_state_str[i]);
|
||||||
case ACPI_BUTTON_LID_INIT_IGNORE:
|
else
|
||||||
return sprintf(buffer, "ignore");
|
c += sprintf(buf + c, "%s ", lid_init_state_str[i]);
|
||||||
default:
|
|
||||||
return sprintf(buffer, "invalid");
|
buf[c - 1] = '\n'; /* Replace the final space with a newline */
|
||||||
}
|
|
||||||
return 0;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
module_param_call(lid_init_state,
|
module_param_call(lid_init_state,
|
||||||
|
Loading…
Reference in New Issue
Block a user