Commit ee639c71 authored by Sebastien Gougeaud's avatar Sebastien Gougeaud Committed by Thomas Leibovici
Browse files

admin: fix incomplete data copy

The correct implementation of the data copy should be done in the
previous patch, but was forgotten. This one also copies string contents.

Change-Id: I87c7670e110f2bd92e649b15f36e22a924fc3452
Signed-off-by: default avatarSebastien Gougeaud <>

Tested-by: default avatarJenkins s8open_nr <>
Reviewed-by: default avatarQuentin Bouget <>
Reviewed-by: default avatarThomas Leibovici <>
parent eafebcf1
......@@ -36,6 +36,7 @@
#include "pho_common.h"
#include "pho_dss.h"
#include "pho_srl_lrs.h"
#include "pho_type_utils.h"
enum pho_cfg_params_admin {
/* Actual admin parameters */
......@@ -229,7 +230,7 @@ static int _device_unlock(struct admin_handle *adm, struct pho_id *dev_ids,
pho_warn("Device '%s' is already unlocked", dev_ids[i].name);
dev_res->rsc.adm_status = PHO_RSC_ADM_ST_UNLOCKED;
memcpy(devices + i, dev_res, sizeof(*dev_res));
dev_info_cpy(devices + i, dev_res);
dss_res_free(dev_res, 1);
......@@ -251,6 +252,8 @@ static int _device_unlock(struct admin_handle *adm, struct pho_id *dev_ids,
dss_device_unlock(&adm->dss, devices, num_dev, adm->lock_owner);
for (i = 0; i < num_dev; ++i)
dev_info_free(devices + i, false);
return rc;
......@@ -52,6 +52,19 @@ static inline char *strdup_safe(const char *str)
return strdup(str);
void dev_info_cpy(struct dev_info *dev_dst, const struct dev_info *dev_src)
if (!dev_dst)
dev_dst-> = dev_src->;
dev_dst->rsc.model = strdup_safe(dev_src->rsc.model);
dev_dst->rsc.adm_status = dev_src->rsc.adm_status;
dev_dst->path = strdup_safe(dev_src->path);
dev_dst->host = strdup_safe(dev_src->host);
struct dev_info *dev_info_dup(const struct dev_info *dev)
struct dev_info *dev_out;
......@@ -60,23 +73,20 @@ struct dev_info *dev_info_dup(const struct dev_info *dev)
if (!dev_out)
return NULL;
dev_out-> = dev->;
dev_out->rsc.model = strdup_safe(dev->rsc.model);
dev_out->rsc.adm_status = dev->rsc.adm_status;
dev_out->path = strdup_safe(dev->path);
dev_out->host = strdup_safe(dev->host);
dev_info_cpy(dev_out, dev);
return dev_out;
void dev_info_free(struct dev_info *dev)
void dev_info_free(struct dev_info *dev, bool free_top_struct)
if (!dev)
if (free_top_struct)
struct media_info *media_info_dup(const struct media_info *media)
......@@ -45,8 +45,16 @@ bool pho_id_equal(const struct pho_id *id1, const struct pho_id *id2);
/** duplicate a dev_info structure */
struct dev_info *dev_info_dup(const struct dev_info *dev);
/** free a dev_info structure */
void dev_info_free(struct dev_info *dev);
/** copy a dev_info structure in an already allocated one */
void dev_info_cpy(struct dev_info *dev_dst, const struct dev_info *dev_src);
* Free a dev_info structure
* If free_top_struct is false, only releasing the structure contents,
* the caller is responsible for the top structure.
void dev_info_free(struct dev_info *dev, bool free_top_struct);
/** duplicate a media_info structure */
struct media_info *media_info_dup(const struct media_info *mda);
......@@ -581,7 +581,7 @@ err_no_res:
static void dev_descr_fini(gpointer ptr)
struct dev_descr *dev = (struct dev_descr *)ptr;
dev_info_free(dev->dss_dev_info, true);
dev->dss_dev_info = NULL;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment