IB/hfi1: Replace deprecated strncpy
authorJustin Stitt <justinstitt@google.com>
Thu, 21 Sep 2023 07:17:47 +0000 (07:17 +0000)
committerLeon Romanovsky <leon@kernel.org>
Fri, 22 Sep 2023 10:28:54 +0000 (13:28 +0300)
commitc2d0c5b28a77d549ea52c70cb828e3ae29dda24d
treef89d3661468fdac941a9656f332693016f606c4f
parentf0cc82ca116f5b710bc298ea9bbbdb05bae01f5c
IB/hfi1: Replace deprecated strncpy

`strncpy` is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.

We see that `buf` is expected to be NUL-terminated based on it's use
within a trace event wherein `is_misc_err_name` and `is_various_name`
map to `is_name` through `is_table`:
| TRACE_EVENT(hfi1_interrupt,
|      TP_PROTO(struct hfi1_devdata *dd, const struct is_table *is_entry,
|       int src),
|      TP_ARGS(dd, is_entry, src),
|      TP_STRUCT__entry(DD_DEV_ENTRY(dd)
|       __array(char, buf, 64)
|       __field(int, src)
|       ),
|      TP_fast_assign(DD_DEV_ASSIGN(dd);
|     is_entry->is_name(__entry->buf, 64,
|       src - is_entry->start);
|     __entry->src = src;
|     ),
|      TP_printk("[%s] source: %s [%d]", __get_str(dev), __entry->buf,
|        __entry->src)
| );

Considering the above, a suitable replacement is `strscpy_pad` due to
the fact that it guarantees NUL-termination on the destination buffer
while maintaining the NUL-padding behavior that strncpy provides.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20230921-strncpy-drivers-infiniband-hw-hfi1-chip-c-v1-1-37afcf4964d9@google.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/infiniband/hw/hfi1/chip.c