Skip to content

Commit 4ee7ffe

Browse files
arndbkeithbusch
authored andcommitted
nvmet: re-fix tracing strncpy() warning
An earlier patch had tried to address a warning about a string copy with missing zero termination: drivers/nvme/target/trace.h:52:3: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation] The new version causes a different warning with some compiler versions, notably gcc-9 and gcc-10, and also misses the zero padding that was apparently done intentionally in the original code: drivers/nvme/target/trace.h:56:2: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=] Change it to use strscpy_pad() with the original length, which will give a properly padded and zero-terminated string as well as avoiding the warning. Fixes: d86481e ("nvmet: use min of device_path and disk len") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent bafd590 commit 4ee7ffe

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/nvme/target/trace.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ static inline void __assign_req_name(char *name, struct nvmet_req *req)
5959
return;
6060
}
6161

62-
strncpy(name, req->ns->device_path,
63-
min_t(size_t, DISK_NAME_LEN, strlen(req->ns->device_path)));
62+
strscpy_pad(name, req->ns->device_path, DISK_NAME_LEN);
6463
}
6564
#endif
6665

0 commit comments

Comments
 (0)