Skip to contentSkip to conversation

smc911x driver: cleanup smc911x_initialize()

PATCH New Matthias Kaehlcke 3 participants 5 messages Jan 21, 2010 – Jan 22, 2010 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smc911x driver: cleanup smc911x_initialize()

smc911x_initialize(): remove unecessary call to free() and return 0 in case of failure instead of -1

---
 drivers/net/smc911x.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/smc911x.c +1 -2
index 5d51406..f2b5895 100644
@@ -242,8 +242,7 @@ int smc911x_initialize(u8 dev_num, int base_addr)
 
 	dev = malloc(sizeof(*dev));
 	if (!dev) {
-		free(dev);
-		return -1;
+		return 0;
 	}
 	memset(dev, 0, sizeof(*dev));
 
Signature · 1 line
1.6.3.1
#1 lore raw

PATCH 1/1 smc911x driver: cleanup smc911x_initialize()

Quoted 13 lines · On Thursday 21 January 2010 16:29:24 Matthias Kaehlcke wrote:

smc911x_initialize(): remove unecessary call to free() and return 0 in case of failure instead of -1

---
 drivers/net/smc911x.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/smc911x.c +0 -0
index 5d51406..f2b5895 100644

drivers/net/smc911x.c int smc911x_initialize(u8 dev_num, int base_addr) · line 245

