public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] What if eth_init() fails?
Date: Fri, 16 Nov 2007 17:35:30 +0100	[thread overview]
Message-ID: <20071116163530.6AD0A24888@gemini.denx.de> (raw)
In-Reply-To: Your message of "Fri, 16 Nov 2007 11:43:43 +0530." <bb58ac4d0711152213y4e4520ay44ae0b9d5302b9c2@mail.gmail.com>

Dear Upakul,

in message <bb58ac4d0711152213y4e4520ay44ae0b9d5302b9c2@mail.gmail.com> 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

  parent reply	other threads:[~2007-11-16 16:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-14  6:21 [U-Boot-Users] What if eth_init() fails? Upakul Barkakaty
2007-11-14 11:07 ` Detlev Zundel
2007-11-16  6:13   ` Upakul Barkakaty
2007-11-16 12:29     ` Detlev Zundel
2007-11-16 16:27       ` Detlev Zundel
2007-11-16 16:35     ` Wolfgang Denk [this message]
2007-11-14 15:08 ` Ben Warren
2007-11-14 15:24 ` Timur Tabi
2007-11-14 16:49   ` Mike Frysinger
2007-11-14 16:53     ` Timur Tabi
2007-11-14 17:00       ` Mike Frysinger
  -- strict thread matches above, loose matches on Subject: below --
2007-11-19  4:37 Upakul Barkakaty
2007-11-19 13:26 ` Wolfgang Denk

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=20071116163530.6AD0A24888@gemini.denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /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