From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: "Hans de Goede" <hdegoede@redhat.com>,
"Andy Shevchenko" <andy.shevchenko@gmail.com>,
"Jorge Lopez" <jorge.lopez2@hp.com>,
"Li Zetao" <lizetao1@huawei.com>,
"Simon Trimmer" <simont@opensource.cirrus.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Mark Pearson" <mpearson-lenovo@squebb.ca>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org,
ibm-acpi-devel@lists.sourceforge.net,
linux-input@vger.kernel.org
Cc: Corentin Chary <corentin.chary@gmail.com>,
"Luke D. Jones" <luke@ljones.dev>,
Mark Pearson <markpearson@lenovo.com>,
Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Subject: [PATCH v1 2/7] platform/x86: hp: hp-bioscfg: Use 2-argument strscpy()
Date: Sun, 2 Jun 2024 11:57:55 +0300 [thread overview]
Message-ID: <20240602090244.1666360-3-andy.shevchenko@gmail.com> (raw)
In-Reply-To: <20240602090244.1666360-1-andy.shevchenko@gmail.com>
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>
---
.../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
next prev parent reply other threads:[~2024-06-02 9:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-02 8:57 [PATCH v1 0/7] platform/x86: Move to 2-argument strscpy() Andy Shevchenko
2024-06-02 8:57 ` [PATCH v1 1/7] platform/x86: asus-tf103c-dock: Use " Andy Shevchenko
2024-06-02 13:28 ` Hans de Goede
2024-06-02 8:57 ` Andy Shevchenko [this message]
2024-06-02 8:57 ` [PATCH v1 3/7] platform/x86: intel: chtwc_int33fe: " Andy Shevchenko
2024-06-02 8:57 ` [PATCH v1 4/7] platform/x86: serial-multi-instantiate: " Andy Shevchenko
2024-06-02 8:57 ` [PATCH v1 5/7] platform/x86: think-lmi: " Andy Shevchenko
2024-06-02 8:57 ` [PATCH v1 6/7] platform/x86: thinkpad_acpi: " Andy Shevchenko
2024-06-02 8:58 ` [PATCH v1 7/7] platform/x86: touchscreen_dmi: " Andy Shevchenko
2024-06-03 9:16 ` Hans de Goede
2024-06-03 11:54 ` [PATCH v1 0/7] platform/x86: Move to " Ilpo Järvinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240602090244.1666360-3-andy.shevchenko@gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=corentin.chary@gmail.com \
--cc=hdegoede@redhat.com \
--cc=hmh@hmh.eng.br \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jorge.lopez2@hp.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizetao1@huawei.com \
--cc=luke@ljones.dev \
--cc=markpearson@lenovo.com \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
--cc=simont@opensource.cirrus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).