platform/x86: hp-bioscfg: consolidate common package-element parsing
Subsystems (2)
PATCH 1/1 platform/x86: hp-bioscfg: consolidate common package-element parsing
hp_populate_string_elements_from_package(), hp_populate_integer_elements_from_package(), hp_populate_enumeration_elements_from_package(), hp_populate_ordered_list_elements_from_package(), and hp_populate_password_elements_from_package() each parse the same PATH..SECURITY_LEVEL range into their own struct common_data sub-object, copy-pasted five times. Factor it into hp_get_common_data_from_package(), called from all five, mirroring hp_get_common_data_from_buffer()'s existing split for the buffer side.
The five PREREQUISITES loops weren't identical: on a bad prerequisite string, string/integer/ordered_list continue, enumeration returns -EINVAL, password breaks. The shared helper continues, matching the majority and hp_get_common_data_from_buffer()'s own handling of the equivalent failure. This changes enumeration (no longer aborts the package) and password (no longer leaves later prerequisites unfilled).
The expected_*_types[eloc] != obj[elem].type check above this switch has the same split -- enumeration warns and continues, the rest pr_err() and return -EIO -- left alone here; consolidating it needs each type's expected_*_types[] table passed into a shared checker, not just struct common_data.
--- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 97 +++++++++++++++++++ drivers/platform/x86/hp/hp-bioscfg/bioscfg.h | 3 + .../x86/hp/hp-bioscfg/enum-attributes.c | 57 +---------- .../x86/hp/hp-bioscfg/int-attributes.c | 57 +---------- .../x86/hp/hp-bioscfg/order-list-attributes.c | 58 +---------- .../x86/hp/hp-bioscfg/passwdobj-attributes.c | 57 +---------- .../x86/hp/hp-bioscfg/string-attributes.c | 58 +---------- 7 files changed, 125 insertions(+), 262 deletions(-)
drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +97 -0
@@ -484,6 +484,103 @@ int hp_convert_hexstr_to_str(const char *input, u32 input_len, char **str, int *return ret; } +/** +* hp_get_common_data_from_package() - Parse the package elements shared +* by every attribute type (PATH..SECURITY_LEVEL) +* @obj: ACPI object package for this attribute instance +* @obj_count: Number of elements in @obj +* @elem: Current position in @obj; advanced in place when PREREQUISITES +* consumes additional array elements +* @eloc: Current common-element locator; advanced in place when +* PREREQUISITES_SIZE is zero, since PREREQUISITES is then omitted +* by BIOS +* @int_value: Integer value already decoded by the caller for *@eloc, +* when applicable +* @str_value: String value already decoded by the caller for *@eloc, when +* applicable; reused and reset to NULL while walking +* PREREQUISITES, same as the caller does with its own copy +* @common: Destination common_data struct for this attribute instance +* +* Called by each type's own hp_populate_*_elements_from_package() +* instead of duplicating this parsing per type, since every BIOS +* attribute package uses the same layout for these elements (see +* struct common_data). +* +* Return: 0 on success, or -EINVAL if @obj is too small for the +* declared PREREQUISITES_SIZE. +*/ +int hp_get_common_data_from_package (union acpi_object *obj,int obj_count, +int *elem,int *eloc,u32 int_value, +char **str_value,struct common_data *common) +{ +int value_len; +int reqs; +int size; + +switch (*eloc) { +case PATH : +strscpy (common->path, *str_value); +break ; +case IS_READONLY : + common->is_readonly = int_value; +break ; +case DISPLAY_IN_UI : + common->display_in_ui = int_value; +break ; +case REQUIRES_PHYSICAL_PRESENCE : + common->requires_physical_presence = int_value; +break ; +case SEQUENCE : + common->sequence = int_value; +break ; +case PREREQUISITES_SIZE : +if (int_value >MAX_PREREQUISITES_SIZE ) { +pr_warn ("Prerequisites size value exceeded the maximum number of elements supported or data may be malformed\n" ); + int_value =MAX_PREREQUISITES_SIZE ; + } + common->prerequisites_size = int_value; + +/* +* This step is needed to keep the expected +* element list pointing to the right obj[elem].type +* when the size is zero. PREREQUISITES +* object is omitted by BIOS when the size is +* zero. +*/ +if (common->prerequisites_size ==0 ) + (*eloc)++; +break ; +case PREREQUISITES : + size =min_t (u32, common->prerequisites_size,MAX_PREREQUISITES_SIZE ); + +for (reqs =0 ; reqs < size; reqs++) { +if (*elem + reqs >= obj_count) { +pr_err ("Error elem-objects package is too small\n" ); +return -EINVAL ; + } + +if (hp_convert_hexstr_to_str (obj[*elem + reqs].string.pointer, + obj[*elem + reqs].string.length, + str_value, &value_len)) +continue ; + +strscpy (common->prerequisites[reqs], *str_value); +kfree (*str_value); + *str_value =NULL ; + } +if (size) + *elem += size -1 ; +break ; +case SECURITY_LEVEL : + common->security_level = int_value; +break ; +default : +break ; + } + +return 0 ; +} +/* map output size to the corresponding WMI method id */ int hp_encode_outsize_for_pvsz (int outsize) {
drivers/platform/x86/hp/hp-bioscfg/bioscfg.h +3 -0
@@ -493,5 +493,8 @@ void hp_friendly_user_name_update(char *path, const char *attr_name, char *attr_display, int attr_size);int hp_wmi_error_and_message (int error_code);int hp_get_common_data_from_buffer (u8 **buffer_ptr,u32 *buffer_size,struct common_data *common); +int hp_get_common_data_from_package (union acpi_object *obj,int obj_count, +int *elem,int *eloc,u32 int_value, +char **str_value,struct common_data *common);#endif
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c +5 -52
76 lines not on this page · raw message
drivers/platform/x86/hp/hp-bioscfg/int-attributes.c +5 -52
77 lines not on this page · raw message
drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c +5 -53
80 lines not on this page · raw message
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c +5 -52
76 lines not on this page · raw message
drivers/platform/x86/hp/hp-bioscfg/string-attributes.c +5 -53
78 lines not on this page · raw message
Signature · 1 line
2.55.0
Ilpo Järvinen
maintainerQuoted 11 lines · Muhammad Bilal
hp_populate_string_elements_from_package(),hp_populate_integer_elements_from_package(),hp_populate_enumeration_elements_from_package(),hp_populate_ordered_list_elements_from_package(), andhp_populate_password_elements_from_package()each parse the same PATH..SECURITY_LEVEL range into their own structcommon_datasub-object, copy-pasted five times. Factor it intohp_get_common_data_from_package(), called from all five, mirroring hp_get_common_data_from_buffer()'s existing split for the buffer side.
Quoted 1 line
[...]
Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.
FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.
The list of commits applied:
[1/1] platform/x86: hp-bioscfg: consolidate common package-element parsing
commit: 4de5dc3bf805e96b41081d8001aaa416e4e58d98
--
i.