[PATCH v1 4/8] ACPI: bus: Split _OSC error processing out of acpi_run_osc()

Rafael J. Wysocki posted 1 patch 1 month, 2 weeks ago
drivers/acpi/bus.c |   56 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 20 deletions(-)
[PATCH v1 4/8] ACPI: bus: Split _OSC error processing out of acpi_run_osc()
Posted by Rafael J. Wysocki 1 month, 2 weeks ago
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Split a function for processing _OSL errors called acpi_osc_error_check()
out of acpi_run_osc() to facilitate subsequent changes.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/bus.c |   56 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 20 deletions(-)

--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -236,13 +236,46 @@ static int acpi_eval_osc(acpi_handle han
 	return 0;
 }
 
+static bool acpi_osc_error_check(acpi_handle handle, guid_t *guid, int rev,
+				 struct acpi_buffer *cap, u32 *retbuf)
+{
+	/* Bit 0 in the query DWORD of the return buffer is reserved. */
+	u32 errors = retbuf[OSC_QUERY_DWORD] & OSC_ERROR_MASK;
+	u32 *capbuf = cap->pointer;
+
+	/*
+	 * If OSC_QUERY_ENABLE is set in the capabilities buffer, ignore bit 4.
+	 */
+	if (capbuf[OSC_QUERY_DWORD] & OSC_QUERY_ENABLE)
+		errors &= ~OSC_CAPABILITIES_MASK_ERROR;
+
+	if (!errors)
+		return false;
+
+	if (errors & OSC_REQUEST_ERROR)
+		acpi_handle_debug(handle, "_OSC: request failed\n");
+
+	if (errors & OSC_INVALID_UUID_ERROR)
+		acpi_handle_debug(handle, "_OSC: invalid UUID\n");
+
+	if (errors & OSC_INVALID_REVISION_ERROR)
+		acpi_handle_debug(handle, "_OSC: invalid revision\n");
+
+	if (errors & OSC_CAPABILITIES_MASK_ERROR)
+		acpi_handle_debug(handle, "_OSC: capability bits masked\n");
+
+	acpi_dump_osc_data(handle, guid, rev, cap);
+
+	return true;
+}
+
 acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
 {
 	union acpi_object in_params[4], *out_obj;
 	struct acpi_buffer output;
 	acpi_status status = AE_OK;
 	guid_t guid;
-	u32 errors;
+	u32 *retbuf;
 	int ret;
 
 	if (!context || !context->cap.pointer ||
@@ -256,26 +289,9 @@ acpi_status acpi_run_osc(acpi_handle han
 		return AE_ERROR;
 
 	out_obj = output.pointer;
-	/* Only take defined error bits into account. */
-	errors = *((u32 *)out_obj->buffer.pointer) & OSC_ERROR_MASK;
-	/* If OSC_QUERY_ENABLE is set, ignore the "capabilities masked" bit. */
-	if (((u32 *)context->cap.pointer)[OSC_QUERY_DWORD] & OSC_QUERY_ENABLE)
-		errors &= ~OSC_CAPABILITIES_MASK_ERROR;
-
-	if (errors) {
-		if (errors & OSC_REQUEST_ERROR)
-			acpi_handle_debug(handle, "_OSC request failed");
-
-		if (errors & OSC_INVALID_UUID_ERROR)
-			acpi_handle_debug(handle, "_OSC invalid UUID");
-
-		if (errors & OSC_INVALID_REVISION_ERROR)
-			acpi_handle_debug(handle, "_OSC invalid revision");
-
-		if (errors & OSC_CAPABILITIES_MASK_ERROR)
-			acpi_handle_debug(handle, "_OSC capability bits masked");
+	retbuf = (u32 *)out_obj->buffer.pointer;
 
-		acpi_dump_osc_data(handle, &guid, context->rev, &context->cap);
+	if (acpi_osc_error_check(handle, &guid, context->rev, &context->cap, retbuf)) {
 		status = AE_ERROR;
 		goto out_kfree;
 	}
Re: [PATCH v1 4/8] ACPI: bus: Split _OSC error processing out of acpi_run_osc()
Posted by Jonathan Cameron 1 month, 2 weeks ago
On Thu, 18 Dec 2025 21:36:57 +0100
"Rafael J. Wysocki" <rafael@kernel.org> wrote:

> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Split a function for processing _OSL errors called acpi_osc_error_check()
_OSC?
> out of acpi_run_osc() to facilitate subsequent changes.
> 
> No intentional functional impact.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Minor request inline. 
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> ---
>  drivers/acpi/bus.c |   56 ++++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 36 insertions(+), 20 deletions(-)
> 
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -236,13 +236,46 @@ static int acpi_eval_osc(acpi_handle han
>  	return 0;
>  }
>  
> +static bool acpi_osc_error_check(acpi_handle handle, guid_t *guid, int rev,
> +				 struct acpi_buffer *cap, u32 *retbuf)
> +{
> +	/* Bit 0 in the query DWORD of the return buffer is reserved. */
> +	u32 errors = retbuf[OSC_QUERY_DWORD] & OSC_ERROR_MASK;
> +	u32 *capbuf = cap->pointer;
> +
> +	/*
> +	 * If OSC_QUERY_ENABLE is set in the capabilities buffer, ignore bit 4.

Maybe add a tiny bit on why?

> +	 */
> +	if (capbuf[OSC_QUERY_DWORD] & OSC_QUERY_ENABLE)
> +		errors &= ~OSC_CAPABILITIES_MASK_ERROR;
> +
> +	if (!errors)
> +		return false;
> +
> +	if (errors & OSC_REQUEST_ERROR)
> +		acpi_handle_debug(handle, "_OSC: request failed\n");
> +
> +	if (errors & OSC_INVALID_UUID_ERROR)
> +		acpi_handle_debug(handle, "_OSC: invalid UUID\n");
> +
> +	if (errors & OSC_INVALID_REVISION_ERROR)
> +		acpi_handle_debug(handle, "_OSC: invalid revision\n");
> +
> +	if (errors & OSC_CAPABILITIES_MASK_ERROR)
> +		acpi_handle_debug(handle, "_OSC: capability bits masked\n");
> +
> +	acpi_dump_osc_data(handle, guid, rev, cap);
> +
> +	return true;
> +}

> 
>
Re: [PATCH v1 4/8] ACPI: bus: Split _OSC error processing out of acpi_run_osc()
Posted by Rafael J. Wysocki 1 month, 2 weeks ago
On Fri, Dec 19, 2025 at 1:46 PM Jonathan Cameron
<jonathan.cameron@huawei.com> wrote:
>
> On Thu, 18 Dec 2025 21:36:57 +0100
> "Rafael J. Wysocki" <rafael@kernel.org> wrote:
>
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > Split a function for processing _OSL errors called acpi_osc_error_check()
> _OSC?
> > out of acpi_run_osc() to facilitate subsequent changes.
> >
> > No intentional functional impact.
> >
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Minor request inline.
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
> > ---
> >  drivers/acpi/bus.c |   56 ++++++++++++++++++++++++++++++++++-------------------
> >  1 file changed, 36 insertions(+), 20 deletions(-)
> >
> > --- a/drivers/acpi/bus.c
> > +++ b/drivers/acpi/bus.c
> > @@ -236,13 +236,46 @@ static int acpi_eval_osc(acpi_handle han
> >       return 0;
> >  }
> >
> > +static bool acpi_osc_error_check(acpi_handle handle, guid_t *guid, int rev,
> > +                              struct acpi_buffer *cap, u32 *retbuf)
> > +{
> > +     /* Bit 0 in the query DWORD of the return buffer is reserved. */
> > +     u32 errors = retbuf[OSC_QUERY_DWORD] & OSC_ERROR_MASK;
> > +     u32 *capbuf = cap->pointer;
> > +
> > +     /*
> > +      * If OSC_QUERY_ENABLE is set in the capabilities buffer, ignore bit 4.
>
> Maybe add a tiny bit on why?

OK, I'll expand the comment.