All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH v2] util: distinguish error codes for sysfs_{read, write}_attr()
Date: Fri, 09 Jun 2017 14:04:59 -0700	[thread overview]
Message-ID: <149704229930.26749.7610142989390389569.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)

There are occasions where it would be good to know the difference
between a sysfs attribute failing to be accessed because we could not
open versus could not read/write.

Cc: Linda Knippers <linda.knippers@hpe.com>
[ljk: just return the errno directly]
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/sysfs.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/util/sysfs.c b/util/sysfs.c
index 31d1a898eba2..4178aeced087 100644
--- a/util/sysfs.c
+++ b/util/sysfs.c
@@ -34,13 +34,13 @@ int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf)
 
 	if (fd < 0) {
 		log_dbg(ctx, "failed to open %s: %s\n", path, strerror(errno));
-		return -1;
+		return -errno;
 	}
 	n = read(fd, buf, SYSFS_ATTR_SIZE);
 	close(fd);
 	if (n < 0 || n >= SYSFS_ATTR_SIZE) {
 		log_dbg(ctx, "failed to read %s: %s\n", path, strerror(errno));
-		return -1;
+		return -errno;
 	}
 	buf[n] = 0;
 	if (n && buf[n-1] == '\n')
@@ -56,7 +56,7 @@ static int write_attr(struct log_ctx *ctx, const char *path,
 
 	if (fd < 0) {
 		log_dbg(ctx, "failed to open %s: %s\n", path, strerror(errno));
-		return -1;
+		return -errno;
 	}
 	n = write(fd, buf, len);
 	close(fd);
@@ -64,7 +64,7 @@ static int write_attr(struct log_ctx *ctx, const char *path,
 		if (!quiet)
 			log_dbg(ctx, "failed to write %s to %s: %s\n", buf, path,
 					strerror(errno));
-		return -1;
+		return -errno;
 	}
 	return 0;
 }

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

                 reply	other threads:[~2017-06-09 21:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=149704229930.26749.7610142989390389569.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.