What if eth_init() fails?
Hi all,
I observed that when the Ethernet initialization fails, it is not properly halting the operation and exiting. On walking through the Networking files, I saw that the eth_init() in eth.c either returns a 0 or 1. Now, in the NetLoop() in net.c file, from where the eth_init() gets called, checks the condition
if (eth_init(bd) < 0)
{
eth_halt();
return(-1);
}which is thus never true.
Thus the network operation, never exits gracefully, if Ethernet init fails.
Any of you, have any clues about this??
Signature · 5 lines
View this message in context: http://www.nabble.com/What-if-eth_init%28%29-fails--tf4802433.html#a13740586 Sent from the Uboot - Users mailing list [email protected]. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.denx.de/pipermail/u-boot/attachments/20071113/c07f5f6b/attachment.htm
Hi Upakul,
Quoted 7 lines
Hi all, I observed that when the Ethernet initialization fails, it is not properly halting the operation and exiting. On walking through the Networking files, I saw that the
eth_init()ineth.ceither returns a 0 or 1. Now, in theNetLoop()innet.cfile, from where theeth_init()gets called, checks the condition if (eth_init(bd)< 0) {eth_halt(); return(-1); } which is thus never true. Thus the network operation, never exits gracefully, if Ethernet init fails. Any of you, have any clues about this??
I think your analysis is right and thus the code in NetLoop should be fixed. Feel free to send a patch and I am pretty sure Ben Warren will pick it up into the u-boot-net repo.
Cheers
Detlev
Signature · 8 lines
Two monks went fishing in an electron river. The first monk drew out his network, and out flopped a hacker. The second monk cried, "The poor hacker! How can it live outside of the network?" The first monk said, "When you have learned to live outside the network, then you will know." -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
Hi Upakul,
Quoted 5 lines · Upakul Barkakaty
Hi all, I observed that when the Ethernet initialization fails, it is not properly halting the operation and exiting. On walking through the Networking files, I saw that the
eth_init()ineth.ceither returns a 0 or 1. Now, in theNetLoop()innet.cfile, from where theeth_init()gets called, checks the condition if (eth_init(bd)< 0) {eth_halt();
Quoted 8 lines
return(-1); } which is thus never true. Thus the network operation, never exits gracefully, if Ethernet init fails. Any of you, have any clues about this??
------------------------------------------------------------------------
View this message in context: What ifeth_init()fails?
<http://www.nabble.com/What-if-eth_init%28%29-fails--tf4802433.html#a13740586>
Sent from the Uboot - Users mailing list archive
<http://www.nabble.com/Uboot---Users-f553.html> at Nabble.com.
You are correct. If you send a patch, I'll incorporate it.
regards,
Ben
Quoted 8 lines · Upakul Barkakaty
Hi all, I observed that when the Ethernet initialization fails, it is not properly halting the operation and exiting. On walking through the Networking files, I saw that the
eth_init()ineth.ceither returns a 0 or 1. Now, in theNetLoop()innet.cfile, from where theeth_init()gets called, checks the condition if (eth_init(bd)< 0) {eth_halt(); return(-1); } which is thus never true. Thus the network operation, never exits gracefully, if Ethernet init fails. Any of you, have any clues about this??
This is a known bug. The problem is that it's been around for so long, people don't realize what's happening. If you fix it, you might break something else.
I still think it should be fixed. In fact, I was planning on submitting a patch next month for it.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 10 lines · Timur Tabi
Quoted 8 lines · Upakul Barkakaty
Hi all, I observed that when the Ethernet initialization fails, it is not properly halting the operation and exiting. On walking through the Networking files, I saw that the
eth_init()ineth.ceither returns a 0 or 1. Now, in theNetLoop()innet.cfile, from where theeth_init()gets called, checks the condition if (eth_init(bd)< 0) {eth_halt(); return(-1); } which is thus never true. Thus the network operation, never exits gracefully, if Ethernet init fails. Any of you, have any clues about this??
Quoted 3 lines
This is a known bug. The problem is that it's been around for so long, people don't realize what's happening. If you fix it, you might break something else.
so by fixing one bug, you may expose other bugs, and that's a bad thing ? bad code has gotta go !
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20071114/ed3e560a/attachment.pgp
Quoted 2 lines · Mike Frysinger
so by fixing one bug, you may expose other bugs, and that's a bad thing ? bad code has gotta go !
My point was that if you fix this bug, you should be prepared for other bugs to show up, and people to be surprised about it. Don't just fix the first bug and walk away. If you can't test all the other platforms, then you should at least pay attention when other people report the other bugs, and then help them out.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 9 lines · Timur Tabi
Quoted 2 lines · Mike Frysinger
so by fixing one bug, you may expose other bugs, and that's a bad thing ?
bad code has gotta go !My point was that if you fix this bug, you should be prepared for other bugs to show up, and people to be surprised about it. Don't just fix the first bug and walk away. If you can't test all the other platforms, then you should at least pay attention when other people report the other bugs, and then help them out.
i'd say it is the fault of those platforms for having bad code in the first place ... cant reasonably expect Upakul to audit and fix everyone's mistakes. -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20071114/002769c6/attachment.pgp
Hi Detlev/Ben,
Thanks for the replies. I am attaching herewith, the patch which I suppose should fix the issue in NetLoop().
Regards,
Upakul Barkakaty
Conexant Systems,Inc
Quoted 24 lines · Detlev Zundel
Hi Upakul,
Quoted 1 line
Hi all, I observed that when the Ethernet initialization fails, it is
not
Quoted 1 line
properly halting the operation and exiting. On walking through the
Networking
Quoted 1 line
files, I saw that the
eth_init()ineth.ceither returns a 0 or 1. Now,in the
Quoted 1 line
NetLoop()innet.cfile, from where theeth_init()gets called, checksthe
Quoted 1 line
condition if (
eth_init(bd)< 0) {eth_halt(); return(-1); } which isthus never
Quoted 1 line
true. Thus the network operation, never exits gracefully, if Ethernet
init
Quoted 1 line
fails. Any of you, have any clues about this??
I think your analysis is right and thus the code in NetLoop should be fixed. Feel free to send a patch and I am pretty sure Ben Warren will pick it up into the u-boot-net repo.
Cheers
Detlev
Quoted 13 lines
--
Two monks went fishing in an electron river. The first monk drew out his
network, and out flopped a hacker. The second monk cried, "The poor hacker!
How can it live outside of the network?" The first monk said, "When
you
have learned to live outside the network, then you will know." --
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.denx.de/pipermail/u-boot/attachments/20071116/68985e7e/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: net.c.patch
Type: application/octet-stream
Size: 290 bytes
Desc: not available
Url : http://lists.denx.de/pipermail/u-boot/attachments/20071116/68985e7e/attachment.obj
Hi Upakul,
Quoted 2 lines
Thanks for the replies. I am attaching herewith, the patch which I suppose should fix the issue in
NetLoop().
Thanks, but nowadays we would appreciate if you could send a patch with a proper commit message and a Signed-Off-By line. Just look at recent patches here on the mailing list to see what I mean. Oh and by the way, version 1.2.0 will not get any update fixes so please base your patch on the top of tree of git, thanks.
net/net.c line 311
Quoted 11 lines
net/net.c +1
-1@@ -305,7 +305,7 @@#ifdef CONFIG_NET_MULTI eth_set_current ();#endif -if (eth_init (bd) <0 ) { +if (eth_init (bd) >0 ) {eth_halt ();return (-1 ); }
Secondly and more important, did you test this? I'd say your test is the wrong way round, i.e. eth_init returns true in the C sense (!=0) if it was able to initialize an interface. (This also chimes with the naming of the function by the way). So I'd propose to go for "!eth_init(..)".
Cheers
Detlev
Signature · 7 lines
Man sei weder unzufrieden mit sich selbst - denn das waere Kleinmut - noch
selbstzufrieden - denn das waere Dummheit.
--- Baltasar Gracian
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.deHi,
Quoted 9 lines
Quoted 9 lines
net/net.c +1
-1@@ -305,7 +305,7 @@#ifdef CONFIG_NET_MULTI eth_set_current ();#endif -if (eth_init (bd) <0 ) { +if (eth_init (bd) >0 ) {eth_halt ();
Quoted 8 lines
net/net.c line 311
Quoted 2 lines
net/net.c +0
-0return (-1 ); }Secondly and more important, did you test this? I'd say your test is the wrong way round, i.e.
eth_initreturns true in the C sense (!=0) if it was able to initialize an interface. (This also chimes with the naming of the function by the way). So I'd propose to go for "!eth_init(..)".
Thinking about this somemore, I am now convinced that the problem should not be fixed at the caller but in eth_init. Testing for <0 is a pretty idiomatic test for errors, so we should rather adjust eth_init to fit this idiom than spreading "aberrant" behaviour.
Cheers
Detlev
Signature · 6 lines
Computers are useless. They can only give you answers.
-- Pablo Picasso
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: [email protected]Dear Upakul,
Quoted 3 lines · in message <[email protected]> you…
Thanks for the replies. I am attaching herewith, the patch which I suppose should fix the issue in
NetLoop().
I'm sorry, but I think this is actually not a good idea.
Tradition is that a function returns <0 (typical -1) in case of problems, and a return code >=0 indicates success (eventually including a useful return value).
It seems that the original call was based on that expectation, too:
net/net.c +0 -1
@@ -305,7 +305,7 @@#ifdef CONFIG_NET_MULTI eth_set_current ();#endif -if (eth_init (bd) <0 ) {
The test for "< 0" reads to me: "if there was an error"...
+ if (eth_init(bd) > 0) {
Now this is completely misleading.
Assuming that eth_init() can only result in sucess or failure, the test should be written either as
if (eth_init(bd) != 0) ... /* error handling */
or be left as is:
if (eth_init(bd) < 0) ... /* error handling */
Actually I strongly prefer the second form which perfectly matches my internal C parser :-)
So the real fix for this problem is to change the code of eth_init() instead and to make it return -1 in case of errors (instead of 1).
Note that all places where eth_init() is called should be checked.
And BTW: please stop posting HTML!
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected] There is an order of things in this universe. -- Apollo, "Who Mourns for Adonais?" stardate 3468.1