diff mbox

[ndctl] ndctl: fix ars_status output buffer sizing

Message ID 20160220230025.21083.79247.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit ec343fb3db29
Headers show

Commit Message

Dan Williams Feb. 20, 2016, 11 p.m. UTC
The ars_cap command indicates the buffer size we need to prepare for
ars_status commands.  The kernel reads the ars_status.out_length field
to validate how much output buffer space is available.  The
ndctl_bus_cmd_new_ars_status() helper was neglecting to set that size.
It was also misinterpreting the value of ars_cap.max_ars_out.  That
value is the total output data size of an ars_status command, not
incremental to the base size of a ars_status command.

Cc: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 lib/libndctl-ars.c |    4 ++--
 test/libndctl.c    |    7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/lib/libndctl-ars.c b/lib/libndctl-ars.c
index ea3af82ca647..863217dd09aa 100644
--- a/lib/libndctl-ars.c
+++ b/lib/libndctl-ars.c
@@ -111,8 +111,7 @@  NDCTL_EXPORT struct ndctl_cmd *ndctl_bus_cmd_new_ars_status(struct ndctl_cmd *ar
 		return NULL;
 	}
 
-	size = sizeof(*cmd) + sizeof(struct nd_cmd_ars_status) +
-			ars_cap_cmd->max_ars_out;
+	size = sizeof(*cmd) + ars_cap_cmd->max_ars_out;
 	cmd = calloc(1, size);
 	if (!cmd)
 		return NULL;
@@ -123,6 +122,7 @@  NDCTL_EXPORT struct ndctl_cmd *ndctl_bus_cmd_new_ars_status(struct ndctl_cmd *ar
 	cmd->size = size;
 	cmd->status = 1;
 	cmd->firmware_status = &cmd->ars_status->status;
+	cmd->ars_status->out_length = ars_cap_cmd->max_ars_out;
 
 	return cmd;
 }
diff --git a/test/libndctl.c b/test/libndctl.c
index 5c26b5fdffc3..b4539b996d6a 100644
--- a/test/libndctl.c
+++ b/test/libndctl.c
@@ -1607,9 +1607,10 @@  static int check_ars_cap(struct ndctl_bus *bus, struct ndctl_dimm *dimm,
 		return rc;
 	}
 
-	if (ndctl_cmd_ars_cap_get_size(cmd) != 256) {
-		fprintf(stderr, "%s: bus: %s expect size: %d got: %d\n",
-				__func__, ndctl_bus_get_provider(bus), 256,
+	if (ndctl_cmd_ars_cap_get_size(cmd) < sizeof(struct nd_cmd_ars_status)) {
+		fprintf(stderr, "%s: bus: %s expect size >= %zd got: %d\n",
+				__func__, ndctl_bus_get_provider(bus),
+				sizeof(struct nd_cmd_ars_status),
 				ndctl_cmd_ars_cap_get_size(cmd));
 		ndctl_cmd_unref(cmd);
 		return -ENXIO;