From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 5/9] usb: gadget: fastboot: Always remove temporary file
Date: Fri, 9 Feb 2018 10:43:12 +0100 [thread overview]
Message-ID: <20180209094316.8523-6-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180209094316.8523-1-s.hauer@pengutronix.de>
We should consistently remove the temporary image file, regardless
of the error code. To do so, always jump to the end of the function
where the temporary file is removed.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/usb/gadget/f_fastboot.c | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 62b13bcb8c..db9b906b2b 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -895,7 +895,8 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
if (!fentry) {
fastboot_tx_print(f_fb, "FAILNo such partition: %s", cmd);
- return;
+ ret = -ENOENT;
+ goto out;
}
filename = fentry->filename;
@@ -903,22 +904,21 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
if (filetype == filetype_android_sparse) {
if (!IS_ENABLED(USB_GADGET_FASTBOOT_SPARSE)) {
fastboot_tx_print(f_fb, "FAILsparse image not supported");
- return;
+ ret = -EOPNOTSUPP;
+ goto out;
}
ret = fastboot_handle_sparse(f_fb, fentry);
- if (ret) {
+ if (ret)
fastboot_tx_print(f_fb, "FAILwriting sparse image: %s",
strerror(-ret));
- return;
- }
goto out;
}
ret = check_ubi(f_fb, fentry, filetype);
if (ret < 0)
- return;
+ goto out;
if (ret > 0) {
struct mtd_info *mtd;
@@ -926,11 +926,8 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
mtd = get_mtd(f_fb, fentry->filename);
ret = do_ubiformat(f_fb, mtd, FASTBOOT_TMPFILE);
- if (ret) {
+ if (ret)
fastboot_tx_print(f_fb, "FAILwrite partition: %s", strerror(-ret));
- return;
- }
-
goto out;
}
@@ -951,7 +948,7 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
f_fb->download_size);
if (ret) {
fastboot_tx_print(f_fb, "FAILreading barebox");
- return;
+ goto out;
}
data.image = image;
@@ -960,10 +957,8 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
free(image);
- if (ret) {
+ if (ret)
fastboot_tx_print(f_fb, "FAILupdate barebox: %s", strerror(-ret));
- return;
- }
goto out;
}
@@ -971,15 +966,14 @@ static void cb_flash(struct f_fastboot *f_fb, const char *cmd)
copy:
ret = copy_file(FASTBOOT_TMPFILE, filename, 1);
- unlink(FASTBOOT_TMPFILE);
-
- if (ret) {
+ if (ret)
fastboot_tx_print(f_fb, "FAILwrite partition: %s", strerror(-ret));
- return;
- }
out:
- fastboot_tx_print(f_fb, "OKAY");
+ if (!ret)
+ fastboot_tx_print(f_fb, "OKAY");
+
+ unlink(FASTBOOT_TMPFILE);
}
static void cb_erase(struct f_fastboot *f_fb, const char *cmd)
--
2.15.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2018-02-09 9:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-09 9:43 [PATCH 0/9] Fastboot customization support Sascha Hauer
2018-02-09 9:43 ` [PATCH 1/9] ubiformat: Allow to ubiformat with a buffer given Sascha Hauer
2018-02-09 9:43 ` [PATCH 2/9] usb: gadget: fastboot: Make sparse support optional Sascha Hauer
2018-02-09 9:43 ` [PATCH 3/9] usb: gadget: fastboot: pass struct f_fastboot * around Sascha Hauer
2018-02-09 9:43 ` [PATCH 4/9] usb: gadget: fastboot: use read_file_2 Sascha Hauer
2018-02-09 9:43 ` Sascha Hauer [this message]
2018-02-09 9:43 ` [PATCH 6/9] usb: gadget: fastboot: fix typo Sascha Hauer
2018-02-09 9:43 ` [PATCH 7/9] usb: gadget: fastboot: beautify fb_run_command() Sascha Hauer
2018-02-09 9:43 ` [PATCH 8/9] usb: gadget: fastboot: Add option to download to a buffer Sascha Hauer
2018-02-09 9:43 ` [PATCH 9/9] usb: gadget: fastboot: Add external command execution support 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=20180209094316.8523-6-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