scsi: bfa: Use snprintf() in bfa_fcs_fabric_psymb_init()

Similar to bfa_fcs_fabric_nsymb_init(), bfa_fcs_fabric_psymb_init() builds
the port symbolic name using strscpy() and a chain of seven or eight
strlcat() calls.

In preparation for removing the deprecated strlcat() API[1], replace the
chained strscpy() and strlcat() calls with a single snprintf() call.

An empty host_os_patch naturally contributes no characters through %s,
allowing both cases to be handled by the same snprintf() call. Since
snprintf() also NUL-terminates the destination, the explicit final NUL
assignment can be dropped.

Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: codemender-patching+linux@google.com
Assisted-by: LLM
Signed-off-by: Bill Wendling <morbo@google.com>
Signed-off-by: Mariia Nikitash <nikitash.mariiaw@gmail.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/20260928090031.712418-3-nikitash.mariiaw@gmail.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
This commit is contained in:
Bill Wendling 2026-09-28 02:00:30 -07:00 committed by Martin K. Petersen (Oracle)
parent 0a5b53c1e7
commit 6697e9f202

View File

@ -760,53 +760,16 @@ bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
/* Model name/number */
strscpy(port_cfg->sym_name.symname, model,
BFA_SYMNAME_MAXLEN);
strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
BFA_SYMNAME_MAXLEN);
/* Driver Version */
strlcat(port_cfg->sym_name.symname, driver_info->version,
BFA_SYMNAME_MAXLEN);
strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
BFA_SYMNAME_MAXLEN);
/* Host machine name */
strlcat(port_cfg->sym_name.symname,
driver_info->host_machine_name,
BFA_SYMNAME_MAXLEN);
strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
BFA_SYMNAME_MAXLEN);
/*
* Host OS Info :
* If OS Patch Info is not there, do not truncate any bytes from the
* OS name string and instead copy the entire OS info string (64 bytes).
*/
if (driver_info->host_os_patch[0] == '\0') {
strlcat(port_cfg->sym_name.symname,
driver_info->host_os_name,
BFA_SYMNAME_MAXLEN);
strlcat(port_cfg->sym_name.symname,
BFA_FCS_PORT_SYMBNAME_SEPARATOR,
BFA_SYMNAME_MAXLEN);
} else {
strlcat(port_cfg->sym_name.symname,
driver_info->host_os_name,
BFA_SYMNAME_MAXLEN);
strlcat(port_cfg->sym_name.symname,
BFA_FCS_PORT_SYMBNAME_SEPARATOR,
BFA_SYMNAME_MAXLEN);
/* Append host OS Patch Info */
strlcat(port_cfg->sym_name.symname,
driver_info->host_os_patch,
BFA_SYMNAME_MAXLEN);
}
/* null terminate */
port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
snprintf(port_cfg->sym_name.symname, BFA_SYMNAME_MAXLEN,
"%s" BFA_FCS_PORT_SYMBNAME_SEPARATOR
"%s" BFA_FCS_PORT_SYMBNAME_SEPARATOR
"%s" BFA_FCS_PORT_SYMBNAME_SEPARATOR
"%s" BFA_FCS_PORT_SYMBNAME_SEPARATOR
"%s",
model, driver_info->version,
driver_info->host_machine_name,
driver_info->host_os_name,
driver_info->host_os_patch);
}
/*