Skip to contentSkip to conversation

net: e1000: Add initialized eth_device & e1000_hw structure

PATCH New Kumar Gala 4 participants 6 messages Nov 12, 2010 – Nov 17, 2010 Network drivers

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 net: e1000: Add initialized eth_device & e1000_hw structure

nic and hw structures are allocated via malloc i.e. return memory is not zero initialized. Because of this few structure member like "function pointers" are initialized with garbage values.

It may cause problem. for eg. during eth_initialize, dev->write_hwaddr is used.

---
 drivers/net/e1000.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
drivers/net/e1000.c +14 -0
index 2825342..911eb2c 100644
@@ -5177,7 +5177,21 @@ e1000_initialize(bd_t * bis)
 		}
 
 		nic = (struct eth_device *) malloc(sizeof (*nic));
+		if (!nic) {
+			printf("Error: e1000 - Can not alloc memory\n");
+			return 0;
+		}
+
 		hw = (struct e1000_hw *) malloc(sizeof (*hw));
+		if (!nic) {
+			free(nic);
+			printf("Error: e1000 - Can not alloc memory\n");
+			return 0;
+		}
+
+		memset(nic, 0, sizeof(*dev));
+		memset(hw, 0, sizeof(*hw));
+
 		hw->pdev = devno;
 		nic->priv = hw;
 
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/1 net: e1000: Add initialized eth_device & e1000_hw structure

Quoted 17 lines · Kumar Gala

nic and hw structures are allocated via malloc i.e. return memory is not zero initialized. Because of this few structure member like "function pointers" are initialized with garbage values.

It may cause problem. for eg. during eth_initialize, dev->write_hwaddr is used.

---
?drivers/net/e1000.c | ? 14 ++++++++++++++ ?1 files changed, 14 insertions(+), 0 deletions(-)

drivers/net/e1000.c +0 -0
index 2825342..911eb2c 100644

drivers/net/e1000.c e1000_initialize(bd_t * bis) · line 5186

Quoted 10 lines
drivers/net/e1000.c +6 -0
@@ -5177,7 +5177,21 @@ e1000_initialize(bd_t * bis)
 ? ? ? ? ? ? ? ?}
 
 ? ? ? ? ? ? ? ?nic = (struct eth_device *) malloc(sizeof (*nic));
+ ? ? ? ? ? ? ? if (!nic) {
+ ? ? ? ? ? ? ? ? ? ? ? printf("Error: e1000 - Can not alloc memory\n");
+ ? ? ? ? ? ? ? ? ? ? ? return 0;
+ ? ? ? ? ? ? ? }
+
 ? ? ? ? ? ? ? ?hw = (struct e1000_hw *) malloc(sizeof (*hw));
+ ? ? ? ? ? ? ? if (!nic) {

Copy and paste error, I think you want "if (!hw)"

Paul.

Quoted 19 lines
drivers/net/e1000.c +8 -1
+ ? ? ? ? ? ? ? ? ? ? ? free(nic);
+ ? ? ? ? ? ? ? ? ? ? ? printf("Error: e1000 - Can not alloc memory\n");
+ ? ? ? ? ? ? ? ? ? ? ? return 0;
+ ? ? ? ? ? ? ? }
+
+ ? ? ? ? ? ? ? memset(nic, 0, sizeof(*dev));
+ ? ? ? ? ? ? ? memset(hw, 0, sizeof(*hw));
+
 ? ? ? ? ? ? ? ?hw->pdev = devno;
 ? ? ? ? ? ? ? ?nic->priv = hw;
 
--

1.7.2.3

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#2 lore raw

PATCH 1/1 net: e1000: Add initialized eth_device & e1000_hw structure

In reply to Kumar Gala

Dear Kumar Gala,

Quoted 17 lines · In message <[email protected]> you…

nic and hw structures are allocated via malloc i.e. return memory is not zero initialized. Because of this few structure member like "function pointers" are initialized with garbage values.

It may cause problem. for eg. during eth_initialize, dev->write_hwaddr is used.

---
 drivers/net/e1000.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
drivers/net/e1000.c +0 -0
index 2825342..911eb2c 100644

drivers/net/e1000.c e1000_initialize(bd_t * bis) · line 5186

Quoted 10 lines
drivers/net/e1000.c +6 -0
@@ -5177,7 +5177,21 @@ e1000_initialize(bd_t * bis)
 		}
 
 		nic = (struct eth_device *) malloc(sizeof (*nic));
+		if (!nic) {
+			printf("Error: e1000 - Can not alloc memory\n");
+			return 0;
+		}
+
 		hw = (struct e1000_hw *) malloc(sizeof (*hw));
+		if (!nic) {

--------------------^^^^ !hw

Applied after fixing the typo.

Thanks.

Best regards,

Wolfgang Denk

Signature · 6 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: wd at denx.de
The more complex the mind, the greater the need for the simplicity of
play.
	-- Kirk, "Shore Leave", stardate 3025.8
author
#3 lore raw

PATCH 1/1 net: e1000: Add initialized eth_device & e1000_hw structure

Quoted 32 lines · Wolfgang Denk

Dear Kumar Gala,

Quoted 17 lines · In message <[email protected]> you…

nic and hw structures are allocated via malloc i.e. return memory is not zero initialized. Because of this few structure member like "function pointers" are initialized with garbage values.

It may cause problem. for eg. during eth_initialize, dev->write_hwaddr is used.

---
drivers/net/e1000.c | 14 ++++++++++++++

1 files changed, 14 insertions(+), 0 deletions(-)
drivers/net/e1000.c +0 -0
index 2825342..911eb2c 100644

drivers/net/e1000.c e1000_initialize(bd_t * bis) · line 5186

Quoted 10 lines
drivers/net/e1000.c +6 -0
@@ -5177,7 +5177,21 @@ e1000_initialize(bd_t * bis)
 		}
 
 		nic = (struct eth_device *) malloc(sizeof (*nic));
+		if (!nic) {
+			printf("Error: e1000 - Can not alloc memory\n");
+			return 0;
+		}
+
 		hw = (struct e1000_hw *) malloc(sizeof (*hw));
+		if (!nic) {

--------------------^^^^ !hw

Quoted 1 line

Applied after fixing the typo.

Thanks ;)

- k

#4 lore raw

PATCH 1/1 net: e1000: typo using wrong argument to sizeof

Typo from 4b29bdb0ed08412d225a8be94f61fc6c37a59dd5

---
 drivers/net/e1000.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/e1000.c +1 -1
index 18584ef..60b04c2 100644
@@ -5189,7 +5189,7 @@ e1000_initialize(bd_t * bis)
 			return 0;
 		}
 
-		memset(nic, 0, sizeof(*dev));
+		memset(nic, 0, sizeof(*nic));
 		memset(hw, 0, sizeof(*hw));
 
 		hw->pdev = devno;
Signature · 1 line
1.6.6.1
#5 lore raw

PATCH 1/1 net: e1000: typo using wrong argument to sizeof

Dear Matthew McClintock,

Quoted 6 lines · In message <[email protected]> you wrote:

Typo from 4b29bdb0ed08412d225a8be94f61fc6c37a59dd5

---
 drivers/net/e1000.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Applied, thanks.

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: wd at denx.de
"A child is a person who can't understand why someone would give away
a perfectly good kitten."                               - Doug Larson