Skip to content

Commit b398eee

Browse files
committed
ACPI: button: Clean up adding and removing lid procfs interface
The procfs interface is only used with lid devices which only becomes clear after looking into the function bodies of acpi_button_add_fs() and acpi_button_remove_fs(). Moreover, the only error code returned by the former of these functions is -ENODEV, so the ret local variable in it is redundant, and the return type of the latter one can be changed to void. Accordingly, rename these functions to acpi_button_add_fs() and acpi_button_remove_fs(), respectively, move the button->type checks against ACPI_BUTTON_TYPE_LID from them to their callers, and make code simplifications as per the above. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/1869050.VLH7GnMWUR@rafael.j.wysocki
1 parent a99d758 commit b398eee

1 file changed

Lines changed: 20 additions & 34 deletions

File tree

drivers/acpi/button.c

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,10 @@ static int __maybe_unused acpi_button_state_seq_show(struct seq_file *seq,
292292
return 0;
293293
}
294294

295-
static int acpi_button_add_fs(struct acpi_button *button)
295+
static int acpi_lid_add_fs(struct acpi_button *button)
296296
{
297297
struct acpi_device *device = button->adev;
298298
struct proc_dir_entry *entry = NULL;
299-
int ret = 0;
300-
301-
/* procfs I/F for ACPI lid device only */
302-
if (button->type != ACPI_BUTTON_TYPE_LID)
303-
return 0;
304299

305300
if (acpi_button_dir || acpi_lid_dir) {
306301
pr_info("More than one Lid device found!\n");
@@ -314,50 +309,39 @@ static int acpi_button_add_fs(struct acpi_button *button)
314309

315310
/* create /proc/acpi/button/lid */
316311
acpi_lid_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
317-
if (!acpi_lid_dir) {
318-
ret = -ENODEV;
312+
if (!acpi_lid_dir)
319313
goto remove_button_dir;
320-
}
321314

322315
/* create /proc/acpi/button/lid/LID/ */
323316
acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), acpi_lid_dir);
324-
if (!acpi_device_dir(device)) {
325-
ret = -ENODEV;
317+
if (!acpi_device_dir(device))
326318
goto remove_lid_dir;
327-
}
328319

329320
/* create /proc/acpi/button/lid/LID/state */
330321
entry = proc_create_single_data(ACPI_BUTTON_FILE_STATE, S_IRUGO,
331322
acpi_device_dir(device), acpi_button_state_seq_show,
332323
button);
333-
if (!entry) {
334-
ret = -ENODEV;
324+
if (!entry)
335325
goto remove_dev_dir;
336-
}
337326

338-
done:
339-
return ret;
327+
return 0;
340328

341329
remove_dev_dir:
342-
remove_proc_entry(acpi_device_bid(device),
343-
acpi_lid_dir);
330+
remove_proc_entry(acpi_device_bid(device), acpi_lid_dir);
344331
acpi_device_dir(device) = NULL;
345332
remove_lid_dir:
346333
remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
347334
acpi_lid_dir = NULL;
348335
remove_button_dir:
349336
remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
350337
acpi_button_dir = NULL;
351-
goto done;
338+
return -ENODEV;
352339
}
353340

354-
static int acpi_button_remove_fs(struct acpi_button *button)
341+
static void acpi_lid_remove_fs(struct acpi_button *button)
355342
{
356343
struct acpi_device *device = button->adev;
357344

358-
if (button->type != ACPI_BUTTON_TYPE_LID)
359-
return 0;
360-
361345
remove_proc_entry(ACPI_BUTTON_FILE_STATE,
362346
acpi_device_dir(device));
363347
remove_proc_entry(acpi_device_bid(device),
@@ -367,8 +351,6 @@ static int acpi_button_remove_fs(struct acpi_button *button)
367351
acpi_lid_dir = NULL;
368352
remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
369353
acpi_button_dir = NULL;
370-
371-
return 0;
372354
}
373355

374356
static acpi_handle saved_lid_handle;
@@ -588,6 +570,12 @@ static int acpi_button_probe(struct platform_device *pdev)
588570
handler = acpi_lid_notify;
589571
sprintf(class, "%s/%s",
590572
ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
573+
574+
error = acpi_lid_add_fs(button);
575+
if (error) {
576+
input_free_device(input);
577+
goto err_free_button;
578+
}
591579
break;
592580

593581
case ACPI_BUTTON_TYPE_POWER:
@@ -615,12 +603,6 @@ static int acpi_button_probe(struct platform_device *pdev)
615603
goto err_free_button;
616604
}
617605

618-
error = acpi_button_add_fs(button);
619-
if (error) {
620-
input_free_device(input);
621-
goto err_free_button;
622-
}
623-
624606
snprintf(button->phys, sizeof(button->phys), "%s/button/input0",
625607
acpi_device_hid(device));
626608

@@ -690,7 +672,9 @@ static int acpi_button_probe(struct platform_device *pdev)
690672
device_init_wakeup(button->dev, false);
691673
input_unregister_device(input);
692674
err_remove_fs:
693-
acpi_button_remove_fs(button);
675+
if (button_type == ACPI_BUTTON_TYPE_LID)
676+
acpi_lid_remove_fs(button);
677+
694678
err_free_button:
695679
kfree(button);
696680
memset(acpi_device_class(device), 0, sizeof(acpi_device_class));
@@ -731,8 +715,10 @@ static void acpi_button_remove(struct platform_device *pdev)
731715

732716
device_init_wakeup(button->dev, false);
733717

734-
acpi_button_remove_fs(button);
735718
input_unregister_device(button->input);
719+
if (button->type == ACPI_BUTTON_TYPE_LID)
720+
acpi_lid_remove_fs(button);
721+
736722
kfree(button);
737723

738724
memset(acpi_device_class(adev), 0, sizeof(acpi_device_class));

0 commit comments

Comments
 (0)