Use 2-argument strscpy(), which is not only shorter but also provides an additional check that destination buffer is an array. Signed-off-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx> --- .../x86/hp/hp-bioscfg/enum-attributes.c | 18 +++++------------- .../x86/hp/hp-bioscfg/int-attributes.c | 7 ++----- .../x86/hp/hp-bioscfg/order-list-attributes.c | 18 +++++------------- .../x86/hp/hp-bioscfg/passwdobj-attributes.c | 19 +++++-------------- .../x86/hp/hp-bioscfg/spmobj-attributes.c | 3 +-- .../x86/hp/hp-bioscfg/string-attributes.c | 12 ++++-------- 6 files changed, 22 insertions(+), 55 deletions(-) diff --git a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c index a2402d31c146..c50ad5880503 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c +++ b/drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c @@ -52,9 +52,7 @@ static void update_enumeration_value(int instance_id, char *attr_value) { struct enumeration_data *enum_data = &bioscfg_drv.enumeration_data[instance_id]; - strscpy(enum_data->current_value, - attr_value, - sizeof(enum_data->current_value)); + strscpy(enum_data->current_value, attr_value); } ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, enumeration); @@ -174,8 +172,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum case VALUE: break; case PATH: - strscpy(enum_data->common.path, str_value, - sizeof(enum_data->common.path)); + strscpy(enum_data->common.path, str_value); break; case IS_READONLY: enum_data->common.is_readonly = int_value; @@ -222,9 +219,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum if (ret) return -EINVAL; - strscpy(enum_data->common.prerequisites[reqs], - str_value, - sizeof(enum_data->common.prerequisites[reqs])); + strscpy(enum_data->common.prerequisites[reqs], str_value); kfree(str_value); str_value = NULL; @@ -236,8 +231,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum break; case ENUM_CURRENT_VALUE: - strscpy(enum_data->current_value, - str_value, sizeof(enum_data->current_value)); + strscpy(enum_data->current_value, str_value); break; case ENUM_SIZE: if (int_value > MAX_VALUES_SIZE) { @@ -278,9 +272,7 @@ static int hp_populate_enumeration_elements_from_package(union acpi_object *enum * is greater than MAX_VALUES_SIZE */ if (size < MAX_VALUES_SIZE) - strscpy(enum_data->possible_values[pos_values], - str_value, - sizeof(enum_data->possible_values[pos_values])); + strscpy(enum_data->possible_values[pos_values], str_value); kfree(str_value); str_value = NULL; diff --git a/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c index 86b7ac63fec2..6c7f4d5fa9cb 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c +++ b/drivers/platform/x86/hp/hp-bioscfg/int-attributes.c @@ -192,8 +192,7 @@ static int hp_populate_integer_elements_from_package(union acpi_object *integer_ integer_data->current_value = int_value; break; case PATH: - strscpy(integer_data->common.path, str_value, - sizeof(integer_data->common.path)); + strscpy(integer_data->common.path, str_value); break; case IS_READONLY: integer_data->common.is_readonly = int_value; @@ -240,9 +239,7 @@ static int hp_populate_integer_elements_from_package(union acpi_object *integer_ if (ret) continue; - strscpy(integer_data->common.prerequisites[reqs], - str_value, - sizeof(integer_data->common.prerequisites[reqs])); + strscpy(integer_data->common.prerequisites[reqs], str_value); kfree(str_value); str_value = NULL; } diff --git a/drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c index 1ff09dfb7d7e..c6e57bb9d8b7 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c +++ b/drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c @@ -57,9 +57,7 @@ static void update_ordered_list_value(int instance, char *attr_value) { struct ordered_list_data *ordered_list_data = &bioscfg_drv.ordered_list_data[instance]; - strscpy(ordered_list_data->current_value, - attr_value, - sizeof(ordered_list_data->current_value)); + strscpy(ordered_list_data->current_value, attr_value); } ATTRIBUTE_S_COMMON_PROPERTY_SHOW(display_name, ordered_list); @@ -179,13 +177,11 @@ static int hp_populate_ordered_list_elements_from_package(union acpi_object *ord /* Assign appropriate element value to corresponding field*/ switch (eloc) { case VALUE: - strscpy(ordered_list_data->current_value, - str_value, sizeof(ordered_list_data->current_value)); + strscpy(ordered_list_data->current_value, str_value); replace_char_str(ordered_list_data->current_value, COMMA_SEP, SEMICOLON_SEP); break; case PATH: - strscpy(ordered_list_data->common.path, str_value, - sizeof(ordered_list_data->common.path)); + strscpy(ordered_list_data->common.path, str_value); break; case IS_READONLY: ordered_list_data->common.is_readonly = int_value; @@ -227,9 +223,7 @@ static int hp_populate_ordered_list_elements_from_package(union acpi_object *ord if (ret) continue; - strscpy(ordered_list_data->common.prerequisites[reqs], - str_value, - sizeof(ordered_list_data->common.prerequisites[reqs])); + strscpy(ordered_list_data->common.prerequisites[reqs], str_value); kfree(str_value); str_value = NULL; @@ -271,9 +265,7 @@ static int hp_populate_ordered_list_elements_from_package(union acpi_object *ord part = strsep(&part_tmp, COMMA_SEP); for (olist_elem = 0; olist_elem < MAX_ELEMENTS_SIZE && part; olist_elem++) { - strscpy(ordered_list_data->elements[olist_elem], - part, - sizeof(ordered_list_data->elements[olist_elem])); + strscpy(ordered_list_data->elements[olist_elem], part); part = strsep(&part_tmp, COMMA_SEP); } ordered_list_data->elements_size = olist_elem; diff --git a/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c index f7efe217a4bb..35936c05e45b 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c +++ b/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c @@ -101,13 +101,9 @@ static int store_password_instance(struct kobject *kobj, const char *buf, if (!ret) { if (is_current) - strscpy(bioscfg_drv.password_data[id].current_password, - buf_cp, - sizeof(bioscfg_drv.password_data[id].current_password)); + strscpy(bioscfg_drv.password_data[id].current_password, buf_cp); else - strscpy(bioscfg_drv.password_data[id].new_password, - buf_cp, - sizeof(bioscfg_drv.password_data[id].new_password)); + strscpy(bioscfg_drv.password_data[id].new_password, buf_cp); } kfree(buf_cp); @@ -272,8 +268,7 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor case VALUE: break; case PATH: - strscpy(password_data->common.path, str_value, - sizeof(password_data->common.path)); + strscpy(password_data->common.path, str_value); break; case IS_READONLY: password_data->common.is_readonly = int_value; @@ -315,9 +310,7 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor if (ret) break; - strscpy(password_data->common.prerequisites[reqs], - str_value, - sizeof(password_data->common.prerequisites[reqs])); + strscpy(password_data->common.prerequisites[reqs], str_value); kfree(str_value); str_value = NULL; @@ -359,9 +352,7 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor if (ret) break; - strscpy(password_data->encodings[pos_values], - str_value, - sizeof(password_data->encodings[pos_values])); + strscpy(password_data->encodings[pos_values], str_value); kfree(str_value); str_value = NULL; diff --git a/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c index 86f90238750c..2b00a14792e9 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c +++ b/drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c @@ -365,8 +365,7 @@ int hp_populate_secure_platform_data(struct kobject *attr_name_kobj) /* Populate data for Secure Platform Management */ bioscfg_drv.spm_data.attr_name_kobj = attr_name_kobj; - strscpy(bioscfg_drv.spm_data.attribute_name, SPM_STR, - sizeof(bioscfg_drv.spm_data.attribute_name)); + strscpy(bioscfg_drv.spm_data.attribute_name, SPM_STR); bioscfg_drv.spm_data.is_enabled = 0; bioscfg_drv.spm_data.mechanism = 0; diff --git a/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c index f0c20070094d..27758b779b2d 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c +++ b/drivers/platform/x86/hp/hp-bioscfg/string-attributes.c @@ -50,7 +50,7 @@ static void update_string_value(int instance_id, char *attr_value) struct string_data *string_data = &bioscfg_drv.string_data[instance_id]; /* Write settings to BIOS */ - strscpy(string_data->current_value, attr_value, sizeof(string_data->current_value)); + strscpy(string_data->current_value, attr_value); } /* @@ -178,12 +178,10 @@ static int hp_populate_string_elements_from_package(union acpi_object *string_ob /* Assign appropriate element value to corresponding field*/ switch (eloc) { case VALUE: - strscpy(string_data->current_value, - str_value, sizeof(string_data->current_value)); + strscpy(string_data->current_value, str_value); break; case PATH: - strscpy(string_data->common.path, str_value, - sizeof(string_data->common.path)); + strscpy(string_data->common.path, str_value); break; case IS_READONLY: string_data->common.is_readonly = int_value; @@ -231,9 +229,7 @@ static int hp_populate_string_elements_from_package(union acpi_object *string_ob if (ret) continue; - strscpy(string_data->common.prerequisites[reqs], - str_value, - sizeof(string_data->common.prerequisites[reqs])); + strscpy(string_data->common.prerequisites[reqs], str_value); kfree(str_value); str_value = NULL; } -- 2.45.1