From d65a428f2d700355865ccc199b300f8cb08e8592 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 29 Mar 2024 22:43:48 +0100 Subject: [PATCH] device_id: use dm_strncpy Simplify code. --- lib/device/device_id.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/device/device_id.c b/lib/device/device_id.c index b4cefaa83..b39883c12 100644 --- a/lib/device/device_id.c +++ b/lib/device/device_id.c @@ -620,17 +620,13 @@ void free_wwids(struct dm_list *ids) struct dev_wwid *dev_add_wwid(char *id, int id_type, struct dm_list *ids) { struct dev_wwid *dw; - int len; if (!id_type) id_type = _wwid_type_num(id); - if (!(dw = zalloc(sizeof(struct dev_wwid)))) - return NULL; - len = strlen(id); - if (len >= DEV_WWID_SIZE) - len = DEV_WWID_SIZE - 1; - memcpy(dw->id, id, len); + if (!(dw = zalloc(sizeof(*dw)))) + return_NULL; + (void)dm_strncpy(dw->id, id, sizeof(dw->id)); dw->type = id_type; dm_list_add(ids, &dw->list); return dw;