2009-03-07 09:27:51

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 1/2] ath5k: constify stuff

Make some structures const to place them in .rodata, since we won't
change them.

Most important parts of objdump -h:
- 0 .text 00011170
+ 0 .text 00011140
- 5 .rodata 0000828e
+ 5 .rodata 0000895e
- 13 .data 00000560
+ 13 .data 00000110
- 14 .devinit.data 00000260

Signed-off-by: Jiri Slaby <[email protected]>
Cc: Nick Kossifidis <[email protected]>
Cc: Luis R. Rodriguez <[email protected]>
Cc: Bob Copeland <[email protected]>
---
drivers/net/wireless/ath5k/attach.c | 13 ++++++-------
drivers/net/wireless/ath5k/base.c | 8 ++++----
drivers/net/wireless/ath5k/debug.c | 10 +++++-----
drivers/net/wireless/ath5k/reset.c | 2 +-
4 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/drivers/net/wireless/ath5k/attach.c b/drivers/net/wireless/ath5k/attach.c
index 05bc5cb..656cb9d 100644
--- a/drivers/net/wireless/ath5k/attach.c
+++ b/drivers/net/wireless/ath5k/attach.c
@@ -34,14 +34,14 @@
static int ath5k_hw_post(struct ath5k_hw *ah)
{

- int i, c;
- u16 cur_reg;
- u16 regs[2] = {AR5K_STA_ID0, AR5K_PHY(8)};
- u32 var_pattern;
- u32 static_pattern[4] = {
+ static const u32 static_pattern[4] = {
0x55555555, 0xaaaaaaaa,
0x66666666, 0x99999999
};
+ static const u16 regs[2] = { AR5K_STA_ID0, AR5K_PHY(8) };
+ int i, c;
+ u16 cur_reg;
+ u32 var_pattern;
u32 init_val;
u32 cur_val;

@@ -106,7 +106,6 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
{
struct ath5k_hw *ah;
struct pci_dev *pdev = sc->pdev;
- u8 mac[ETH_ALEN] = {};
int ret;
u32 srev;

@@ -312,7 +311,7 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
}

/* MAC address is cleared until add_interface */
- ath5k_hw_set_lladdr(ah, mac);
+ ath5k_hw_set_lladdr(ah, (u8[ETH_ALEN]){});

/* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
memset(ah->ah_bssid, 0xff, ETH_ALEN);
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c
index 08d691d..780fe6c 100644
--- a/drivers/net/wireless/ath5k/base.c
+++ b/drivers/net/wireless/ath5k/base.c
@@ -79,7 +79,7 @@ MODULE_VERSION("0.6.0 (EXPERIMENTAL)");


/* Known PCI ids */
-static struct pci_device_id ath5k_pci_id_table[] __devinitdata = {
+static const struct pci_device_id ath5k_pci_id_table[] = {
{ PCI_VDEVICE(ATHEROS, 0x0207), .driver_data = AR5K_AR5210 }, /* 5210 early */
{ PCI_VDEVICE(ATHEROS, 0x0007), .driver_data = AR5K_AR5210 }, /* 5210 */
{ PCI_VDEVICE(ATHEROS, 0x0011), .driver_data = AR5K_AR5211 }, /* 5311 - this is on AHB bus !*/
@@ -103,7 +103,7 @@ static struct pci_device_id ath5k_pci_id_table[] __devinitdata = {
MODULE_DEVICE_TABLE(pci, ath5k_pci_id_table);

/* Known SREVs */
-static struct ath5k_srev_name srev_names[] = {
+static const struct ath5k_srev_name srev_names[] = {
{ "5210", AR5K_VERSION_MAC, AR5K_SREV_AR5210 },
{ "5311", AR5K_VERSION_MAC, AR5K_SREV_AR5311 },
{ "5311A", AR5K_VERSION_MAC, AR5K_SREV_AR5311A },
@@ -142,7 +142,7 @@ static struct ath5k_srev_name srev_names[] = {
{ "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN },
};

-static struct ieee80211_rate ath5k_rates[] = {
+static const struct ieee80211_rate ath5k_rates[] = {
{ .bitrate = 10,
.hw_value = ATH5K_RATE_CODE_1M, },
{ .bitrate = 20,
@@ -248,7 +248,7 @@ static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
struct ieee80211_bss_conf *bss_conf,
u32 changes);

-static struct ieee80211_ops ath5k_hw_ops = {
+static const struct ieee80211_ops ath5k_hw_ops = {
.tx = ath5k_tx,
.start = ath5k_start,
.stop = ath5k_stop,
diff --git a/drivers/net/wireless/ath5k/debug.c b/drivers/net/wireless/ath5k/debug.c
index 413ed68..9770bb3 100644
--- a/drivers/net/wireless/ath5k/debug.c
+++ b/drivers/net/wireless/ath5k/debug.c
@@ -82,14 +82,14 @@ static int ath5k_debugfs_open(struct inode *inode, struct file *file)
/* debugfs: registers */

struct reg {
- char *name;
+ const char *name;
int addr;
};

#define REG_STRUCT_INIT(r) { #r, r }

/* just a few random registers, might want to add more */
-static struct reg regs[] = {
+static const struct reg regs[] = {
REG_STRUCT_INIT(AR5K_CR),
REG_STRUCT_INIT(AR5K_RXDP),
REG_STRUCT_INIT(AR5K_CFG),
@@ -142,7 +142,7 @@ static struct reg regs[] = {

static void *reg_start(struct seq_file *seq, loff_t *pos)
{
- return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
+ return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
}

static void reg_stop(struct seq_file *seq, void *p)
@@ -153,7 +153,7 @@ static void reg_stop(struct seq_file *seq, void *p)
static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
{
++*pos;
- return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
+ return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
}

static int reg_show(struct seq_file *seq, void *p)
@@ -290,7 +290,7 @@ static const struct file_operations fops_reset = {

/* debugfs: debug level */

-static struct {
+static const struct {
enum ath5k_debug_level level;
const char *name;
const char *desc;
diff --git a/drivers/net/wireless/ath5k/reset.c b/drivers/net/wireless/ath5k/reset.c
index 1531ccd..685dc21 100644
--- a/drivers/net/wireless/ath5k/reset.c
+++ b/drivers/net/wireless/ath5k/reset.c
@@ -102,7 +102,7 @@ static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
* index into rates for control rates, we can set it up like this because
* this is only used for AR5212 and we know it supports G mode
*/
-static int control_rates[] =
+static const unsigned int control_rates[] =
{ 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };

/**
--
1.6.1.3


2009-03-07 09:28:13

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 2/2] ath5k: don't change mac in eeprom_read_mac on error

Do not touch mac parameter passed to ath5k_eeprom_read_mac unless
we are sure we have correct address. I.e. when returning error, do
not change it.

While at it, use '= {}' compiler trick for memsetting mac_d.

Signed-off-by: Jiri Slaby <[email protected]>
Cc: Nick Kossifidis <[email protected]>
Cc: Luis R. Rodriguez <[email protected]>
Cc: Bob Copeland <[email protected]>
---
drivers/net/wireless/ath5k/eeprom.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/ath5k/eeprom.c b/drivers/net/wireless/ath5k/eeprom.c
index a54ee7e..ac45ca4 100644
--- a/drivers/net/wireless/ath5k/eeprom.c
+++ b/drivers/net/wireless/ath5k/eeprom.c
@@ -1418,14 +1418,11 @@ ath5k_eeprom_init(struct ath5k_hw *ah)
*/
int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
{
- u8 mac_d[ETH_ALEN];
+ u8 mac_d[ETH_ALEN] = {};
u32 total, offset;
u16 data;
int octet, ret;

- memset(mac, 0, ETH_ALEN);
- memset(mac_d, 0, ETH_ALEN);
-
ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
if (ret)
return ret;
@@ -1441,11 +1438,11 @@ int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
octet += 2;
}

- memcpy(mac, mac_d, ETH_ALEN);
-
if (!total || total == 3 * 0xffff)
return -EINVAL;

+ memcpy(mac, mac_d, ETH_ALEN);
+
return 0;
}

--
1.6.1.3

2009-03-07 12:03:45

by Nick Kossifidis

[permalink] [raw]
Subject: Re: [PATCH 1/2] ath5k: constify stuff

2009/3/7 Jiri Slaby <[email protected]>:
> Make some structures const to place them in .rodata, since we won't
> change them.
>
> Most important parts of objdump -h:
> -  0 .text         00011170
> +  0 .text         00011140
> -  5 .rodata       0000828e
> +  5 .rodata       0000895e
> - 13 .data         00000560
> + 13 .data         00000110
> - 14 .devinit.data 00000260
>
> Signed-off-by: Jiri Slaby <[email protected]>
> Cc: Nick Kossifidis <[email protected]>
> Cc: Luis R. Rodriguez <[email protected]>
> Cc: Bob Copeland <[email protected]>
> ---
>  drivers/net/wireless/ath5k/attach.c |   13 ++++++-------
>  drivers/net/wireless/ath5k/base.c   |    8 ++++----
>  drivers/net/wireless/ath5k/debug.c  |   10 +++++-----
>  drivers/net/wireless/ath5k/reset.c  |    2 +-
>  4 files changed, 16 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/net/wireless/ath5k/attach.c b/drivers/net/wireless/ath5k/attach.c
> index 05bc5cb..656cb9d 100644
> --- a/drivers/net/wireless/ath5k/attach.c
> +++ b/drivers/net/wireless/ath5k/attach.c
> @@ -34,14 +34,14 @@
>  static int ath5k_hw_post(struct ath5k_hw *ah)
>  {
>
> -       int i, c;
> -       u16 cur_reg;
> -       u16 regs[2] = {AR5K_STA_ID0, AR5K_PHY(8)};
> -       u32 var_pattern;
> -       u32 static_pattern[4] = {
> +       static const u32 static_pattern[4] = {
>                0x55555555,     0xaaaaaaaa,
>                0x66666666,     0x99999999
>        };
> +       static const u16 regs[2] = { AR5K_STA_ID0, AR5K_PHY(8) };
> +       int i, c;
> +       u16 cur_reg;
> +       u32 var_pattern;
>        u32 init_val;
>        u32 cur_val;
>
> @@ -106,7 +106,6 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
>  {
>        struct ath5k_hw *ah;
>        struct pci_dev *pdev = sc->pdev;
> -       u8 mac[ETH_ALEN] = {};
>        int ret;
>        u32 srev;
>
> @@ -312,7 +311,7 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
>        }
>
>        /* MAC address is cleared until add_interface */
> -       ath5k_hw_set_lladdr(ah, mac);
> +       ath5k_hw_set_lladdr(ah, (u8[ETH_ALEN]){});
>
>        /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
>        memset(ah->ah_bssid, 0xff, ETH_ALEN);
> diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c
> index 08d691d..780fe6c 100644
> --- a/drivers/net/wireless/ath5k/base.c
> +++ b/drivers/net/wireless/ath5k/base.c
> @@ -79,7 +79,7 @@ MODULE_VERSION("0.6.0 (EXPERIMENTAL)");
>
>
>  /* Known PCI ids */
> -static struct pci_device_id ath5k_pci_id_table[] __devinitdata = {
> +static const struct pci_device_id ath5k_pci_id_table[] = {
>        { PCI_VDEVICE(ATHEROS, 0x0207), .driver_data = AR5K_AR5210 }, /* 5210 early */
>        { PCI_VDEVICE(ATHEROS, 0x0007), .driver_data = AR5K_AR5210 }, /* 5210 */
>        { PCI_VDEVICE(ATHEROS, 0x0011), .driver_data = AR5K_AR5211 }, /* 5311 - this is on AHB bus !*/
> @@ -103,7 +103,7 @@ static struct pci_device_id ath5k_pci_id_table[] __devinitdata = {
>  MODULE_DEVICE_TABLE(pci, ath5k_pci_id_table);
>
>  /* Known SREVs */
> -static struct ath5k_srev_name srev_names[] = {
> +static const struct ath5k_srev_name srev_names[] = {
>        { "5210",       AR5K_VERSION_MAC,       AR5K_SREV_AR5210 },
>        { "5311",       AR5K_VERSION_MAC,       AR5K_SREV_AR5311 },
>        { "5311A",      AR5K_VERSION_MAC,       AR5K_SREV_AR5311A },
> @@ -142,7 +142,7 @@ static struct ath5k_srev_name srev_names[] = {
>        { "xxxxx",      AR5K_VERSION_RAD,       AR5K_SREV_UNKNOWN },
>  };
>
> -static struct ieee80211_rate ath5k_rates[] = {
> +static const struct ieee80211_rate ath5k_rates[] = {
>        { .bitrate = 10,
>          .hw_value = ATH5K_RATE_CODE_1M, },
>        { .bitrate = 20,
> @@ -248,7 +248,7 @@ static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
>                struct ieee80211_bss_conf *bss_conf,
>                u32 changes);
>
> -static struct ieee80211_ops ath5k_hw_ops = {
> +static const struct ieee80211_ops ath5k_hw_ops = {
>        .tx             = ath5k_tx,
>        .start          = ath5k_start,
>        .stop           = ath5k_stop,
> diff --git a/drivers/net/wireless/ath5k/debug.c b/drivers/net/wireless/ath5k/debug.c
> index 413ed68..9770bb3 100644
> --- a/drivers/net/wireless/ath5k/debug.c
> +++ b/drivers/net/wireless/ath5k/debug.c
> @@ -82,14 +82,14 @@ static int ath5k_debugfs_open(struct inode *inode, struct file *file)
>  /* debugfs: registers */
>
>  struct reg {
> -       char *name;
> +       const char *name;
>        int addr;
>  };
>
>  #define REG_STRUCT_INIT(r) { #r, r }
>
>  /* just a few random registers, might want to add more */
> -static struct reg regs[] = {
> +static const struct reg regs[] = {
>        REG_STRUCT_INIT(AR5K_CR),
>        REG_STRUCT_INIT(AR5K_RXDP),
>        REG_STRUCT_INIT(AR5K_CFG),
> @@ -142,7 +142,7 @@ static struct reg regs[] = {
>
>  static void *reg_start(struct seq_file *seq, loff_t *pos)
>  {
> -       return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
> +       return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
>  }
>
>  static void reg_stop(struct seq_file *seq, void *p)
> @@ -153,7 +153,7 @@ static void reg_stop(struct seq_file *seq, void *p)
>  static void *reg_next(struct seq_file *seq, void *p, loff_t *pos)
>  {
>        ++*pos;
> -       return *pos < ARRAY_SIZE(regs) ? &regs[*pos] : NULL;
> +       return *pos < ARRAY_SIZE(regs) ? (void *)&regs[*pos] : NULL;
>  }
>
>  static int reg_show(struct seq_file *seq, void *p)
> @@ -290,7 +290,7 @@ static const struct file_operations fops_reset = {
>
>  /* debugfs: debug level */
>
> -static struct {
> +static const struct {
>        enum ath5k_debug_level level;
>        const char *name;
>        const char *desc;
> diff --git a/drivers/net/wireless/ath5k/reset.c b/drivers/net/wireless/ath5k/reset.c
> index 1531ccd..685dc21 100644
> --- a/drivers/net/wireless/ath5k/reset.c
> +++ b/drivers/net/wireless/ath5k/reset.c
> @@ -102,7 +102,7 @@ static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
>  * index into rates for control rates, we can set it up like this because
>  * this is only used for AR5212 and we know it supports G mode
>  */
> -static int control_rates[] =
> +static const unsigned int control_rates[] =
>        { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
>
>  /**

Acked-by: Nick Kossifidis <[email protected]>



--
GPG ID: 0xD21DB2DB
As you read this post global entropy rises. Have Fun ;-)
Nick

2009-03-07 12:06:21

by Nick Kossifidis

[permalink] [raw]
Subject: Re: [ath5k-devel] [PATCH 2/2] ath5k: don't change mac in eeprom_read_mac on error

2009/3/7 Jiri Slaby <[email protected]>:
> Do not touch mac parameter passed to ath5k_eeprom_read_mac unless
> we are sure we have correct address. I.e. when returning error, do
> not change it.
>
> While at it, use '= {}' compiler trick for memsetting mac_d.
>
> Signed-off-by: Jiri Slaby <[email protected]>
> Cc: Nick Kossifidis <[email protected]>
> Cc: Luis R. Rodriguez <[email protected]>
> Cc: Bob Copeland <[email protected]>
> ---
>  drivers/net/wireless/ath5k/eeprom.c |    9 +++------
>  1 files changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/wireless/ath5k/eeprom.c b/drivers/net/wireless/ath5k/eeprom.c
> index a54ee7e..ac45ca4 100644
> --- a/drivers/net/wireless/ath5k/eeprom.c
> +++ b/drivers/net/wireless/ath5k/eeprom.c
> @@ -1418,14 +1418,11 @@ ath5k_eeprom_init(struct ath5k_hw *ah)
>  */
>  int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
>  {
> -       u8 mac_d[ETH_ALEN];
> +       u8 mac_d[ETH_ALEN] = {};
>        u32 total, offset;
>        u16 data;
>        int octet, ret;
>
> -       memset(mac, 0, ETH_ALEN);
> -       memset(mac_d, 0, ETH_ALEN);
> -
>        ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
>        if (ret)
>                return ret;
> @@ -1441,11 +1438,11 @@ int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
>                octet += 2;
>        }
>
> -       memcpy(mac, mac_d, ETH_ALEN);
> -
>        if (!total || total == 3 * 0xffff)
>                return -EINVAL;
>
> +       memcpy(mac, mac_d, ETH_ALEN);
> +
>        return 0;
>  }
>

Acked-by: Nick Kossifidis <[email protected]>


--
GPG ID: 0xD21DB2DB
As you read this post global entropy rises. Have Fun ;-)
Nick

2009-03-07 12:35:18

by Bob Copeland

[permalink] [raw]
Subject: Re: [PATCH 2/2] ath5k: don't change mac in eeprom_read_mac on error

On Sat, Mar 07, 2009 at 10:26:42AM +0100, Jiri Slaby wrote:
> Do not touch mac parameter passed to ath5k_eeprom_read_mac unless
> we are sure we have correct address. I.e. when returning error, do
> not change it.
>
> While at it, use '= {}' compiler trick for memsetting mac_d.
>
> Signed-off-by: Jiri Slaby <[email protected]>
> Cc: Nick Kossifidis <[email protected]>

Wrong email address for Nick :) Otherwise,

Acked-by: Bob Copeland <[email protected]>

--
Bob Copeland %% http://www.bobcopeland.com