All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ladislav Michl <Ladislav.Michl@seznam.cz>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/5] NetStar: eeprom - undefined reference to `memset'
Date: Thu, 28 Jan 2010 00:18:24 +0100	[thread overview]
Message-ID: <20100127231824.GB18557@localhost.localdomain> (raw)
In-Reply-To: <20100127231620.GA18557@localhost.localdomain>

From: Ladislav Michl <ladis@linux-mips.org>

Defining partially initialized struct eth_device on stack means
gcc has to zero out it, and some gcc versions optimize this with
an implicit call to memset. Move definition to data section
to avoid that (it has also nice side effect that we need not
to pass it to helper functions anymore)

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 board/netstar/eeprom.c |   61 +++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/board/netstar/eeprom.c b/board/netstar/eeprom.c
index adb01b9..ef530a3 100644
--- a/board/netstar/eeprom.c
+++ b/board/netstar/eeprom.c
@@ -28,40 +28,43 @@
 #include <net.h>
 #include "../drivers/net/smc91111.h"
 
-static u16 read_eeprom_reg(struct eth_device *dev, u16 reg)
+static struct eth_device dev = {
+	.iobase = CONFIG_SMC91111_BASE
+};
+
+static u16 read_eeprom_reg(u16 reg)
 {
 	int timeout;
 
-	SMC_SELECT_BANK(dev, 2);
-	SMC_outw(dev, reg, PTR_REG);
+	SMC_SELECT_BANK(&dev, 2);
+	SMC_outw(&dev, reg, PTR_REG);
 
-	SMC_SELECT_BANK(dev, 1);
-	SMC_outw(dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT | CTL_RELOAD,
-		 CTL_REG);
+	SMC_SELECT_BANK(&dev, 1);
+	SMC_outw(&dev, SMC_inw(&dev, CTL_REG) | CTL_EEPROM_SELECT | CTL_RELOAD, CTL_REG);
 	timeout = 100;
-	while((SMC_inw (dev, CTL_REG) & CTL_RELOAD) && --timeout)
+	while ((SMC_inw(&dev, CTL_REG) & CTL_RELOAD) && --timeout)
 		udelay(100);
 	if (timeout == 0) {
 		printf("Timeout Reading EEPROM register %02x\n", reg);
 		return 0;
 	}
 
-	return SMC_inw (dev, GP_REG);
+	return SMC_inw(&dev, GP_REG);
 }
 
-static int write_eeprom_reg(struct eth_device *dev, u16 value, u16 reg)
+static int write_eeprom_reg(u16 value, u16 reg)
 {
 	int timeout;
 
-	SMC_SELECT_BANK(dev, 2);
-	SMC_outw(dev, reg, PTR_REG);
+	SMC_SELECT_BANK(&dev, 2);
+	SMC_outw(&dev, reg, PTR_REG);
 
-	SMC_SELECT_BANK(dev, 1);
-	SMC_outw(dev, value, GP_REG);
-	SMC_outw(dev, SMC_inw (dev, CTL_REG) | CTL_EEPROM_SELECT | CTL_STORE, CTL_REG);
+	SMC_SELECT_BANK(&dev, 1);
+	SMC_outw(&dev, value, GP_REG);
+	SMC_outw(&dev, SMC_inw(&dev, CTL_REG) | CTL_EEPROM_SELECT | CTL_STORE, CTL_REG);
 	timeout = 100;
-	while ((SMC_inw(dev, CTL_REG) & CTL_STORE) && --timeout)
-		udelay (100);
+	while ((SMC_inw(&dev, CTL_REG) & CTL_STORE) && --timeout)
+		udelay(100);
 	if (timeout == 0) {
 		printf("Timeout Writing EEPROM register %02x\n", reg);
 		return 0;
@@ -70,17 +73,17 @@ static int write_eeprom_reg(struct eth_device *dev, u16 value, u16 reg)
 	return 1;
 }
 
-static int write_data(struct eth_device *dev, u16 *buf, int len)
+static int write_data(u16 *buf, int len)
 {
 	u16 reg = 0x23;
 
 	while (len--)
-		write_eeprom_reg(dev, *buf++, reg++);
+		write_eeprom_reg(*buf++, reg++);
 
 	return 0;
 }
 
-static int verify_macaddr(struct eth_device *dev, char *s)
+static int verify_macaddr(char *s)
 {
 	u16 reg;
 	int i, err = 0;
@@ -88,7 +91,7 @@ static int verify_macaddr(struct eth_device *dev, char *s)
 	printf("MAC Address: ");
 	err = i = 0;
 	for (i = 0; i < 3; i++) {
-		reg = read_eeprom_reg(dev, 0x20 + i);
+		reg = read_eeprom_reg(0x20 + i);
 		printf("%02x:%02x%c", reg & 0xff, reg >> 8, i != 2 ? ':' : '\n');
 		if (s)
 			err |= reg != ((u16 *)s)[i];
@@ -97,7 +100,7 @@ static int verify_macaddr(struct eth_device *dev, char *s)
 	return err ? 0 : 1;
 }
 
-static int set_mac(struct eth_device *dev, char *s)
+static int set_mac(char *s)
 {
 	int i;
 	char *e, eaddr[6];
@@ -109,7 +112,7 @@ static int set_mac(struct eth_device *dev, char *s)
 	}
 
 	for (i = 0; i < 3; i++)
-		write_eeprom_reg(dev, *(((u16 *)eaddr) + i), 0x20 + i);
+		write_eeprom_reg(*(((u16 *)eaddr) + i), 0x20 + i);
 
 	return 0;
 }
@@ -145,10 +148,6 @@ int eeprom(int argc, char *argv[])
 	int i, len, ret;
 	unsigned char buf[58], *p;
 
-	struct eth_device dev = {
-		.iobase = CONFIG_SMC91111_BASE
-	};
-
 	app_startup(argv);
 	if (get_version() != XF_VERSION) {
 		printf("Wrong XF_VERSION.\n");
@@ -157,14 +156,14 @@ int eeprom(int argc, char *argv[])
 		return 1;
 	}
 
-	if ((SMC_inw (&dev, BANK_SELECT) & 0xFF00) != 0x3300) {
+	if ((SMC_inw(&dev, BANK_SELECT) & 0xFF00) != 0x3300) {
 		printf("SMSC91111 not found.\n");
 		return 2;
 	}
 
 	/* Called without parameters - print MAC address */
 	if (argc < 2) {
-		verify_macaddr(&dev, NULL);
+		verify_macaddr(NULL);
 		return 0;
 	}
 
@@ -198,8 +197,8 @@ int eeprom(int argc, char *argv[])
 	}
 
 	/* First argument (MAC) is mandatory */
-	set_mac(&dev, argv[1]);
-	if (verify_macaddr(&dev, argv[1])) {
+	set_mac(argv[1]);
+	if (verify_macaddr(argv[1])) {
 		printf("*** MAC address does not match! ***\n");
 		return 4;
 	}
@@ -207,7 +206,7 @@ int eeprom(int argc, char *argv[])
 	while (len--)
 		*p++ = 0;
 
-	write_data(&dev, (u16 *)buf, sizeof(buf) >> 1);
+	write_data((u16 *)buf, sizeof(buf) >> 1);
 
 	return 0;
 }
-- 
1.5.3.8

  reply	other threads:[~2010-01-27 23:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-27 23:16 [U-Boot] [PATCH 0/5] NetStar updates Ladislav Michl
2010-01-27 23:18 ` Ladislav Michl [this message]
2010-01-27 23:19 ` [U-Boot] [PATCH 2/5] NetStar: eeprom - be less verbose Ladislav Michl
2010-01-27 23:20 ` [U-Boot] [PATCH 3/5] NetStar: eeprom - fix linker error Ladislav Michl
2010-01-27 23:21 ` [U-Boot] [PATCH 4/5] NetStar: fix default environment Ladislav Michl
2010-01-27 23:22 ` [U-Boot] [PATCH 5/5] NetStar: make mtdparts default ready for recent kernels Ladislav Michl
2010-02-08 16:55 ` [U-Boot] [PATCH 0/5] NetStar updates Paulraj, Sandeep
2010-02-08 18:39   ` Ladislav Michl
2010-02-08 19:21     ` Paulraj, Sandeep
2010-02-08 21:41       ` Ladislav Michl
2010-02-08 20:45         ` Paulraj, Sandeep
2010-02-09  9:12         ` [U-Boot] [PATCH] netstar.h: do not exceed 80 columns Ladislav Michl
2010-02-18  2:22           ` Paulraj, Sandeep

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=20100127231824.GB18557@localhost.localdomain \
    --to=ladislav.michl@seznam.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.