Skip to content

Commit 06a17f2

Browse files
committed
ACPI: bus: Adjust acpi_osc_handshake() parameter list
For the sake of interface cleanliness, it is better to avoid using ACPICA data types in the parameter lists of helper functions that don't belong to ACPICA, so adjust the parameter list of recently introduced acpi_osc_handshake() to take a capabilities buffer pointer and the size of the buffer (in u32 size units) as parameters directly instead of a struct acpi_buffer pointer. This is also somewhat more straightforward on the caller side because they won't need to create struct acpi_buffer objects themselves to pass them to the helper function and it guarantees that the size of the buffer in bytes will always be a multiple of 4 (the size of u32). Moreover, it addresses a premature cap pointer dereference and eliminates a sizeof(32) that should have been sizeof(u32) [1]. Fixes: e532288 ("ACPI: bus: Rework the handling of \_SB._OSC platform features") Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Closes: https://lore.kernel.org/linux-acpi/202512242052.W4GhDauV-lkp@intel.com/ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> [ rjw: Fixed typo under sizeof(), used ARRAY_SIZE() in two places ] Link: https://patch.msgid.link/12833187.O9o76ZdvQC@rafael.j.wysocki Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d9239fd commit 06a17f2

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

drivers/acpi/bus.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -326,31 +326,33 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
326326
EXPORT_SYMBOL(acpi_run_osc);
327327

328328
static int acpi_osc_handshake(acpi_handle handle, const char *uuid_str,
329-
int rev, struct acpi_buffer *cap)
329+
int rev, u32 *capbuf, size_t bufsize)
330330
{
331331
union acpi_object in_params[4], *out_obj;
332-
size_t bufsize = cap->length / sizeof(u32);
333332
struct acpi_object_list input;
333+
struct acpi_buffer cap = {
334+
.pointer = capbuf,
335+
.length = bufsize * sizeof(u32),
336+
};
334337
struct acpi_buffer output;
335-
u32 *capbuf, *retbuf, test;
338+
u32 *retbuf, test;
336339
guid_t guid;
337340
int ret, i;
338341

339-
if (!cap || cap->length < 2 * sizeof(32) || guid_parse(uuid_str, &guid))
342+
if (!capbuf || bufsize < 2 || guid_parse(uuid_str, &guid))
340343
return -EINVAL;
341344

342345
/* First evaluate _OSC with OSC_QUERY_ENABLE set. */
343-
capbuf = cap->pointer;
344346
capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
345347

346-
ret = acpi_eval_osc(handle, &guid, rev, cap, in_params, &output);
348+
ret = acpi_eval_osc(handle, &guid, rev, &cap, in_params, &output);
347349
if (ret)
348350
return ret;
349351

350352
out_obj = output.pointer;
351353
retbuf = (u32 *)out_obj->buffer.pointer;
352354

353-
if (acpi_osc_error_check(handle, &guid, rev, cap, retbuf)) {
355+
if (acpi_osc_error_check(handle, &guid, rev, &cap, retbuf)) {
354356
ret = -ENODATA;
355357
goto out;
356358
}
@@ -403,7 +405,7 @@ static int acpi_osc_handshake(acpi_handle handle, const char *uuid_str,
403405
*/
404406
acpi_handle_err(handle, "_OSC: errors while processing control request\n");
405407
acpi_handle_err(handle, "_OSC: some features may be missing\n");
406-
acpi_osc_error_check(handle, &guid, rev, cap, retbuf);
408+
acpi_osc_error_check(handle, &guid, rev, &cap, retbuf);
407409
}
408410

409411
out:
@@ -446,10 +448,6 @@ static void acpi_bus_osc_negotiate_platform_control(void)
446448
{
447449
static const u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
448450
u32 capbuf[2], feature_mask;
449-
struct acpi_buffer cap = {
450-
.pointer = capbuf,
451-
.length = sizeof(capbuf),
452-
};
453451
acpi_handle handle;
454452

455453
feature_mask = OSC_SB_PR3_SUPPORT | OSC_SB_HOTPLUG_OST_SUPPORT |
@@ -497,7 +495,7 @@ static void acpi_bus_osc_negotiate_platform_control(void)
497495

498496
acpi_handle_info(handle, "platform _OSC: OS support mask [%08x]\n", feature_mask);
499497

500-
if (acpi_osc_handshake(handle, sb_uuid_str, 1, &cap))
498+
if (acpi_osc_handshake(handle, sb_uuid_str, 1, capbuf, ARRAY_SIZE(capbuf)))
501499
return;
502500

503501
feature_mask = capbuf[OSC_SUPPORT_DWORD];
@@ -532,10 +530,6 @@ static void acpi_bus_osc_negotiate_usb_control(void)
532530
{
533531
static const u8 sb_usb_uuid_str[] = "23A0D13A-26AB-486C-9C5F-0FFA525A575A";
534532
u32 capbuf[3], control;
535-
struct acpi_buffer cap = {
536-
.pointer = capbuf,
537-
.length = sizeof(capbuf),
538-
};
539533
acpi_handle handle;
540534

541535
if (!osc_sb_native_usb4_support_confirmed)
@@ -550,7 +544,7 @@ static void acpi_bus_osc_negotiate_usb_control(void)
550544
capbuf[OSC_SUPPORT_DWORD] = 0;
551545
capbuf[OSC_CONTROL_DWORD] = control;
552546

553-
if (acpi_osc_handshake(handle, sb_usb_uuid_str, 1, &cap))
547+
if (acpi_osc_handshake(handle, sb_usb_uuid_str, 1, capbuf, ARRAY_SIZE(capbuf)))
554548
return;
555549

556550
osc_sb_native_usb4_control = capbuf[OSC_CONTROL_DWORD];

0 commit comments

Comments
 (0)