util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bernhard Voelker <mail@bernhard-voelker.de>
To: util-linux@vger.kernel.org
Cc: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: [PATCH] lib/sysfs: make sysfs_partno_to_devno better readable
Date: Tue, 14 Aug 2012 09:01:45 +0200	[thread overview]
Message-ID: <1344927705-5866-1-git-send-email-mail@bernhard-voelker.de> (raw)

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
---
 lib/sysfs.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/sysfs.c b/lib/sysfs.c
index b468e88..7b2c5f7 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -321,8 +321,8 @@ int sysfs_is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_nam
 }
 
 /*
- * Copnverts @partno (partition number) to devno of the partition. The @cxt
- * handles wholedisk device.
+ * Converts @partno (partition number) to devno of the partition.
+ * The @cxt handles wholedisk device.
  *
  * Note that this code does not expect any special format of the
  * partitions devnames.
@@ -345,13 +345,15 @@ dev_t sysfs_partno_to_devno(struct sysfs_cxt *cxt, int partno)
 			continue;
 
 		snprintf(path, sizeof(path), "%s/partition", d->d_name);
-		if (sysfs_read_int(cxt, path, &n) || n != partno)
+		if (sysfs_read_int(cxt, path, &n))
 			continue;
 
-		snprintf(path, sizeof(path), "%s/dev", d->d_name);
-		if (sysfs_scanf(cxt, path, "%d:%d", &maj, &min) == 2)
-			devno = makedev(maj, min);
-		break;
+		if (n == partno) {
+			snprintf(path, sizeof(path), "%s/dev", d->d_name);
+			if (sysfs_scanf(cxt, path, "%d:%d", &maj, &min) == 2)
+				devno = makedev(maj, min);
+			break;
+		}
 	}
 
 	closedir(dir);
-- 
1.7.7


             reply	other threads:[~2012-08-14  7:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14  7:01 Bernhard Voelker [this message]
2012-08-14 16:23 ` [PATCH] lib/sysfs: make sysfs_partno_to_devno better readable Karel Zak

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=1344927705-5866-1-git-send-email-mail@bernhard-voelker.de \
    --to=mail@bernhard-voelker.de \
    --cc=util-linux@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).