scsi: lpfc: Replace strlcat() with scnprintf() in lpfc_vport_symbolic_node_name()

In preparation for removing the strlcat() API[1], replace its uses in
lpfc_vport_symbolic_node_name().

The function builds five unconditional fragments, so one scnprintf()
call composes the whole string. The intermediate tmp buffer and the per
fragment overflow checks become unnecessary. scnprintf() truncates at
the buffer size and returns the number of bytes it wrote, which equals
the length that the removed strnlen() call computed.

The old code capped every fragment at MAXHOSTNAMELEN bytes before
appending it, independently of the room left in the destination. The
replacement formats each fragment directly into the destination, so a
fragment longer than MAXHOSTNAMELEN is no longer truncated when the
destination has room for it.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Ian Bridges <icb@fastmail.org>
Link: https://patch.msgid.link/20260729144617.1388646-3-icb@fastmail.org
Reviewed-by: Nigel Kirkland <nigel.kirkland@broadcom.com>
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
This commit is contained in:
Ian Bridges 2026-07-29 09:46:14 -05:00 committed by Martin K. Petersen (Oracle)
parent 5a03dbfd67
commit 07f46a9f89

View File

@ -1823,34 +1823,15 @@ lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
size_t size)
{
char fwrev[FW_REV_STR_SIZE] = {0};
char tmp[MAXHOSTNAMELEN] = {0};
memset(symbol, 0, size);
scnprintf(tmp, sizeof(tmp), "Emulex %s", vport->phba->ModelName);
if (strlcat(symbol, tmp, size) >= size)
goto buffer_done;
lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
scnprintf(tmp, sizeof(tmp), " FV%s", fwrev);
if (strlcat(symbol, tmp, size) >= size)
goto buffer_done;
scnprintf(tmp, sizeof(tmp), " DV%s", lpfc_release_version);
if (strlcat(symbol, tmp, size) >= size)
goto buffer_done;
scnprintf(tmp, sizeof(tmp), " HN:%s", vport->phba->os_host_name);
if (strlcat(symbol, tmp, size) >= size)
goto buffer_done;
memset(symbol, 0, size);
/* Note :- OS name is "Linux" */
scnprintf(tmp, sizeof(tmp), " OS:%s", init_utsname()->sysname);
strlcat(symbol, tmp, size);
buffer_done:
return strnlen(symbol, size);
return scnprintf(symbol, size, "Emulex %s FV%s DV%s HN:%s OS:%s",
vport->phba->ModelName, fwrev,
lpfc_release_version, vport->phba->os_host_name,
init_utsname()->sysname);
}
static uint32_t