Skip to content

Commit f4cb34a

Browse files
committed
Merge branches 'acpi-ac', 'acpi-pad' and 'pnp'
Merge updates of the ACPI AC and ACPI PAD drivers and PNP updates for 6.7-rc1: - Switch over the ACPI AC and ACPI PAD drivers to using the platform driver interface which, is more logically consistent than binding a driver directly to an ACPI device object, and clean them up (Michal Wilczynski). - Replace strncpy() in the PNP code with either memcpy() or strscpy() as appropriate (Justin Stitt). - Clean up coding style in pnp.h (GuoHua Cheng). * acpi-ac: ACPI: AC: Rename ACPI device from device to adev ACPI: AC: Replace acpi_driver with platform_driver ACPI: AC: Use string_choices API instead of ternary operator ACPI: AC: Remove redundant checks * acpi-pad: ACPI: acpi_pad: Rename ACPI device from device to adev ACPI: acpi_pad: Use dev groups for sysfs ACPI: acpi_pad: Replace acpi_driver with platform_driver * pnp: PNP: replace deprecated strncpy() with memcpy() PNP: ACPI: replace deprecated strncpy() with strscpy() PNP: Clean up coding style in pnp.h
4 parents 3660e64 + c7b5937 + 5ccd40c + 50cbdaf commit f4cb34a

File tree

5 files changed

+80
-119
lines changed

5 files changed

+80
-119
lines changed

drivers/acpi/ac.c

Lines changed: 41 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/delay.h>
1818
#include <linux/platform_device.h>
1919
#include <linux/power_supply.h>
20+
#include <linux/string_choices.h>
2021
#include <linux/acpi.h>
2122
#include <acpi/battery.h>
2223

@@ -32,8 +33,9 @@ MODULE_AUTHOR("Paul Diefenbaugh");
3233
MODULE_DESCRIPTION("ACPI AC Adapter Driver");
3334
MODULE_LICENSE("GPL");
3435

35-
static int acpi_ac_add(struct acpi_device *device);
36-
static void acpi_ac_remove(struct acpi_device *device);
36+
static int acpi_ac_probe(struct platform_device *pdev);
37+
static void acpi_ac_remove(struct platform_device *pdev);
38+
3739
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data);
3840

3941
static const struct acpi_device_id ac_device_ids[] = {
@@ -50,17 +52,6 @@ static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
5052
static int ac_sleep_before_get_state_ms;
5153
static int ac_only;
5254

53-
static struct acpi_driver acpi_ac_driver = {
54-
.name = "ac",
55-
.class = ACPI_AC_CLASS,
56-
.ids = ac_device_ids,
57-
.ops = {
58-
.add = acpi_ac_add,
59-
.remove = acpi_ac_remove,
60-
},
61-
.drv.pm = &acpi_ac_pm,
62-
};
63-
6455
struct acpi_ac {
6556
struct power_supply *charger;
6657
struct power_supply_desc charger_desc;
@@ -128,15 +119,12 @@ static enum power_supply_property ac_props[] = {
128119
/* Driver Model */
129120
static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
130121
{
131-
struct acpi_device *device = data;
132-
struct acpi_ac *ac = acpi_driver_data(device);
133-
134-
if (!ac)
135-
return;
122+
struct acpi_ac *ac = data;
123+
struct acpi_device *adev = ac->device;
136124

137125
switch (event) {
138126
default:
139-
acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n",
127+
acpi_handle_debug(adev->handle, "Unsupported event [0x%x]\n",
140128
event);
141129
fallthrough;
142130
case ACPI_AC_NOTIFY_STATUS:
@@ -153,10 +141,10 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
153141
msleep(ac_sleep_before_get_state_ms);
154142

155143
acpi_ac_get_state(ac);
156-
acpi_bus_generate_netlink_event(device->pnp.device_class,
157-
dev_name(&device->dev), event,
144+
acpi_bus_generate_netlink_event(adev->pnp.device_class,
145+
dev_name(&adev->dev), event,
158146
(u32) ac->state);
159-
acpi_notifier_call_chain(device, event, (u32) ac->state);
147+
acpi_notifier_call_chain(adev, event, (u32) ac->state);
160148
kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
161149
}
162150
}
@@ -213,51 +201,49 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = {
213201
{},
214202
};
215203

216-
static int acpi_ac_add(struct acpi_device *device)
204+
static int acpi_ac_probe(struct platform_device *pdev)
217205
{
206+
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
218207
struct power_supply_config psy_cfg = {};
219-
int result = 0;
220-
struct acpi_ac *ac = NULL;
221-
222-
223-
if (!device)
224-
return -EINVAL;
208+
struct acpi_ac *ac;
209+
int result;
225210

226211
ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
227212
if (!ac)
228213
return -ENOMEM;
229214

230-
ac->device = device;
231-
strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
232-
strcpy(acpi_device_class(device), ACPI_AC_CLASS);
233-
device->driver_data = ac;
215+
ac->device = adev;
216+
strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
217+
strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
218+
219+
platform_set_drvdata(pdev, ac);
234220

235221
result = acpi_ac_get_state(ac);
236222
if (result)
237223
goto err_release_ac;
238224

239225
psy_cfg.drv_data = ac;
240226

241-
ac->charger_desc.name = acpi_device_bid(device);
227+
ac->charger_desc.name = acpi_device_bid(adev);
242228
ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;
243229
ac->charger_desc.properties = ac_props;
244230
ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
245231
ac->charger_desc.get_property = get_ac_property;
246-
ac->charger = power_supply_register(&ac->device->dev,
232+
ac->charger = power_supply_register(&pdev->dev,
247233
&ac->charger_desc, &psy_cfg);
248234
if (IS_ERR(ac->charger)) {
249235
result = PTR_ERR(ac->charger);
250236
goto err_release_ac;
251237
}
252238

253-
pr_info("%s [%s] (%s)\n", acpi_device_name(device),
254-
acpi_device_bid(device), ac->state ? "on-line" : "off-line");
239+
pr_info("%s [%s] (%s-line)\n", acpi_device_name(adev),
240+
acpi_device_bid(adev), str_on_off(ac->state));
255241

256242
ac->battery_nb.notifier_call = acpi_ac_battery_notify;
257243
register_acpi_notifier(&ac->battery_nb);
258244

259-
result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
260-
acpi_ac_notify, device);
245+
result = acpi_dev_install_notify_handler(adev, ACPI_ALL_NOTIFY,
246+
acpi_ac_notify, ac);
261247
if (result)
262248
goto err_unregister;
263249

@@ -275,16 +261,9 @@ static int acpi_ac_add(struct acpi_device *device)
275261
#ifdef CONFIG_PM_SLEEP
276262
static int acpi_ac_resume(struct device *dev)
277263
{
278-
struct acpi_ac *ac;
264+
struct acpi_ac *ac = dev_get_drvdata(dev);
279265
unsigned int old_state;
280266

281-
if (!dev)
282-
return -EINVAL;
283-
284-
ac = acpi_driver_data(to_acpi_device(dev));
285-
if (!ac)
286-
return -EINVAL;
287-
288267
old_state = ac->state;
289268
if (acpi_ac_get_state(ac))
290269
return 0;
@@ -297,23 +276,28 @@ static int acpi_ac_resume(struct device *dev)
297276
#define acpi_ac_resume NULL
298277
#endif
299278

300-
static void acpi_ac_remove(struct acpi_device *device)
279+
static void acpi_ac_remove(struct platform_device *pdev)
301280
{
302-
struct acpi_ac *ac = NULL;
281+
struct acpi_ac *ac = platform_get_drvdata(pdev);
303282

304-
if (!device || !acpi_driver_data(device))
305-
return;
306-
307-
ac = acpi_driver_data(device);
308-
309-
acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
283+
acpi_dev_remove_notify_handler(ac->device, ACPI_ALL_NOTIFY,
310284
acpi_ac_notify);
311285
power_supply_unregister(ac->charger);
312286
unregister_acpi_notifier(&ac->battery_nb);
313287

314288
kfree(ac);
315289
}
316290

291+
static struct platform_driver acpi_ac_driver = {
292+
.probe = acpi_ac_probe,
293+
.remove_new = acpi_ac_remove,
294+
.driver = {
295+
.name = "ac",
296+
.acpi_match_table = ac_device_ids,
297+
.pm = &acpi_ac_pm,
298+
},
299+
};
300+
317301
static int __init acpi_ac_init(void)
318302
{
319303
int result;
@@ -326,7 +310,7 @@ static int __init acpi_ac_init(void)
326310

327311
dmi_check_system(ac_dmi_table);
328312

329-
result = acpi_bus_register_driver(&acpi_ac_driver);
313+
result = platform_driver_register(&acpi_ac_driver);
330314
if (result < 0)
331315
return -ENODEV;
332316

@@ -335,7 +319,7 @@ static int __init acpi_ac_init(void)
335319

336320
static void __exit acpi_ac_exit(void)
337321
{
338-
acpi_bus_unregister_driver(&acpi_ac_driver);
322+
platform_driver_unregister(&acpi_ac_driver);
339323
}
340324
module_init(acpi_ac_init);
341325
module_exit(acpi_ac_exit);

drivers/acpi/acpi_pad.c

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/slab.h>
1919
#include <linux/acpi.h>
2020
#include <linux/perf_event.h>
21+
#include <linux/platform_device.h>
2122
#include <asm/mwait.h>
2223
#include <xen/xen.h>
2324

@@ -336,33 +337,14 @@ static ssize_t idlecpus_show(struct device *dev,
336337

337338
static DEVICE_ATTR_RW(idlecpus);
338339

339-
static int acpi_pad_add_sysfs(struct acpi_device *device)
340-
{
341-
int result;
342-
343-
result = device_create_file(&device->dev, &dev_attr_idlecpus);
344-
if (result)
345-
return -ENODEV;
346-
result = device_create_file(&device->dev, &dev_attr_idlepct);
347-
if (result) {
348-
device_remove_file(&device->dev, &dev_attr_idlecpus);
349-
return -ENODEV;
350-
}
351-
result = device_create_file(&device->dev, &dev_attr_rrtime);
352-
if (result) {
353-
device_remove_file(&device->dev, &dev_attr_idlecpus);
354-
device_remove_file(&device->dev, &dev_attr_idlepct);
355-
return -ENODEV;
356-
}
357-
return 0;
358-
}
340+
static struct attribute *acpi_pad_attrs[] = {
341+
&dev_attr_idlecpus.attr,
342+
&dev_attr_idlepct.attr,
343+
&dev_attr_rrtime.attr,
344+
NULL
345+
};
359346

360-
static void acpi_pad_remove_sysfs(struct acpi_device *device)
361-
{
362-
device_remove_file(&device->dev, &dev_attr_idlecpus);
363-
device_remove_file(&device->dev, &dev_attr_idlepct);
364-
device_remove_file(&device->dev, &dev_attr_rrtime);
365-
}
347+
ATTRIBUTE_GROUPS(acpi_pad);
366348

367349
/*
368350
* Query firmware how many CPUs should be idle
@@ -416,49 +398,47 @@ static void acpi_pad_handle_notify(acpi_handle handle)
416398
static void acpi_pad_notify(acpi_handle handle, u32 event,
417399
void *data)
418400
{
419-
struct acpi_device *device = data;
401+
struct acpi_device *adev = data;
420402

421403
switch (event) {
422404
case ACPI_PROCESSOR_AGGREGATOR_NOTIFY:
423405
acpi_pad_handle_notify(handle);
424-
acpi_bus_generate_netlink_event(device->pnp.device_class,
425-
dev_name(&device->dev), event, 0);
406+
acpi_bus_generate_netlink_event(adev->pnp.device_class,
407+
dev_name(&adev->dev), event, 0);
426408
break;
427409
default:
428410
pr_warn("Unsupported event [0x%x]\n", event);
429411
break;
430412
}
431413
}
432414

433-
static int acpi_pad_add(struct acpi_device *device)
415+
static int acpi_pad_probe(struct platform_device *pdev)
434416
{
417+
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
435418
acpi_status status;
436419

437-
strcpy(acpi_device_name(device), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
438-
strcpy(acpi_device_class(device), ACPI_PROCESSOR_AGGREGATOR_CLASS);
420+
strcpy(acpi_device_name(adev), ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME);
421+
strcpy(acpi_device_class(adev), ACPI_PROCESSOR_AGGREGATOR_CLASS);
439422

440-
if (acpi_pad_add_sysfs(device))
441-
return -ENODEV;
423+
status = acpi_install_notify_handler(adev->handle,
424+
ACPI_DEVICE_NOTIFY, acpi_pad_notify, adev);
442425

443-
status = acpi_install_notify_handler(device->handle,
444-
ACPI_DEVICE_NOTIFY, acpi_pad_notify, device);
445-
if (ACPI_FAILURE(status)) {
446-
acpi_pad_remove_sysfs(device);
426+
if (ACPI_FAILURE(status))
447427
return -ENODEV;
448-
}
449428

450429
return 0;
451430
}
452431

453-
static void acpi_pad_remove(struct acpi_device *device)
432+
static void acpi_pad_remove(struct platform_device *pdev)
454433
{
434+
struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
435+
455436
mutex_lock(&isolated_cpus_lock);
456437
acpi_pad_idle_cpus(0);
457438
mutex_unlock(&isolated_cpus_lock);
458439

459-
acpi_remove_notify_handler(device->handle,
440+
acpi_remove_notify_handler(adev->handle,
460441
ACPI_DEVICE_NOTIFY, acpi_pad_notify);
461-
acpi_pad_remove_sysfs(device);
462442
}
463443

464444
static const struct acpi_device_id pad_device_ids[] = {
@@ -467,13 +447,13 @@ static const struct acpi_device_id pad_device_ids[] = {
467447
};
468448
MODULE_DEVICE_TABLE(acpi, pad_device_ids);
469449

470-
static struct acpi_driver acpi_pad_driver = {
471-
.name = "processor_aggregator",
472-
.class = ACPI_PROCESSOR_AGGREGATOR_CLASS,
473-
.ids = pad_device_ids,
474-
.ops = {
475-
.add = acpi_pad_add,
476-
.remove = acpi_pad_remove,
450+
static struct platform_driver acpi_pad_driver = {
451+
.probe = acpi_pad_probe,
452+
.remove_new = acpi_pad_remove,
453+
.driver = {
454+
.dev_groups = acpi_pad_groups,
455+
.name = "processor_aggregator",
456+
.acpi_match_table = pad_device_ids,
477457
},
478458
};
479459

@@ -487,12 +467,12 @@ static int __init acpi_pad_init(void)
487467
if (power_saving_mwait_eax == 0)
488468
return -EINVAL;
489469

490-
return acpi_bus_register_driver(&acpi_pad_driver);
470+
return platform_driver_register(&acpi_pad_driver);
491471
}
492472

493473
static void __exit acpi_pad_exit(void)
494474
{
495-
acpi_bus_unregister_driver(&acpi_pad_driver);
475+
platform_driver_unregister(&acpi_pad_driver);
496476
}
497477

498478
module_init(acpi_pad_init);

drivers/pnp/pnpacpi/core.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,9 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
250250
dev->capabilities |= PNP_DISABLE;
251251

252252
if (strlen(acpi_device_name(device)))
253-
strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
253+
strscpy(dev->name, acpi_device_name(device), sizeof(dev->name));
254254
else
255-
strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
256-
257-
/* Handle possible string truncation */
258-
dev->name[sizeof(dev->name) - 1] = '\0';
255+
strscpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
259256

260257
if (dev->active)
261258
pnpacpi_parse_allocated_resource(dev);

drivers/pnp/pnpbios/rsparser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
454454
switch (tag) {
455455

456456
case LARGE_TAG_ANSISTR:
457-
strncpy(dev->name, p + 3,
458-
len >= PNP_NAME_LEN ? PNP_NAME_LEN - 2 : len);
457+
memcpy(dev->name, p + 3,
458+
len >= PNP_NAME_LEN ? PNP_NAME_LEN - 2 : len);
459459
dev->name[len >=
460460
PNP_NAME_LEN ? PNP_NAME_LEN - 1 : len] = '\0';
461461
break;

0 commit comments

Comments
 (0)