From: Wolfgang Denk Date: Fri, 16 Nov 2007 17:35:30 +0100 Subject: [U-Boot-Users] What if eth_init() fails? In-Reply-To: Your message of "Fri, 16 Nov 2007 11:43:43 +0530." Message-ID: <20071116163530.6AD0A24888@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Upakul, in message you wrote: > > 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: --- u-boot-1.2.0_orig/net/net.c 2007-01-07 04:43:11.000000000 +0530 +++ u-boot-1.2.0/net/net.c 2007-11-14 18:03:03.000000000 +0530 @@ -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 -- 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: wd@denx.de There is an order of things in this universe. -- Apollo, "Who Mourns for Adonais?" stardate 3468.1