]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
platform/x86: hp: hp-bioscfg: Use 2-argument strscpy()
authorAndy Shevchenko <andy.shevchenko@gmail.com>
Sun, 2 Jun 2024 08:57:55 +0000 (11:57 +0300)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 3 Jun 2024 11:51:36 +0000 (14:51 +0300)
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@gmail.com>
Link: https://lore.kernel.org/r/20240602090244.1666360-3-andy.shevchenko@gmail.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/hp/hp-bioscfg/enum-attributes.c
drivers/platform/x86/hp/hp-bioscfg/int-attributes.c
drivers/platform/x86/hp/hp-bioscfg/order-list-attributes.c
drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
drivers/platform/x86/hp/hp-bioscfg/spmobj-attributes.c
drivers/platform/x86/hp/hp-bioscfg/string-attributes.c

index a2402d31c14620b79f90f44caa11db839f9831db..c50ad58805038ecb7deb009740ca63b4ec35e2d1 100644 (file)
@@ -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;
index 86b7ac63fec20e0dbabbb53888516d03d165fc3e..6c7f4d5fa9cb9c1cdb2f10f32f0d2226216c1efd 100644 (file)
@@ -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;
                        }
index 1ff09dfb7d7e97e89d41d91197ac99254b695500..c6e57bb9d8b74d5ffa9c777c209a5b77102e024c 100644 (file)
@@ -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;
index f7efe217a4bb5e0807e752b74285c3f950ea3fb7..35936c05e45b9c45a455ca647a99c2b7c989232c 100644 (file)
@@ -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;
 
index 86f90238750c2f76d6ea11c12ae9b5001c766304..2b00a14792e9211d75342eb3d7f09db67a9e9893 100644 (file)
@@ -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;
index f0c20070094d4a0dd28134131ff08417a8261c39..27758b779b2d3ccb18445b508914e2f7d9a5fce3 100644 (file)
@@ -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;
                        }