Skip to content

Commit

Permalink
Get rid of strlcpy()
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Baldyga <[email protected]>
  • Loading branch information
robertbaldyga committed May 10, 2024
1 parent 7045c9b commit ab0d7d0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion modules/cas_cache/exp_obj.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/module.h>
Expand Down Expand Up @@ -476,7 +477,7 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,

gd->fops = &_cas_exp_obj_ops;
gd->private_data = dsk;
strlcpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name));
strscpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name));

cas_blk_queue_make_request(queue, _cas_exp_obj_make_rq_fn);

Expand Down
8 changes: 4 additions & 4 deletions modules/cas_cache/layer_cache_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ static void cache_mngt_probe_metadata_end(void *priv, int error,
goto err;
}

strlcpy(context->cache_name_meta, status->cache_name,
strscpy(context->cache_name_meta, status->cache_name,
OCF_CACHE_NAME_SIZE);
*(context->cache_mode_meta) = status->cache_mode;
*(context->cache_line_size_meta) = status->cache_line_size;
Expand Down Expand Up @@ -2487,7 +2487,7 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
}

result = 0;
strlcpy(cfg->name, cache_name_meta, OCF_CACHE_NAME_SIZE);
strscpy(cfg->name, cache_name_meta, OCF_CACHE_NAME_SIZE);
cfg->cache_mode = cache_mode_meta;
cfg->cache_line_size = cache_line_size_meta;
default:
Expand Down Expand Up @@ -3096,7 +3096,7 @@ int cache_mngt_get_info(struct kcas_cache_info *info)
if (info->info.attached && !info->info.standby_detached) {
uuid = ocf_cache_get_uuid(cache);
BUG_ON(!uuid);
strlcpy(info->cache_path_name, uuid->data,
strscpy(info->cache_path_name, uuid->data,
min(sizeof(info->cache_path_name), uuid->size));
} else {
memset(info->cache_path_name, 0, sizeof(info->cache_path_name));
Expand Down Expand Up @@ -3176,7 +3176,7 @@ int cache_mngt_get_core_info(struct kcas_core_info *info)
uuid = ocf_core_get_uuid(core);

if (uuid->data) {
strlcpy(info->core_path_name, uuid->data,
strscpy(info->core_path_name, uuid->data,
min(sizeof(info->core_path_name), uuid->size));
}

Expand Down
3 changes: 2 additions & 1 deletion modules/cas_cache/ocf_env.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -597,7 +598,7 @@ static inline int env_bit_test(int nr, const void *addr)
#define env_strncmp(s1, slen1, s2, slen2) strncmp(s1, s2, \
min_t(size_t, slen1, slen2))
#define env_strncpy(dest, dmax, src, slen) ({ \
strlcpy(dest, src, min_t(int, dmax, slen)); \
strscpy(dest, src, min_t(int, dmax, slen)); \
0; \
})

Expand Down

0 comments on commit ab0d7d0

Please sign in to comment.