Skip to content

Commit ee7e226

Browse files
Lv Zhengrafaeljw
authored andcommitted
ACPI / button: Refactor functions to eliminate redundant code
(Correct a wrong macro usage.) This patch simplies the code by merging some redundant code. No functional changes. Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent c2dd420 commit ee7e226

File tree

1 file changed

+49
-42
lines changed

1 file changed

+49
-42
lines changed

drivers/acpi/button.c

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,52 @@ static struct acpi_device *lid_device;
113113
static struct proc_dir_entry *acpi_button_dir;
114114
static struct proc_dir_entry *acpi_lid_dir;
115115

116+
static int acpi_lid_evaluate_state(struct acpi_device *device)
117+
{
118+
unsigned long long lid_state;
119+
acpi_status status;
120+
121+
status = acpi_evaluate_integer(device->handle, "_LID", NULL, &lid_state);
122+
if (ACPI_FAILURE(status))
123+
return -ENODEV;
124+
125+
return lid_state ? 1 : 0;
126+
}
127+
128+
static int acpi_lid_notify_state(struct acpi_device *device, int state)
129+
{
130+
struct acpi_button *button = acpi_driver_data(device);
131+
int ret;
132+
133+
/* input layer checks if event is redundant */
134+
input_report_switch(button->input, SW_LID, !state);
135+
input_sync(button->input);
136+
137+
if (state)
138+
pm_wakeup_event(&device->dev, 0);
139+
140+
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
141+
if (ret == NOTIFY_DONE)
142+
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state,
143+
device);
144+
if (ret == NOTIFY_DONE || ret == NOTIFY_OK) {
145+
/*
146+
* It is also regarded as success if the notifier_chain
147+
* returns NOTIFY_OK or NOTIFY_DONE.
148+
*/
149+
ret = 0;
150+
}
151+
return ret;
152+
}
153+
116154
static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
117155
{
118156
struct acpi_device *device = seq->private;
119-
acpi_status status;
120-
unsigned long long state;
157+
int state;
121158

122-
status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state);
159+
state = acpi_lid_evaluate_state(device);
123160
seq_printf(seq, "state: %s\n",
124-
ACPI_FAILURE(status) ? "unsupported" :
125-
(state ? "open" : "closed"));
161+
state < 0 ? "unsupported" : (state ? "open" : "closed"));
126162
return 0;
127163
}
128164

@@ -231,51 +267,22 @@ EXPORT_SYMBOL(acpi_lid_notifier_unregister);
231267

232268
int acpi_lid_open(void)
233269
{
234-
acpi_status status;
235-
unsigned long long state;
236-
237270
if (!lid_device)
238271
return -ENODEV;
239272

240-
status = acpi_evaluate_integer(lid_device->handle, "_LID", NULL,
241-
&state);
242-
if (ACPI_FAILURE(status))
243-
return -ENODEV;
244-
245-
return !!state;
273+
return acpi_lid_evaluate_state(lid_device);
246274
}
247275
EXPORT_SYMBOL(acpi_lid_open);
248276

249-
static int acpi_lid_send_state(struct acpi_device *device)
277+
static int acpi_lid_update_state(struct acpi_device *device)
250278
{
251-
struct acpi_button *button = acpi_driver_data(device);
252-
unsigned long long state;
253-
acpi_status status;
254-
int ret;
255-
256-
status = acpi_evaluate_integer(device->handle, "_LID", NULL, &state);
257-
if (ACPI_FAILURE(status))
258-
return -ENODEV;
279+
int state;
259280

260-
/* input layer checks if event is redundant */
261-
input_report_switch(button->input, SW_LID, !state);
262-
input_sync(button->input);
281+
state = acpi_lid_evaluate_state(device);
282+
if (state < 0)
283+
return state;
263284

264-
if (state)
265-
pm_wakeup_event(&device->dev, 0);
266-
267-
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state, device);
268-
if (ret == NOTIFY_DONE)
269-
ret = blocking_notifier_call_chain(&acpi_lid_notifier, state,
270-
device);
271-
if (ret == NOTIFY_DONE || ret == NOTIFY_OK) {
272-
/*
273-
* It is also regarded as success if the notifier_chain
274-
* returns NOTIFY_OK or NOTIFY_DONE.
275-
*/
276-
ret = 0;
277-
}
278-
return ret;
285+
return acpi_lid_notify_state(device, state);
279286
}
280287

281288
static void acpi_button_notify(struct acpi_device *device, u32 event)
@@ -290,7 +297,7 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
290297
case ACPI_BUTTON_NOTIFY_STATUS:
291298
input = button->input;
292299
if (button->type == ACPI_BUTTON_TYPE_LID) {
293-
acpi_lid_send_state(device);
300+
acpi_lid_update_state(device);
294301
} else {
295302
int keycode;
296303

0 commit comments

Comments
 (0)