From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] tftp: do not forget to close the file in error case
Date: Mon, 14 Jun 2010 09:43:42 +0200 [thread overview]
Message-ID: <1276501424-3224-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1276501424-3224-1-git-send-email-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/tftp.c | 48 ++++++++++++++++++++++--------------------------
1 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/net/tftp.c b/net/tftp.c
index b0bc7c5..38d16bc 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -206,31 +206,11 @@ static void tftp_handler(char *packet, unsigned len)
}
}
-static int tftp_start(char *filename)
-{
- char ip1[16];
-
- tftp_filename = filename;
-
- printf("TFTP from server %s; Filename: '%s'\nLoading: ",
- ip_to_string(net_get_serverip(), ip1),
- tftp_filename);
-
- tftp_timer_start = get_time_ns();
- tftp_state = STATE_RRQ;
- tftp_block = 0;
-
- tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler);
- if (IS_ERR(tftp_con))
- return PTR_ERR(tftp_con);
-
- return tftp_send();
-}
-
static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
{
char *localfile;
char *remotefile;
+ char ip1[16];
if (argc < 2)
return COMMAND_ERROR_USAGE;
@@ -248,9 +228,25 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
return 1;
}
- tftp_err = tftp_start(remotefile);
+ tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler);
+ if (IS_ERR(tftp_con)) {
+ tftp_err = PTR_ERR(tftp_con);
+ goto out_close;
+ }
+
+ tftp_filename = remotefile;
+
+ printf("TFTP from server %s; Filename: '%s'\nLoading: ",
+ ip_to_string(net_get_serverip(), ip1),
+ tftp_filename);
+
+ tftp_timer_start = get_time_ns();
+ tftp_state = STATE_RRQ;
+ tftp_block = 0;
+
+ tftp_err = tftp_send();
if (tftp_err)
- goto out;
+ goto out_unreg;
while (tftp_state != STATE_DONE) {
if (ctrlc()) {
@@ -264,11 +260,11 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
tftp_send();
}
}
-
+out_unreg:
net_unregister(tftp_con);
-
+out_close:
close(net_store_fd);
-out:
+
if (tftp_err) {
printf("\ntftp failed: %s\n", strerror(-tftp_err));
unlink(localfile);
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2010-06-14 7:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-14 7:43 Some (new-) network stack fixes Sascha Hauer
2010-06-14 7:43 ` Sascha Hauer [this message]
2010-06-14 7:43 ` [PATCH 2/3] parameter: set p->value to NULL to avoid freeing it again Sascha Hauer
2010-06-14 7:43 ` [PATCH 3/3] dhcp: do not call net_unregister if net_udp_new failed 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=1276501424-3224-2-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