mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 6/8] FAT: Fix error path
Date: Sun, 18 Mar 2012 15:26:42 +0100	[thread overview]
Message-ID: <1332080804-13132-7-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1332080804-13132-1-git-send-email-s.hauer@pengutronix.de>

- forward the return value of chk_mounted to detect whether mount succeeded
- free resources on mount failure

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fat/fat.c |   18 +++++++++++++++---
 fs/fat/ff.c  |    4 +---
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 7d6e37a..21464bd 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -376,6 +376,7 @@ static int fat_probe(struct device_d *dev)
 	struct fs_device_d *fsdev = dev_to_fs_device(dev);
 	struct fat_priv *priv = xzalloc(sizeof(struct fat_priv));
 	char *backingstore = fsdev->backingstore;
+	int ret;
 
 	dev->priv = priv;
 
@@ -383,13 +384,24 @@ static int fat_probe(struct device_d *dev)
 		backingstore += 5;
 
 	priv->cdev = cdev_open(backingstore, O_RDWR);
-	if (!priv->cdev)
-		return -EINVAL;
+	if (!priv->cdev) {
+		ret = -ENOENT;
+		goto err_open;
+	}
 
 	priv->fat.userdata = priv;
-	f_mount(&priv->fat);
+	ret = f_mount(&priv->fat);
+	if (ret)
+		goto err_mount;
 
 	return 0;
+
+err_mount:
+	cdev_close(priv->cdev);
+err_open:
+	free(priv);
+
+	return ret;
 }
 
 static void fat_remove(struct device_d *dev)
diff --git a/fs/fat/ff.c b/fs/fat/ff.c
index a720389..2d476ee 100644
--- a/fs/fat/ff.c
+++ b/fs/fat/ff.c
@@ -1699,9 +1699,7 @@ int f_mount (
 {
 	fs->fs_type = 0; /* Clear new fs object */
 
-	chk_mounted(fs, 0);
-
-	return 0;
+	return chk_mounted(fs, 0);
 }
 
 /*
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-03-18 14:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-18 14:26 [PATCH] automount support Sascha Hauer
2012-03-18 14:26 ` [PATCH 1/8] fs: change get_fs_device_by_path prototype Sascha Hauer
2012-03-18 14:26 ` [PATCH 2/8] fs: drop struct mtab_entry Sascha Hauer
2012-03-18 14:26 ` [PATCH 3/8] Add automount support Sascha Hauer
2012-03-18 14:26 ` [PATCH 4/8] fs open: pass error from stat Sascha Hauer
2012-03-18 14:26 ` [PATCH 5/8] hush source: expand $PATH Sascha Hauer
2012-03-18 14:26 ` Sascha Hauer [this message]
2012-03-18 14:26 ` [PATCH 7/8] usb command: by default scan only once for USB devices Sascha Hauer
2012-03-18 14:26 ` [PATCH 8/8] partition command: optionally do not automatically prepend the device name Sascha Hauer

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=1332080804-13132-7-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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