[Accel-config] [PATCH v1 2/5] accel-config: Fix a segmentation fault issue in add device

ramesh.thomas at intel.com
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
From: Ramesh Thomas <ramesh.thomas(a)intel.com>

During device init, newly created device should be added to device
linked list only at the end in the success path. Adding of mdev was
done after that, resulting in invalid linked list state if the mdev
scanning failed causing the add device function to fail. Move it before
adding device to linked list.

Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c
index eda6b45..5835129 100644
--- a/accfg/lib/libaccfg.c
+++ b/accfg/lib/libaccfg.c
@@ -568,12 +568,13 @@ static void *add_device(void *parent, int id, const char *ctl_base, char *dev_pr
 	rc = device_parse_type(device);
 	if (rc < 0)
 		goto err_dev_path;
-	list_add_tail(&ctx->devices, &device->list);
-	free(path);
 
 	if (add_device_mdevs(ctx, device))
 		goto err_dev_path;
 
+	list_add_tail(&ctx->devices, &device->list);
+	free(path);
+
 	return device;
 
 err_dev_path:
-- 
2.26.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.