Skip to content

Commit 97892d5

Browse files
committed
ACPI: driver: Do not set acpi_device_name() unnecessarily
ACPI drivers usually set acpi_device_name() for the given struct acpi_device to whatever they like, but that value is never used unless the driver itself uses it and, quite unfortunately, drivers neglect to clear it on remove. Some drivers use it for printing messages or initializing the names of subordinate devices, but it is better to use string literals for that, especially if the given one is used just once. To eliminate unnecessary overhead related to acpi_device_name() handling, rework multiple core ACPI device drivers to stop setting acpi_device_name() for struct acpi_device objects manipulated by them and use a string literal instead of it where applicable. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/10840483.nUPlyArG6x@rafael.j.wysocki
1 parent 6a8e793 commit 97892d5

15 files changed

Lines changed: 14 additions & 46 deletions

File tree

drivers/acpi/ac.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <acpi/battery.h>
2323

2424
#define ACPI_AC_CLASS "ac_adapter"
25-
#define ACPI_AC_DEVICE_NAME "AC Adapter"
2625
#define ACPI_AC_FILE_STATE "state"
2726
#define ACPI_AC_NOTIFY_STATUS 0x80
2827
#define ACPI_AC_STATUS_OFFLINE 0x00
@@ -203,7 +202,6 @@ static int acpi_ac_probe(struct platform_device *pdev)
203202
return -ENOMEM;
204203

205204
ac->device = adev;
206-
strscpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
207205
strscpy(acpi_device_class(adev), ACPI_AC_CLASS);
208206

209207
platform_set_drvdata(pdev, ac);
@@ -226,8 +224,8 @@ static int acpi_ac_probe(struct platform_device *pdev)
226224
goto err_release_ac;
227225
}
228226

229-
pr_info("%s [%s] (%s-line)\n", acpi_device_name(adev),
230-
acpi_device_bid(adev), str_on_off(ac->state));
227+
pr_info("AC Adapter [%s] (%s-line)\n", acpi_device_bid(adev),
228+
str_on_off(ac->state));
231229

232230
ac->battery_nb.notifier_call = acpi_ac_battery_notify;
233231
register_acpi_notifier(&ac->battery_nb);

drivers/acpi/acpi_memhotplug.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#define ACPI_MEMORY_DEVICE_CLASS "memory"
2222
#define ACPI_MEMORY_DEVICE_HID "PNP0C80"
23-
#define ACPI_MEMORY_DEVICE_NAME "Hotplug Mem Device"
2423

