[Accel-config] [PATCH v4 3/3] accel-config: Reset cmd_status during device init

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

Initialize cmd_status at device init to avoid getting stale value
during error checks.

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

diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c
index 5df19a7..f21cab5 100644
--- a/accfg/lib/libaccfg.c
+++ b/accfg/lib/libaccfg.c
@@ -154,6 +154,23 @@ static inline bool is_mdev_registered(struct accfg_device *device)
 	return device->mdev_path && !access(device->mdev_path, R_OK);
 }
 
+static int accfg_set_param(struct accfg_ctx *ctx, int dfd, char *name,
+		void *buf, int len)
+{
+	int fd = openat(dfd, name, O_RDWR);
+	int n;
+
+	if (fd == -1)
+		return -errno;
+
+	n = write(fd, buf, len);
+	close(fd);
+	if (n != len)
+		return -errno;
+
+	return 0;
+}
+
 static long accfg_get_param_long(struct accfg_ctx *ctx, int dfd, char *name)
 {
 	int fd = openat(dfd, name, O_RDONLY);
@@ -589,6 +606,14 @@ static void *add_device(void *parent, int id, const char *ctl_base,
 		return NULL;
 	}
 
+	rc = accfg_set_param(ctx, dfd, "cmd_status", "1", 1);
+	/* older drivers don't support writing to cmd_status */
+	if (rc && rc != -EACCES) {
+		err(ctx, "Failed resetting cmd status %d\n", rc);
+		close(dfd);
+		goto err_device;
+	}
+
 	device = calloc(1, sizeof(*device));
 	if (!device) {
 		err(ctx, "allocation of device failed\n");
-- 
2.26.3
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.