From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/4] net: dhcp: simplify dhcp_options_process
Date: Mon, 14 Dec 2015 11:41:12 +0100 [thread overview]
Message-ID: <1450089674-25721-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1450089674-25721-1-git-send-email-s.hauer@pengutronix.de>
dhcp_options_handle returns the index into the dhcp_options array.
This is only to be able in the caller to print a debug message when
the index returned from dhcp_options_handle is out of bounds.
Simplify this by printing the debug message in dhcp_options_handle
and not in the caller.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/dhcp.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/net/dhcp.c b/net/dhcp.c
index fa4c4d1..78e5fe0 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -482,7 +482,7 @@ static int bootp_request(void)
return ret;
}
-static int dhcp_options_handle(unsigned char option, unsigned char *popt,
+static void dhcp_options_handle(unsigned char option, unsigned char *popt,
int optlen, struct bootp *bp)
{
int i;
@@ -492,13 +492,13 @@ static int dhcp_options_handle(unsigned char option, unsigned char *popt,
opt = &dhcp_options[i];
if (opt->option == option) {
opt->bp = bp;
- opt->handle(opt, popt, optlen);
- goto end;
+ if (opt->handle)
+ opt->handle(opt, popt, optlen);
+ return;
}
}
-end:
- return i;
+ debug("*** Unhandled DHCP Option in OFFER/ACK: %d\n", option);
}
static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
@@ -506,15 +506,12 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
unsigned char *end = popt + sizeof(*bp) + OPT_SIZE;
int oplen;
unsigned char option;
- int i;
while (popt < end && *popt != 0xff) {
oplen = *(popt + 1);
option = *popt;
- i = dhcp_options_handle(option, popt + 2, oplen, bp);
- if (i == ARRAY_SIZE(dhcp_options))
- debug("*** Unhandled DHCP Option in OFFER/ACK: %d\n", option);
+ dhcp_options_handle(option, popt + 2, oplen, bp);
popt += oplen + 2; /* Process next option */
}
--
2.6.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-12-14 10:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-14 10:41 [PATCH 1/4] net: dhcp: unify options and params Sascha Hauer
2015-12-14 10:41 ` Sascha Hauer [this message]
2015-12-14 10:41 ` [PATCH 3/4] net: dhcp: make unmodified variable const Sascha Hauer
2015-12-14 10:41 ` [PATCH 4/4] net: resolv: Make argument const 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=1450089674-25721-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