linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH] btrfs-progs: fix error checking in load_device_info
Date: Fri,  2 Oct 2015 17:49:08 +0200	[thread overview]
Message-ID: <1443800948-27933-1-git-send-email-dsterba@suse.com> (raw)

load_device_info queries the FS_INFO ioctl and this may fail with EPERM
on older kernels. The check did not verify the ioctl return value and
incorrectly returned EPERM if it was previously stored in errno.

This fixes 'btrfs fi usage' that will print the overall summary for all
users (provided that the FS_INFO ioctl is already unprivileged).

Signed-off-by: David Sterba <dsterba@suse.com>
---
 cmds-fi-usage.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index 54b8b1c1d996..50d633372023 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -504,7 +504,7 @@ static int cmp_device_info(const void *a, const void *b)
 static int load_device_info(int fd, struct device_info **device_info_ptr,
 			   int *device_info_count)
 {
-	int ret, i, ndevs, e;
+	int ret, i, ndevs;
 	struct btrfs_ioctl_fs_info_args fi_args;
 	struct btrfs_ioctl_dev_info_args dev_info;
 	struct device_info *info;
@@ -513,12 +513,11 @@ static int load_device_info(int fd, struct device_info **device_info_ptr,
 	*device_info_ptr = 0;
 
 	ret = ioctl(fd, BTRFS_IOC_FS_INFO, &fi_args);
-	e = errno;
-	if (e == EPERM)
-		return -e;
 	if (ret < 0) {
+		if (errno == EPERM)
+			return -errno;
 		fprintf(stderr, "ERROR: cannot get filesystem info - %s\n",
-				strerror(e));
+				strerror(errno));
 		return 1;
 	}
 
-- 
2.1.3


                 reply	other threads:[~2015-10-02 15:50 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=1443800948-27933-1-git-send-email-dsterba@suse.com \
    --to=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).