Quoted 4 lines
drivers/net/smc911x.c +0 -1
@@ -242,8 +242,7 @@ int smc911x_initialize(u8 dev_num, int base_addr)
 
 	dev = malloc(sizeof(*dev));
 	if (!dev) {
-		free(dev);

OK

drivers/net/smc911x.c int smc911x_initialize(u8 dev_num, int base_addr) · line 245

Quoted 2 lines
drivers/net/smc911x.c +1 -1
-		return -1;
+		return 0;

this is an error path, so i think -1 is correct. if you're out of memory, increase your malloc region.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20100121/1b4583b7/attachment.pgp

#2 lore raw

PATCH 1/1 smc911x driver: cleanup smc911x_initialize()

hi mike,

El Thu, Jan 21, 2010 at 06:01:47PM -0500 Mike Frysinger ha dit:

Quoted 21 lines · On Thursday 21 January 2010 16:29:24 Matthias Kaehlcke wrote:
Quoted 13 lines

smc911x_initialize(): remove unecessary call to free() and return 0 in case of failure instead of -1

---
 drivers/net/smc911x.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/smc911x.c +0 -0
index 5d51406..f2b5895 100644

drivers/net/smc911x.c int smc911x_initialize(u8 dev_num, int base_addr) · line 245

Quoted 4 lines
drivers/net/smc911x.c +0 -1
@@ -242,8 +242,7 @@ int smc911x_initialize(u8 dev_num, int base_addr)
 
 	dev = malloc(sizeof(*dev));
 	if (!dev) {
-		free(dev);

OK

Quoted 5 lines

drivers/net/smc911x.c int smc911x_initialize(u8 dev_num, int base_addr) · line 245

Quoted 2 lines
drivers/net/smc911x.c +1 -1
-		return -1;
+		return 0;

this is an error path, so i think -1 is correct. if you're out of memory, increase your malloc region.

that's what I thought in the first place, but Ben Warren told me that in the initialize function the return value indicates the number of devices that were initialized (see
http://lists.denx.de/pipermail/u-boot/2010-January/066859.html)

best regards

Signature · 12 lines
Matthias Kaehlcke
Embedded Linux Developer
Barcelona

                Don't walk behind me, I may not lead
             Don't walk in front of me, I may not follow
                Just walk beside me and be my friend
                          (Albert Camus)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-
#3 lore raw

PATCH 1/1 smc911x driver: cleanup smc911x_initialize()

Hi Matthias,

Quoted 30 lines · Matthias Kaehlcke

hi mike,

El Thu, Jan 21, 2010 at 06:01:47PM -0500 Mike Frysinger ha dit:

Quoted 21 lines · On Thursday 21 January 2010 16:29:24 Matthias Kaehlcke wrote:
Quoted 13 lines

smc911x_initialize(): remove unecessary call to free() and return 0 in case of failure instead of -1

---
 drivers/net/smc911x.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/net/smc911x.c +0 -0
index 5d51406..f2b5895 100644

drivers/net/smc911x.c int smc911x_initialize(u8 dev_num, int base_addr) · line 245

Quoted 4 lines
drivers/net/smc911x.c +0 -1
@@ -242,8 +242,7 @@ int smc911x_initialize(u8 dev_num, int base_addr)
 
    dev = malloc(sizeof(*dev));
    if (!dev) {
-           free(dev);

OK

Quoted 4 lines

drivers/net/smc911x.c int smc911x_initialize(u8 dev_num, int base_addr) · line 245

Quoted 2 lines
drivers/net/smc911x.c +1 -1
-           return -1;
+           return 0;

this is an error path, so i think -1 is correct. if you're out of

memory,

Quoted 8 lines
Quoted 1 line

increase your malloc region.

that's what I thought in the first place, but Ben Warren told me that in the initialize function the return value indicates the number of devices that were initialized (see
http://lists.denx.de/pipermail/u-boot/2010-January/066859.html)

I agree that this is confusing. If the following xxx_eth_initialize()

return codes seem reasonable, I'll send a patch tomorrow that applies it to the logic in net/eth.c:

-2: reserved (magic value, used to return from __def_eth_init()) -1: error
0: no devices added, no error
1+: number of devices added

best regards

Quoted 7 lines

--
Matthias Kaehlcke
Embedded Linux Developer
Barcelona

regards,

Ben

#4 lore raw

PATCH 1/1 smc911x driver: cleanup smc911x_initialize()

Hi Ben,

El Thu, Jan 21, 2010 at 11:36:41PM -0800 Ben Warren ha dit:

Quoted 38 lines
   On Thu, Jan 21, 2010 at 10:18 PM, Matthias Kaehlcke
   <[email protected]> wrote:

     El Thu, Jan 21, 2010 at 06:01:47PM -0500 Mike Frysinger ha dit:
     > On Thursday 21 January 2010 16:29:24 Matthias Kaehlcke wrote:
     > > smc911x_initialize(): remove unecessary call to free() and
     > > return 0 in case of failure instead of -1
     > >
     > > Signed-off-by: Matthias Kaehlcke <[email protected]>
     > > ---
     > >  drivers/net/smc911x.c |    3 +--
     > >  1 files changed, 1 insertions(+), 2 deletions(-)
     > >
     > > diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
     > > index 5d51406..f2b5895 100644
     > > --- a/drivers/net/smc911x.c
     > > +++ b/drivers/net/smc911x.c
     > > @@ -242,8 +242,7 @@ int smc911x_initialize(u8 dev_num, int
     base_addr)
     > >
     > >     dev = malloc(sizeof(*dev));
     > >     if (!dev) {
     > > -           free(dev);
     >
     > OK
     >
     > > -           return -1;
     > > +           return 0;
     >
     > this is an error path, so i think -1 is correct.  if you're out of
     memory,
     > increase your malloc region.

     that's what I thought in the first place, but Ben Warren told me that
     in the initialize function the return value indicates the number of
     devices that were initialized (see
     http://lists.denx.de/pipermail/u-boot/2010-January/066859.html)
Quoted 7 lines
   I agree that this is confusing.  If the following xxx_eth_initialize()
   return codes seem reasonable, I'll send a patch tomorrow that applies it
   to the logic in net/eth.c:
   -2: reserved (magic value, used to return from __def_eth_init())
   -1: error
   0: no devices added, no error
   1+: number of devices added

to me it seems reasonable and less confusing than the current logic.

i can collaborate in the task of applying it to the driver code

Signature · 11 lines
Matthias Kaehlcke
Embedded Linux Developer
Barcelona

  Control over the use of one's ideas really constitutes control over other
  people's lives; and it is usually used to make their lives more difficult.
                          (Richard Stallman)
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-