linux/include/trace/events/mdio.h
Justin Stitt 386f4a7379 trace: events: cleanup deprecated strncpy uses
strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.

For 2 out of 3 of these changes we can simply swap in strscpy() as it
guarantess NUL-termination which is needed for the following trace
print.

trace_rpcgss_context() should use memcpy as its format specifier %.*s
allows for the length to be specifier (__entry->len). Due to this,
acceptor does not technically need to be NUL-terminated. Moreover,
swapping in strscpy() and keeping everything else the same could result
in truncation of the source string by one byte. To remedy this, we could
use `len + 1` but I am unsure of the size of the destination buffer so a
simple memcpy should suffice.
|	TP_printk("win_size=%u expiry=%lu now=%lu timeout=%u acceptor=%.*s",
|		__entry->window_size, __entry->expiry, __entry->now,
|		__entry->timeout, __entry->len, __get_str(acceptor))

I suspect acceptor not to naturally be a NUL-terminated string due to
the presence of some stringify methods.
|	.crstringify_acceptor	= gss_stringify_acceptor,

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: https://github.com/KSPP/linux/issues/90
Signed-off-by: Justin Stitt <justinstitt@google.com>
Acked-by: Chuck Lever <chuck.lever@oracle.com>
Link: https://lore.kernel.org/r/20240401-strncpy-include-trace-events-mdio-h-v1-1-9cb5a4cda116@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-04-05 22:10:25 -07:00

44 lines
1.0 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM mdio
#if !defined(_TRACE_MDIO_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_MDIO_H
#include <linux/tracepoint.h>
TRACE_EVENT_CONDITION(mdio_access,
TP_PROTO(struct mii_bus *bus, char read,
u8 addr, unsigned regnum, u16 val, int err),
TP_ARGS(bus, read, addr, regnum, val, err),
TP_CONDITION(err >= 0),
TP_STRUCT__entry(
__array(char, busid, MII_BUS_ID_SIZE)
__field(char, read)
__field(u8, addr)
__field(u16, val)
__field(unsigned, regnum)
),
TP_fast_assign(
strscpy(__entry->busid, bus->id, MII_BUS_ID_SIZE);
__entry->read = read;
__entry->addr = addr;
__entry->regnum = regnum;
__entry->val = val;
),
TP_printk("%s %-5s phy:0x%02hhx reg:0x%02x val:0x%04hx",
__entry->busid, __entry->read ? "read" : "write",
__entry->addr, __entry->regnum, __entry->val)
);
#endif /* if !defined(_TRACE_MDIO_H) || defined(TRACE_HEADER_MULTI_READ) */
/* This part must be outside protection */
#include <trace/define_trace.h>