diff mbox series

[ndctl] ndctl: return -errno when keyctl_read_alloc() fails

Message ID 20210619014056.31907-3-alison.schofield@intel.com (mailing list archive)
State New
Headers show
Series [ndctl] ndctl: return -errno when keyctl_read_alloc() fails | expand

Commit Message

Alison Schofield June 19, 2021, 1:40 a.m. UTC
When keyctl_read_alloc() fails during key creation a stale rc
value is returned as a key serial number, rather than the errno
from keyctl_read_alloc(). The nvdimm driver eventually discovers
it's a bad key serial number, and the entire operation fails as
it should.

Fail immediately by using the available errno correctly.

Fixes: 86b078b44275 ("ndctl: add passphrase management commands")
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
 ndctl/util/keys.c | 1 +
 1 file changed, 1 insertion(+)

base-commit: 4e646fa490ba4b782afa188dd8818b94c419924e
diff mbox series


diff --git a/ndctl/util/keys.c b/ndctl/util/keys.c
index 30cb4c8..d1cc890 100644
--- a/ndctl/util/keys.c
+++ b/ndctl/util/keys.c
@@ -254,6 +254,7 @@  static key_serial_t dimm_create_key(struct ndctl_dimm *dimm,
 	size = keyctl_read_alloc(key, &buffer);
 	if (size < 0) {
+		rc = -errno;
 		fprintf(stderr, "keyctl_read_alloc failed: %s\n", strerror(errno));
 		keyctl_unlink(key, KEY_SPEC_USER_KEYRING);
 		return rc;