Skip to content

Commit 29a241c

Browse files
acpibobrafaeljw
authored andcommitted
ACPICA: Add argument typechecking for all predefined ACPI names
Fully implements typechecking on all incoming arguments for all predefined names. This ensures that ACPI-related drivers are passing the correct number of arguments, each of the correct object type. Signed-off-by: Bob Moore <[email protected]> Signed-off-by: Lv Zheng <[email protected]> Acked-by: Len Brown <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent e1405ca commit 29a241c

21 files changed

+800
-476
lines changed

drivers/acpi/acpica/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ acpi-$(ACPI_FUTURE_USAGE) += hwtimer.o
8383
acpi-y += \
8484
nsaccess.o \
8585
nsalloc.o \
86+
nsarguments.o \
8687
nsconvert.o \
8788
nsdump.o \
8889
nseval.o \

drivers/acpi/acpica/aclocal.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -362,23 +362,6 @@ union acpi_predefined_info {
362362

363363
#pragma pack()
364364

365-
/* Data block used during object validation */
366-
367-
struct acpi_predefined_data {
368-
char *pathname;
369-
const union acpi_predefined_info *predefined;
370-
union acpi_operand_object *parent_package;
371-
struct acpi_namespace_node *node;
372-
u32 flags;
373-
u32 return_btype;
374-
u8 node_flags;
375-
};
376-
377-
/* Defines for Flags field above */
378-
379-
#define ACPI_OBJECT_REPAIRED 1
380-
#define ACPI_OBJECT_WRAPPED 2
381-
382365
/* Return object auto-repair info */
383366

384367
typedef acpi_status(*acpi_object_converter) (union acpi_operand_object

drivers/acpi/acpica/acnamesp.h

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223,30 +223,41 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info);
223223
void acpi_ns_exec_module_code_list(void);
224224

225225
/*
226-
* nspredef - Support for predefined/reserved names
226+
* nsarguments - Argument count/type checking for predefined/reserved names
227227
*/
228-
acpi_status
229-
acpi_ns_check_predefined_names(struct acpi_namespace_node *node,
230-
u32 user_param_count,
231-
acpi_status return_status,
232-
union acpi_operand_object **return_object);
228+
void
229+
acpi_ns_check_argument_count(char *pathname,
230+
struct acpi_namespace_node *node,
231+
u32 user_param_count,
232+
const union acpi_predefined_info *info);
233233

234234
void
235-
acpi_ns_check_parameter_count(char *pathname,
235+
acpi_ns_check_acpi_compliance(char *pathname,
236236
struct acpi_namespace_node *node,
237-
u32 user_param_count,
238-
const union acpi_predefined_info *info);
237+
const union acpi_predefined_info *predefined);
238+
239+
void acpi_ns_check_argument_types(struct acpi_evaluate_info *info);
240+
241+
/*
242+
* nspredef - Return value checking for predefined/reserved names
243+
*/
244+
acpi_status
245+
acpi_ns_check_return_value(struct acpi_namespace_node *node,
246+
struct acpi_evaluate_info *info,
247+
u32 user_param_count,
248+
acpi_status return_status,
249+
union acpi_operand_object **return_object);
239250

240251
acpi_status
241-
acpi_ns_check_object_type(struct acpi_predefined_data *data,
252+
acpi_ns_check_object_type(struct acpi_evaluate_info *info,
242253
union acpi_operand_object **return_object_ptr,
243254
u32 expected_btypes, u32 package_index);
244255

245256
/*
246257
* nsprepkg - Validation of predefined name packages
247258
*/
248259
acpi_status
249-
acpi_ns_check_package(struct acpi_predefined_data *data,
260+
acpi_ns_check_package(struct acpi_evaluate_info *info,
250261
union acpi_operand_object **return_object_ptr);
251262

252263
/*
@@ -308,24 +319,24 @@ acpi_ns_get_attached_data(struct acpi_namespace_node *node,
308319
* predefined methods/objects
309320
*/
310321
acpi_status
311-
acpi_ns_simple_repair(struct acpi_predefined_data *data,
322+
acpi_ns_simple_repair(struct acpi_evaluate_info *info,
312323
u32 expected_btypes,
313324
u32 package_index,
314325
union acpi_operand_object **return_object_ptr);
315326

316327
acpi_status
317-
acpi_ns_wrap_with_package(struct acpi_predefined_data *data,
328+
acpi_ns_wrap_with_package(struct acpi_evaluate_info *info,
318329
union acpi_operand_object *original_object,
319330
union acpi_operand_object **obj_desc_ptr);
320331

321332
acpi_status
322-
acpi_ns_repair_null_element(struct acpi_predefined_data *data,
333+
acpi_ns_repair_null_element(struct acpi_evaluate_info *info,
323334
u32 expected_btypes,
324335
u32 package_index,
325336
union acpi_operand_object **return_object_ptr);
326337

327338
void
328-
acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
339+
acpi_ns_remove_null_elements(struct acpi_evaluate_info *info,
329340
u8 package_type,
330341
union acpi_operand_object *obj_desc);
331342

@@ -334,7 +345,7 @@ acpi_ns_remove_null_elements(struct acpi_predefined_data *data,
334345
* predefined methods/objects
335346
*/
336347
acpi_status
337-
acpi_ns_complex_repairs(struct acpi_predefined_data *data,
348+
acpi_ns_complex_repairs(struct acpi_evaluate_info *info,
338349
struct acpi_namespace_node *node,
339350
acpi_status validate_status,
340351
union acpi_operand_object **return_object_ptr);

drivers/acpi/acpica/acpredef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ enum acpi_return_package_types {
128128
#define ARG_COUNT_IS_MINIMUM 0x8000
129129
#define METHOD_MAX_ARG_TYPE ACPI_TYPE_PACKAGE
130130

131-
#define METHOD_GET_COUNT(arg_list) (arg_list & METHOD_ARG_MASK)
132-
#define METHOD_GET_NEXT_ARG(arg_list) (arg_list >> METHOD_ARG_BIT_WIDTH)
131+
#define METHOD_GET_ARG_COUNT(arg_list) ((arg_list) & METHOD_ARG_MASK)
132+
#define METHOD_GET_NEXT_TYPE(arg_list) (((arg_list) >>= METHOD_ARG_BIT_WIDTH) & METHOD_ARG_MASK)
133133

134134
/* Macros used to build the predefined info table */
135135

drivers/acpi/acpica/acstruct.h

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,41 @@ union acpi_aml_operands {
178178
};
179179

180180
/*
181-
* Structure used to pass object evaluation parameters.
181+
* Structure used to pass object evaluation information and parameters.
182182
* Purpose is to reduce CPU stack use.
183183
*/
184184
struct acpi_evaluate_info {
185-
struct acpi_namespace_node *prefix_node;
186-
char *pathname;
187-
union acpi_operand_object *obj_desc;
188-
union acpi_operand_object **parameters;
189-
struct acpi_namespace_node *resolved_node;
190-
union acpi_operand_object *return_object;
191-
u8 param_count;
192-
u8 pass_number;
193-
u8 return_object_type;
194-
u8 flags;
185+
/* The first 3 elements are passed by the caller to acpi_ns_evaluate */
186+
187+
struct acpi_namespace_node *prefix_node; /* Input: starting node */
188+
char *relative_pathname; /* Input: path relative to prefix_node */
189+
union acpi_operand_object **parameters; /* Input: argument list */
190+
191+
struct acpi_namespace_node *node; /* Resolved node (prefix_node:relative_pathname) */
192+
union acpi_operand_object *obj_desc; /* Object attached to the resolved node */
193+
char *full_pathname; /* Full pathname of the resolved node */
194+
195+
const union acpi_predefined_info *predefined; /* Used if Node is a predefined name */
196+
union acpi_operand_object *return_object; /* Object returned from the evaluation */
197+
union acpi_operand_object *parent_package; /* Used if return object is a Package */
198+
199+
u32 return_flags; /* Used for return value analysis */
200+
u32 return_btype; /* Bitmapped type of the returned object */
201+
u16 param_count; /* Count of the input argument list */
202+
u8 pass_number; /* Parser pass number */
203+
u8 return_object_type; /* Object type of the returned object */
204+
u8 node_flags; /* Same as Node->Flags */
205+
u8 flags; /* General flags */
195206
};
196207

197208
/* Values for Flags above */
198209

199-
#define ACPI_IGNORE_RETURN_VALUE 1
210+
#define ACPI_IGNORE_RETURN_VALUE 1
211+
212+
/* Defines for return_flags field above */
213+
214+
#define ACPI_OBJECT_REPAIRED 1
215+
#define ACPI_OBJECT_WRAPPED 2
200216

201217
/* Info used by acpi_ns_initialize_devices */
202218

drivers/acpi/acpica/evgpe.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
579579
(local_gpe_event_info->dispatch.
580580
method_node)));
581581
}
582-
583582
break;
584583

585584
default:

drivers/acpi/acpica/evregion.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
532532
}
533533

534534
info->prefix_node = region_obj2->extra.method_REG;
535-
info->pathname = NULL;
535+
info->relative_pathname = NULL;
536536
info->parameters = args;
537537
info->flags = ACPI_IGNORE_RETURN_VALUE;
538538

drivers/acpi/acpica/hwxface.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
495495
* Evaluate the \_Sx namespace object containing the register values
496496
* for this state
497497
*/
498-
info->pathname =
498+
info->relative_pathname =
499499
ACPI_CAST_PTR(char, acpi_gbl_sleep_state_names[sleep_state]);
500500
status = acpi_ns_evaluate(info);
501501
if (ACPI_FAILURE(status)) {
@@ -506,7 +506,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
506506

507507
if (!info->return_object) {
508508
ACPI_ERROR((AE_INFO, "No Sleep State object returned from [%s]",
509-
info->pathname));
509+
info->relative_pathname));
510510
status = AE_AML_NO_RETURN_VALUE;
511511
goto cleanup;
512512
}
@@ -565,7 +565,7 @@ acpi_get_sleep_type_data(u8 sleep_state, u8 *sleep_type_a, u8 *sleep_type_b)
565565
if (ACPI_FAILURE(status)) {
566566
ACPI_EXCEPTION((AE_INFO, status,
567567
"While evaluating Sleep State [%s]",
568-
info->pathname));
568+
info->relative_pathname));
569569
}
570570

571571
ACPI_FREE(info);

0 commit comments

Comments
 (0)