Skip to content

Commit 03fa9a3

Browse files
JustinStittrafaeljw
authored andcommitted
thermal: intel: int340x_thermal: replace deprecated strncpy() with strscpy()
strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. psvt->limit.string can only be 8 bytes so let's use the appropriate size macro ACPI_LIMIT_STR_MAX_LEN. Neither psvt->limit.string or psvt_user[i].limit.string requires the NUL-padding behavior that strncpy() provides as they have both been filled with NUL-bytes prior to the string operation. | memset(&psvt->limit, 0, sizeof(u64)); and | psvt_user = kzalloc(psvt_len, GFP_KERNEL); Let's use `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings # [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: KSPP#90 Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent b33f3d2 commit 03fa9a3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int acpi_parse_psvt(acpi_handle handle, int *psvt_count, struct psvt **ps
309309

310310
if (knob->type == ACPI_TYPE_STRING) {
311311
memset(&psvt->limit, 0, sizeof(u64));
312-
strncpy(psvt->limit.string, psvt_ptr->limit.str_ptr, knob->string.length);
312+
strscpy(psvt->limit.string, psvt_ptr->limit.str_ptr, ACPI_LIMIT_STR_MAX_LEN);
313313
} else {
314314
psvt->limit.integer = psvt_ptr->limit.integer;
315315
}
@@ -468,7 +468,7 @@ static int fill_psvt(char __user *ubuf)
468468
psvt_user[i].unlimit_coeff = psvts[i].unlimit_coeff;
469469
psvt_user[i].control_knob_type = psvts[i].control_knob_type;
470470
if (psvt_user[i].control_knob_type == ACPI_TYPE_STRING)
471-
strncpy(psvt_user[i].limit.string, psvts[i].limit.string,
471+
strscpy(psvt_user[i].limit.string, psvts[i].limit.string,
472472
ACPI_LIMIT_STR_MAX_LEN);
473473
else
474474
psvt_user[i].limit.integer = psvts[i].limit.integer;

0 commit comments

Comments
 (0)