Skip to content

Commit 5642639

Browse files
JustinStittrodrigovivi
authored andcommitted
drm/i915: refactor deprecated strncpy
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. `ctx` is zero allocated and as such strncpy's NUL-padding behavior was strictly a performance hit which is now resolved. 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 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
1 parent afddcbe commit 5642639

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/gpu/drm/i915/gem/selftests/mock_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mock_context(struct drm_i915_private *i915,
3636
if (name) {
3737
struct i915_ppgtt *ppgtt;
3838

39-
strncpy(ctx->name, name, sizeof(ctx->name) - 1);
39+
strscpy(ctx->name, name, sizeof(ctx->name));
4040

4141
ppgtt = mock_ppgtt(i915, name);
4242
if (!ppgtt)

0 commit comments

Comments
 (0)