Skip to content

Commit 10b49d0

Browse files
JustinStittSaeed Mahameed
authored andcommitted
net/mlx5: simplify mlx5_set_driver_version string assignments
In total, just assigning this version string takes: (1) strncpy()'s (5) strlen()'s (3) strncat()'s (1) snprintf()'s (4) max_t()'s Moreover, `strncpy` is deprecated [1] and `strncat` really shouldn't be used either [2]. With this in mind, let's simply use a single `snprintf`. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://elixir.bootlin.com/linux/v6.6-rc5/source/include/linux/fortify-string.h#L448 [2] Link: KSPP#90 Cc: [email protected] Cc: Kees Cook <[email protected]> Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 9454e56 commit 10b49d0

File tree

1 file changed

+3
-17
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+3
-17
lines changed

drivers/net/ethernet/mellanox/mlx5/core/main.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,30 +219,16 @@ static void mlx5_set_driver_version(struct mlx5_core_dev *dev)
219219
int driver_ver_sz = MLX5_FLD_SZ_BYTES(set_driver_version_in,
220220
driver_version);
221221
u8 in[MLX5_ST_SZ_BYTES(set_driver_version_in)] = {};
222-
int remaining_size = driver_ver_sz;
223222
char *string;
224223

225224
if (!MLX5_CAP_GEN(dev, driver_version))
226225
return;
227226

228227
string = MLX5_ADDR_OF(set_driver_version_in, in, driver_version);
229228

230-
strncpy(string, "Linux", remaining_size);
231-
232-
remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
233-
strncat(string, ",", remaining_size);
234-
235-
remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
236-
strncat(string, KBUILD_MODNAME, remaining_size);
237-
238-
remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
239-
strncat(string, ",", remaining_size);
240-
241-
remaining_size = max_t(int, 0, driver_ver_sz - strlen(string));
242-
243-
snprintf(string + strlen(string), remaining_size, "%u.%u.%u",
244-
LINUX_VERSION_MAJOR, LINUX_VERSION_PATCHLEVEL,
245-
LINUX_VERSION_SUBLEVEL);
229+
snprintf(string, driver_ver_sz, "Linux,%s,%u.%u.%u",
230+
KBUILD_MODNAME, LINUX_VERSION_MAJOR,
231+
LINUX_VERSION_PATCHLEVEL, LINUX_VERSION_SUBLEVEL);
246232

247233
/*Send the command*/
248234
MLX5_SET(set_driver_version_in, in, opcode,

0 commit comments

Comments
 (0)