Skip to content

Commit 41a8457

Browse files
spandruvadarafaeljw
authored andcommitted
ACPI: DPTF: Fix reading of attributes
The current assumption that methods to read PCH FIVR attributes will return integer, is not correct. There is no good way to return integer as negative numbers are also valid. These read methods return a package of integers. The first integer returns status, which is 0 on success and any other value for failure. When the returned status is zero, then the second integer returns the actual value. This change fixes this issue by replacing acpi_evaluate_integer() with acpi_evaluate_object() and use acpi_extract_package() to extract results. Fixes: 2ce6324 ("ACPI: DPTF: Add PCH FIVR participant driver") Signed-off-by: Srinivas Pandruvada <[email protected]> Cc: 5.10+ <[email protected]> # 5.10+ Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ff11764 commit 41a8457

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

drivers/acpi/dptf/dptf_pch_fivr.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,42 @@
99
#include <linux/module.h>
1010
#include <linux/platform_device.h>
1111

12+
struct pch_fivr_resp {
13+
u64 status;
14+
u64 result;
15+
};
16+
17+
static int pch_fivr_read(acpi_handle handle, char *method, struct pch_fivr_resp *fivr_resp)
18+
{
19+
struct acpi_buffer resp = { sizeof(struct pch_fivr_resp), fivr_resp};
20+
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
21+
struct acpi_buffer format = { sizeof("NN"), "NN" };
22+
union acpi_object *obj;
23+
acpi_status status;
24+
int ret = -EFAULT;
25+
26+
status = acpi_evaluate_object(handle, method, NULL, &buffer);
27+
if (ACPI_FAILURE(status))
28+
return ret;
29+
30+
obj = buffer.pointer;
31+
if (!obj || obj->type != ACPI_TYPE_PACKAGE)
32+
goto release_buffer;
33+
34+
status = acpi_extract_package(obj, &format, &resp);
35+
if (ACPI_FAILURE(status))
36+
goto release_buffer;
37+
38+
if (fivr_resp->status)
39+
goto release_buffer;
40+
41+
ret = 0;
42+
43+
release_buffer:
44+
kfree(buffer.pointer);
45+
return ret;
46+
}
47+
1248
/*
1349
* Presentation of attributes which are defined for INT1045
1450
* They are:
@@ -23,15 +59,14 @@ static ssize_t name##_show(struct device *dev,\
2359
char *buf)\
2460
{\
2561
struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
26-
unsigned long long val;\
27-
acpi_status status;\
62+
struct pch_fivr_resp fivr_resp;\
63+
int status;\
2864
\
29-
status = acpi_evaluate_integer(acpi_dev->handle, #method,\
30-
NULL, &val);\
31-
if (ACPI_SUCCESS(status))\
32-
return sprintf(buf, "%d\n", (int)val);\
33-
else\
34-
return -EINVAL;\
65+
status = pch_fivr_read(acpi_dev->handle, #method, &fivr_resp);\
66+
if (status)\
67+
return status;\
68+
\
69+
return sprintf(buf, "%llu\n", fivr_resp.result);\
3570
}
3671

3772
#define PCH_FIVR_STORE(name, method) \

0 commit comments

Comments
 (0)