diff options
author | Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> | 2021-02-10 06:47:59 +0100 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2021-02-10 16:38:05 +0100 |
commit | d86481e924a7d6e8a40477ffa98077c6c0d77ed5 (patch) | |
tree | 0308f2c649e3bdf44ca81f6ff5ff716aa9b1ae69 /drivers/nvme/target/trace.h | |
parent | nvmet: use invalid cmd opcode helper (diff) | |
download | linux-d86481e924a7d6e8a40477ffa98077c6c0d77ed5.tar.xz linux-d86481e924a7d6e8a40477ffa98077c6c0d77ed5.zip |
nvmet: use min of device_path and disk len
In function __assign_req_name() instead of using the DEVICE_NAME_LEN in
strncpy() use min of DISK_NAME_LEN and strlen(req->ns->device_path).
This is needed to turn off the following warnings:-
In file included from drivers/nvme/target/core.c:14:
In function ‘__assign_req_name’,
inlined from ‘trace_event_raw_event_nvmet_req_init’ at drivers/nvme/target/./trace.h:58:1:
drivers/nvme/target/trace.h:52:3: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
strncpy(name, req->ns->device_path, DISK_NAME_LEN);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘__assign_req_name’,
inlined from ‘perf_trace_nvmet_req_complete’ at drivers/nvme/target/./trace.h:100:1:
drivers/nvme/target/trace.h:52:3: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
strncpy(name, req->ns->device_path, DISK_NAME_LEN);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘__assign_req_name’,
inlined from ‘perf_trace_nvmet_req_init’ at drivers/nvme/target/./trace.h:58:1:
drivers/nvme/target/trace.h:52:3: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
strncpy(name, req->ns->device_path, DISK_NAME_LEN);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘__assign_req_name’,
inlined from ‘trace_event_raw_event_nvmet_req_complete’ at drivers/nvme/target/./trace.h:100:1:
drivers/nvme/target/trace.h:52:3: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
strncpy(name, req->ns->device_path, DISK_NAME_LEN);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/nvme/target/trace.h')
-rw-r--r-- | drivers/nvme/target/trace.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/drivers/nvme/target/trace.h b/drivers/nvme/target/trace.h index c14e3249a14d..6109b3806b12 100644 --- a/drivers/nvme/target/trace.h +++ b/drivers/nvme/target/trace.h @@ -48,10 +48,13 @@ static inline struct nvmet_ctrl *nvmet_req_to_ctrl(struct nvmet_req *req) static inline void __assign_req_name(char *name, struct nvmet_req *req) { - if (req->ns) - strncpy(name, req->ns->device_path, DISK_NAME_LEN); - else + if (!req->ns) { memset(name, 0, DISK_NAME_LEN); + return; + } + + strncpy(name, req->ns->device_path, + min_t(size_t, DISK_NAME_LEN, strlen(req->ns->device_path))); } #endif |