2524
static const struct acpi_device_id memory_device_ids[] = {
2625
{ACPI_MEMORY_DEVICE_HID, 0},
@@ -297,7 +296,6 @@ static int acpi_memory_device_add(struct acpi_device *device,
297296
INIT_LIST_HEAD(&mem_device->res_list);
298297
mem_device->device = device;
299298
mem_device->mgid = -1;
300-
sprintf(acpi_device_name(device), "%s", ACPI_MEMORY_DEVICE_NAME);
301299
sprintf(acpi_device_class(device), "%s", ACPI_MEMORY_DEVICE_CLASS);
302300
device->driver_data = mem_device;
303301

drivers/acpi/acpi_pad.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <xen/xen.h>
2525

2626
#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
27-
#define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
2827
#define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
2928

3029
#define ACPI_PROCESSOR_AGGREGATOR_STATUS_SUCCESS 0
@@ -427,7 +426,6 @@ static int acpi_pad_probe(struct platform_device *pdev)
427426
{
428427
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
429428

430-
strscpy(acpi_device_name(adev), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
431429
strscpy(acpi_device_class(adev), ACPI_PROCESSOR_AGGREGATOR_CLASS);
432430

433431
return acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,

drivers/acpi/acpi_processor.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ static int acpi_processor_add(struct acpi_device *device,
438438
}
439439

440440
pr->handle = device->handle;
441-
strscpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
442441
strscpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
443442
device->driver_data = pr;
444443

drivers/acpi/acpi_video.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
#include <linux/uaccess.h>
3131
#include <linux/string_choices.h>
3232

33-
#define ACPI_VIDEO_BUS_NAME "Video Bus"
34-
#define ACPI_VIDEO_DEVICE_NAME "Video Device"
35-
3633
#define MAX_NAME_LEN 20
3734

3835
MODULE_AUTHOR("Bruno Ducrot");
@@ -1144,7 +1141,6 @@ static int acpi_video_bus_get_one_device(struct acpi_device *device, void *arg)
11441141
return -ENOMEM;
11451142
}
11461143

1147-
strscpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
11481144
strscpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
11491145

11501146
data->device_id = device_id;
@@ -1882,7 +1878,7 @@ static int acpi_video_bus_add_notify_handler(struct acpi_video_bus *video,
18821878
snprintf(video->phys, sizeof(video->phys),
18831879
"%s/video/input0", acpi_device_hid(video->device));
18841880

1885-
input->name = acpi_device_name(video->device);
1881+
input->name = "Video Bus";
18861882
input->phys = video->phys;
18871883
input->id.bustype = BUS_HOST;
18881884
input->id.product = 0x06;
@@ -2019,7 +2015,6 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
20192015
auxiliary_set_drvdata(aux_dev, video);
20202016

20212017
video->device = device;
2022-
strscpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
20232018
strscpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
20242019
device->driver_data = video;
20252020

@@ -2041,11 +2036,10 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
20412036
*/
20422037
acpi_device_fix_up_power_children(device);
20432038

2044-
pr_info("%s [%s] (multi-head: %s rom: %s post: %s)\n",
2045-
ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2046-
str_yes_no(video->flags.multihead),
2047-
str_yes_no(video->flags.rom),
2048-
str_yes_no(video->flags.post));
2039+
pr_info("Video Device [%s] (multi-head: %s rom: %s post: %s)\n",
2040+
acpi_device_bid(device), str_yes_no(video->flags.multihead),
2041+
str_yes_no(video->flags.rom), str_yes_no(video->flags.post));
2042+
20492043
mutex_lock(&video_list_lock);
20502044
list_add_tail(&video->entry, &video_bus_head);
20512045
mutex_unlock(&video_list_lock);

drivers/acpi/battery.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#define ACPI_BATTERY_CAPACITY_VALID(capacity) \
3434
((capacity) != 0 && (capacity) != ACPI_BATTERY_VALUE_UNKNOWN)
3535

36-
#define ACPI_BATTERY_DEVICE_NAME "Battery"
37-
3836
/* Battery power unit: 0 means mW, 1 means mA */
3937
#define ACPI_BATTERY_POWER_UNIT_MA 1
4038

@@ -1229,7 +1227,6 @@ static int acpi_battery_probe(struct platform_device *pdev)
12291227
platform_set_drvdata(pdev, battery);
12301228

12311229
battery->device = device;
1232-
strscpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
12331230
strscpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
12341231

12351232
result = devm_mutex_init(&pdev->dev, &battery->update_lock);

drivers/acpi/button.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,27 +558,26 @@ static int acpi_button_probe(struct platform_device *pdev)
558558
goto err_free_button;
559559
}
560560

561-
name = acpi_device_name(device);
562561
class = acpi_device_class(device);
563562

564563
if (!strcmp(hid, ACPI_BUTTON_HID_POWER) ||
565564
!strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
566565
button->type = ACPI_BUTTON_TYPE_POWER;
567566
handler = acpi_button_notify;
568-
strscpy(name, ACPI_BUTTON_DEVICE_NAME_POWER, MAX_ACPI_DEVICE_NAME_LEN);
567+
name = ACPI_BUTTON_DEVICE_NAME_POWER;
569568
sprintf(class, "%s/%s",
570569
ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
571570
} else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) ||
572571
!strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) {
573572
button->type = ACPI_BUTTON_TYPE_SLEEP;
574573
handler = acpi_button_notify;
575-
strscpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP, MAX_ACPI_DEVICE_NAME_LEN);
574+
name = ACPI_BUTTON_DEVICE_NAME_SLEEP;
576575
sprintf(class, "%s/%s",
577576
ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
578577
} else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) {
579578
button->type = ACPI_BUTTON_TYPE_LID;
580579
handler = acpi_lid_notify;
581-
strscpy(name, ACPI_BUTTON_DEVICE_NAME_LID, MAX_ACPI_DEVICE_NAME_LEN);
580+
name = ACPI_BUTTON_DEVICE_NAME_LID;
582581
sprintf(class, "%s/%s",
583582
ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
584583
input->open = acpi_lid_input_open;

drivers/acpi/ec.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "internal.h"
3737

3838
#define ACPI_EC_CLASS "embedded_controller"
39-
#define ACPI_EC_DEVICE_NAME "Embedded Controller"
4039

4140
/* EC status register */
4241
#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
@@ -1681,7 +1680,6 @@ static int acpi_ec_probe(struct platform_device *pdev)
16811680
struct acpi_ec *ec;
16821681
int ret;
16831682

1684-
strscpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
16851683
strscpy(acpi_device_class(device), ACPI_EC_CLASS);
16861684

16871685
if (boot_ec && (boot_ec->handle == device->handle ||

drivers/acpi/pci_link.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "internal.h"
3131

3232
#define ACPI_PCI_LINK_CLASS "pci_irq_routing"
33-
#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
3433
#define ACPI_PCI_LINK_MAX_POSSIBLE 16
3534

3635
static int acpi_pci_link_add(struct acpi_device *device,
@@ -725,7 +724,6 @@ static int acpi_pci_link_add(struct acpi_device *device,
725724
return -ENOMEM;
726725

727726
link->device = device;
728-
strscpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
729727
strscpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
730728
device->driver_data = link;
731729

drivers/acpi/pci_root.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "internal.h"
2626

2727
#define ACPI_PCI_ROOT_CLASS "pci_bridge"
28-
#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
2928
static int acpi_pci_root_add(struct acpi_device *device,
3029
const struct acpi_device_id *not_used);
3130
static void acpi_pci_root_remove(struct acpi_device *device);
@@ -689,7 +688,6 @@ static int acpi_pci_root_add(struct acpi_device *device,
689688

690689
root->device = device;
691690
root->segment = segment & 0xFFFF;
692-
strscpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
693691
strscpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
694692
device->driver_data = root;
695693

@@ -698,9 +696,8 @@ static int acpi_pci_root_add(struct acpi_device *device,
698696
goto end;
699697
}
700698

701-
pr_info("%s [%s] (domain %04x %pR)\n",
702-
acpi_device_name(device), acpi_device_bid(device),
703-
root->segment, &root->secondary);
699+
pr_info("PCI Root Bridge [%s] (domain %04x %pR)\n",
700+
acpi_device_bid(device), root->segment, &root->secondary);
704701

705702
root->mcfg_addr = acpi_pci_root_get_mcfg_addr(handle);
706703

0 commit comments

Comments
 (0)