[Accel-config] [PATCH v1 2/6] accel-config: Allow other functionality if mdev support unavailable

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

In older drivers mdev is not supported. To provide backward
compatibility disable mdev if not supported and allow other
functionality.

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

diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c
index b1de896..69f0f71 100644
--- a/accfg/lib/libaccfg.c
+++ b/accfg/lib/libaccfg.c
@@ -568,7 +568,11 @@ static void *add_device(void *parent, int id, const char *ctl_base, char *dev_pr
 		goto err_dev_path;
 	}
 	free(device->mdev_path);
-	device->mdev_path = p;
+	if (access(p, R_OK)) {
+		free(p);
+		device->mdev_path = NULL;
+	} else
+		device->mdev_path = p;
 
 	device->device_buf = calloc(1, strlen(device->device_path) +
 			MAX_PARAM_LEN);
@@ -583,7 +587,7 @@ static void *add_device(void *parent, int id, const char *ctl_base, char *dev_pr
 	if (rc < 0)
 		goto err_dev_path;
 
-	if (add_device_mdevs(ctx, device))
+	if (device->mdev_path && add_device_mdevs(ctx, device))
 		goto err_dev_path;
 
 	list_add_tail(&ctx->devices, &device->list);
@@ -1012,6 +1016,9 @@ ACCFG_EXPORT int accfg_create_mdev(struct accfg_device *device,
 	unsigned int version;
 	int rc;
 
+	if (!device->mdev_path)
+		return -ENOENT;
+
 	if (type >= ACCFG_MDEV_TYPE_UNKNOWN || type < 0)
 		return -EINVAL;
 
@@ -1069,6 +1076,9 @@ ACCFG_EXPORT int accfg_remove_mdev(struct accfg_device *device, uuid_t uuid)
 	struct accfg_device_mdev *entry, *next;
 	int rc, all;
 
+	if (!device->mdev_path)
+		return -ENOENT;
+
 	/* remove all mdevs if null uuid is passed */
 	all = uuid_is_null(uuid);
 	list_for_each_safe(&device->mdev_list, entry, next, list) {
-- 
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.