public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] libmtd: fix mtd_dev_present return value on legacy systems
@ 2014-09-10 14:56 Guido Martínez
  2014-09-15 17:49 ` Brian Norris
  0 siblings, 1 reply; 2+ messages in thread
From: Guido Martínez @ 2014-09-10 14:56 UTC (permalink / raw)
  To: linux-mtd, Artem Bityutskiy
  Cc: Brian Norris, Ezequiel García, Guido Martínez

On legacy systems, if "/proc/mtd" doesn't exist or gives a read error,
mtd_dev_present returns -1 (since it calls legacy_dev_present), contrary
to what's specified in the header file.

This causes checks like

  if (mtd_dev_present(n)) {
    ...
  }

to give false positives. Fix this by comparing the return value to 1.

Signed-off-by: Guido Martínez <guido@vanguardiasur.com.ar>
---
 lib/libmtd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/libmtd.c b/lib/libmtd.c
index 2089373..aff4c8b 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -647,9 +647,9 @@ int mtd_dev_present(libmtd_t desc, int mtd_num) {
 	struct stat st;
 	struct libmtd *lib = (struct libmtd *)desc;
 
-	if (!lib->sysfs_supported)
-		return legacy_dev_present(mtd_num);
-	else {
+	if (!lib->sysfs_supported) {
+		return legacy_dev_present(mtd_num) == 1;
+	} else {
 		char file[strlen(lib->mtd) + 10];
 
 		sprintf(file, lib->mtd, mtd_num);
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libmtd: fix mtd_dev_present return value on legacy systems
  2014-09-10 14:56 [PATCH] libmtd: fix mtd_dev_present return value on legacy systems Guido Martínez
@ 2014-09-15 17:49 ` Brian Norris
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Norris @ 2014-09-15 17:49 UTC (permalink / raw)
  To: Guido Martínez; +Cc: linux-mtd, Ezequiel García, Artem Bityutskiy

On Wed, Sep 10, 2014 at 11:56:40AM -0300, Guido Martínez wrote:
> On legacy systems, if "/proc/mtd" doesn't exist or gives a read error,
> mtd_dev_present returns -1 (since it calls legacy_dev_present), contrary
> to what's specified in the header file.
> 
> This causes checks like
> 
>   if (mtd_dev_present(n)) {
>     ...
>   }
> 
> to give false positives. Fix this by comparing the return value to 1.
> 
> Signed-off-by: Guido Martínez <guido@vanguardiasur.com.ar>

Pushed to mtd-utils.git. Thanks!

Brian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-09-15 17:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-10 14:56 [PATCH] libmtd: fix mtd_dev_present return value on legacy systems Guido Martínez
2014-09-15 17:49 ` Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox