2009-12-14 00:18:30

by Emese Revfy

[permalink] [raw]
Subject: [PATCH 0/3] constify various _ops structures for net-next-dave-git-a252e7

From: Emese Revfy <[email protected]>

Hello everyone!

The following patch series attempts to constify several structures
that hold function pointers. This is only the initial batch, there
are other candidate structures, some of which can probably be
constified as well, I plan to submit them in the future.

The list of constified structures in this series:
e1000_mac_operations
e1000_phy_operations
e1000_nvm_operations

There are certain exceptions where a given instance of the structure
cannot be const, they are marked with a comment in the patch.

The patches compile fine with an allyesconfig kernel on i386 and x86_64.

Please let me know if any of these structures should not be constified
and any other issues you see with them.


Changelog:
----------
v1 -> v2
- updated to net-next-dave-git-a252e7
- extended comments with a reference to code that prevents constification

Thanks,
Emese

drivers/net/e1000e/82571.c | 11 ++++++-----
drivers/net/e1000e/e1000.h | 6 +++---
drivers/net/e1000e/es2lan.c | 7 ++++---
drivers/net/e1000e/hw.h | 18 ++++++++++--------
drivers/net/e1000e/ich8lan.c | 6 +++---
drivers/net/igb/e1000_82575.c | 6 +++---
drivers/net/igb/e1000_hw.h | 7 +++++--
drivers/net/igbvf/vf.h | 1 +
8 files changed, 35 insertions(+), 27 deletions(-)


2009-12-14 00:16:47

by Emese Revfy

[permalink] [raw]
Subject: [PATCH 1/3] Constify struct e1000_mac_operations 2.6.32-git-a252e7 v2

From: Emese Revfy <[email protected]>


Signed-off-by: Emese Revfy <[email protected]>
---
drivers/net/e1000e/82571.c | 3 ++-
drivers/net/e1000e/e1000.h | 2 +-
drivers/net/e1000e/es2lan.c | 3 ++-
drivers/net/e1000e/hw.h | 1 +
drivers/net/e1000e/ich8lan.c | 2 +-
drivers/net/igb/e1000_82575.c | 2 +-
drivers/net/igb/e1000_hw.h | 3 ++-
drivers/net/igbvf/vf.h | 1 +
8 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
index c1a42cf..f388cba 100644
--- a/drivers/net/e1000e/82571.c
+++ b/drivers/net/e1000e/82571.c
@@ -207,6 +207,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
{
struct e1000_hw *hw = &adapter->hw;
struct e1000_mac_info *mac = &hw->mac;
+ /* cannot be const, see this function */
struct e1000_mac_operations *func = &mac->ops;
u32 swsm = 0;
u32 swsm2 = 0;
@@ -1692,7 +1693,7 @@ static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
er32(ICRXDMTC);
}

-static struct e1000_mac_operations e82571_mac_ops = {
+static const struct e1000_mac_operations e82571_mac_ops = {
/* .check_mng_mode: mac type dependent */
/* .check_for_link: media type dependent */
.id_led_init = e1000e_id_led_init,
diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
index cebbd90..68e66b2 100644
--- a/drivers/net/e1000e/e1000.h
+++ b/drivers/net/e1000e/e1000.h
@@ -379,7 +379,7 @@ struct e1000_info {
u32 pba;
u32 max_hw_frame_size;
s32 (*get_variants)(struct e1000_adapter *);
- struct e1000_mac_operations *mac_ops;
+ const struct e1000_mac_operations *mac_ops;
struct e1000_phy_operations *phy_ops;
struct e1000_nvm_operations *nvm_ops;
};
diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
index d2a1047..c44d30a 100644
--- a/drivers/net/e1000e/es2lan.c
+++ b/drivers/net/e1000e/es2lan.c
@@ -202,6 +202,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
{
struct e1000_hw *hw = &adapter->hw;
struct e1000_mac_info *mac = &hw->mac;
+ /* cannot be const, see this function */
struct e1000_mac_operations *func = &mac->ops;

/* Set media type */
@@ -1369,7 +1370,7 @@ static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
er32(ICRXDMTC);
}

-static struct e1000_mac_operations es2_mac_ops = {
+static const struct e1000_mac_operations es2_mac_ops = {
.id_led_init = e1000e_id_led_init,
.check_mng_mode = e1000e_check_mng_mode_generic,
/* check_for_link dependent on media type */
diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
index a7d08da..2238d4d 100644
--- a/drivers/net/e1000e/hw.h
+++ b/drivers/net/e1000e/hw.h
@@ -791,6 +791,7 @@ struct e1000_nvm_operations {
};

struct e1000_mac_info {
+ /* cannot be const, see drivers/net/e1000e/ich8lan.c:e1000_init_mac_params_ich8lan */
struct e1000_mac_operations ops;

u8 addr[6];
diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
index 7b33be9..614a0d4 100644
--- a/drivers/net/e1000e/ich8lan.c
+++ b/drivers/net/e1000e/ich8lan.c
@@ -3291,7 +3291,7 @@ static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
}
}

-static struct e1000_mac_operations ich8_mac_ops = {
+static const struct e1000_mac_operations ich8_mac_ops = {
.id_led_init = e1000e_id_led_init,
.check_mng_mode = e1000_check_mng_mode_ich8lan,
.check_for_link = e1000_check_for_copper_link_ich8lan,
diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
index e8e9e91..34b847a 100644
--- a/drivers/net/igb/e1000_82575.c
+++ b/drivers/net/igb/e1000_82575.c
@@ -1585,7 +1585,7 @@ u16 igb_rxpbs_adjust_82580(u32 data)
return ret_val;
}

-static struct e1000_mac_operations e1000_mac_ops_82575 = {
+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
.init_hw = igb_init_hw_82575,
.check_for_link = igb_check_for_link_82575,
.rar_set = igb_rar_set,
diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
index dbaeb5f..854b252 100644
--- a/drivers/net/igb/e1000_hw.h
+++ b/drivers/net/igb/e1000_hw.h
@@ -324,7 +324,7 @@ struct e1000_nvm_operations {

struct e1000_info {
s32 (*get_invariants)(struct e1000_hw *);
- struct e1000_mac_operations *mac_ops;
+ const struct e1000_mac_operations *mac_ops;
struct e1000_phy_operations *phy_ops;
struct e1000_nvm_operations *nvm_ops;
};
@@ -332,6 +332,7 @@ struct e1000_info {
extern const struct e1000_info e1000_82575_info;

struct e1000_mac_info {
+ /* cannot be const, see drivers/net/igb/e1000_82575.c:igb_get_invariants_82575 */
struct e1000_mac_operations ops;

u8 addr[6];
diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
index 1e8ce37..4f12659 100644
--- a/drivers/net/igbvf/vf.h
+++ b/drivers/net/igbvf/vf.h
@@ -189,6 +189,7 @@ struct e1000_mac_operations {
};

struct e1000_mac_info {
+ /* cannot be const, see drivers/net/igbvf/vf.c:e1000_init_mac_params_vf */
struct e1000_mac_operations ops;
u8 addr[6];
u8 perm_addr[6];
--
1.6.5.3

2009-12-14 00:15:07

by Emese Revfy

[permalink] [raw]
Subject: [PATCH 2/3] Constify struct e1000_phy_operations 2.6.32-git-a252e7 v2

From: Emese Revfy <[email protected]>


Signed-off-by: Emese Revfy <[email protected]>
---
drivers/net/e1000e/82571.c | 6 +++---
drivers/net/e1000e/e1000.h | 2 +-
drivers/net/e1000e/es2lan.c | 2 +-
drivers/net/e1000e/hw.h | 1 +
drivers/net/e1000e/ich8lan.c | 2 +-
drivers/net/igb/e1000_82575.c | 2 +-
drivers/net/igb/e1000_hw.h | 1 +
7 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
index f388cba..12ff45a 100644
--- a/drivers/net/e1000e/82571.c
+++ b/drivers/net/e1000e/82571.c
@@ -1713,7 +1713,7 @@ static const struct e1000_mac_operations e82571_mac_ops = {
.setup_led = e1000e_setup_led_generic,
};

-static struct e1000_phy_operations e82_phy_ops_igp = {
+static const struct e1000_phy_operations e82_phy_ops_igp = {
.acquire = e1000_get_hw_semaphore_82571,
.check_polarity = e1000_check_polarity_igp,
.check_reset_block = e1000e_check_reset_block_generic,
@@ -1731,7 +1731,7 @@ static struct e1000_phy_operations e82_phy_ops_igp = {
.cfg_on_link_up = NULL,
};

-static struct e1000_phy_operations e82_phy_ops_m88 = {
+static const struct e1000_phy_operations e82_phy_ops_m88 = {
.acquire = e1000_get_hw_semaphore_82571,
.check_polarity = e1000_check_polarity_m88,
.check_reset_block = e1000e_check_reset_block_generic,
@@ -1749,7 +1749,7 @@ static struct e1000_phy_operations e82_phy_ops_m88 = {
.cfg_on_link_up = NULL,
};

-static struct e1000_phy_operations e82_phy_ops_bm = {
+static const struct e1000_phy_operations e82_phy_ops_bm = {
.acquire = e1000_get_hw_semaphore_82571,
.check_polarity = e1000_check_polarity_m88,
.check_reset_block = e1000e_check_reset_block_generic,
diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
index 68e66b2..24b704c 100644
--- a/drivers/net/e1000e/e1000.h
+++ b/drivers/net/e1000e/e1000.h
@@ -380,7 +380,7 @@ struct e1000_info {
u32 max_hw_frame_size;
s32 (*get_variants)(struct e1000_adapter *);
const struct e1000_mac_operations *mac_ops;
- struct e1000_phy_operations *phy_ops;
+ const struct e1000_phy_operations *phy_ops;
struct e1000_nvm_operations *nvm_ops;
};

diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
index c44d30a..2e8217e 100644
--- a/drivers/net/e1000e/es2lan.c
+++ b/drivers/net/e1000e/es2lan.c
@@ -1390,7 +1390,7 @@ static const struct e1000_mac_operations es2_mac_ops = {
.setup_led = e1000e_setup_led_generic,
};

-static struct e1000_phy_operations es2_phy_ops = {
+static const struct e1000_phy_operations es2_phy_ops = {
.acquire = e1000_acquire_phy_80003es2lan,
.check_polarity = e1000_check_polarity_m88,
.check_reset_block = e1000e_check_reset_block_generic,
diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
index 2238d4d..a51cbeb 100644
--- a/drivers/net/e1000e/hw.h
+++ b/drivers/net/e1000e/hw.h
@@ -828,6 +828,7 @@ struct e1000_mac_info {
};

struct e1000_phy_info {
+ /* cannot be const, see drivers/net/e1000e/82571.c:e1000_init_phy_params_82571 */
struct e1000_phy_operations ops;

enum e1000_phy_type type;
diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
index 614a0d4..eefef85 100644
--- a/drivers/net/e1000e/ich8lan.c
+++ b/drivers/net/e1000e/ich8lan.c
@@ -3309,7 +3309,7 @@ static const struct e1000_mac_operations ich8_mac_ops = {
/* id_led_init dependent on mac type */
};

-static struct e1000_phy_operations ich8_phy_ops = {
+static const struct e1000_phy_operations ich8_phy_ops = {
.acquire = e1000_acquire_swflag_ich8lan,
.check_reset_block = e1000_check_reset_block_ich8lan,
.commit = NULL,
diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
index 34b847a..050dc32 100644
--- a/drivers/net/igb/e1000_82575.c
+++ b/drivers/net/igb/e1000_82575.c
@@ -1593,7 +1593,7 @@ static const struct e1000_mac_operations e1000_mac_ops_82575 = {
.get_speed_and_duplex = igb_get_speed_and_duplex_copper,
};

-static struct e1000_phy_operations e1000_phy_ops_82575 = {
+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
.acquire = igb_acquire_phy_82575,
.get_cfg_done = igb_get_cfg_done_82575,
.release = igb_release_phy_82575,
diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
index 854b252..937540f 100644
--- a/drivers/net/igb/e1000_hw.h
+++ b/drivers/net/igb/e1000_hw.h
@@ -378,6 +378,7 @@ struct e1000_mac_info {
};

struct e1000_phy_info {
+ /* cannot be const, see drivers/net/igb/e1000_82575.c:igb_get_invariants_82575 */
struct e1000_phy_operations ops;

enum e1000_phy_type type;
--
1.6.5.3

2009-12-14 00:17:00

by Emese Revfy

[permalink] [raw]
Subject: [PATCH 3/3] Constify struct e1000_nvm_operations 2.6.32-git-a252e7 v2

From: Emese Revfy <[email protected]>


Signed-off-by: Emese Revfy <[email protected]>
---
drivers/net/e1000e/82571.c | 2 +-
drivers/net/e1000e/e1000.h | 2 +-
drivers/net/e1000e/es2lan.c | 2 +-
drivers/net/e1000e/hw.h | 16 ++++++++--------
drivers/net/e1000e/ich8lan.c | 2 +-
drivers/net/igb/e1000_82575.c | 2 +-
drivers/net/igb/e1000_hw.h | 3 ++-
7 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
index 12ff45a..738f51d 100644
--- a/drivers/net/e1000e/82571.c
+++ b/drivers/net/e1000e/82571.c
@@ -1767,7 +1767,7 @@ static const struct e1000_phy_operations e82_phy_ops_bm = {
.cfg_on_link_up = NULL,
};

-static struct e1000_nvm_operations e82571_nvm_ops = {
+static const struct e1000_nvm_operations e82571_nvm_ops = {
.acquire = e1000_acquire_nvm_82571,
.read = e1000e_read_nvm_eerd,
.release = e1000_release_nvm_82571,
diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
index 24b704c..2b42fba 100644
--- a/drivers/net/e1000e/e1000.h
+++ b/drivers/net/e1000e/e1000.h
@@ -381,7 +381,7 @@ struct e1000_info {
s32 (*get_variants)(struct e1000_adapter *);
const struct e1000_mac_operations *mac_ops;
const struct e1000_phy_operations *phy_ops;
- struct e1000_nvm_operations *nvm_ops;
+ const struct e1000_nvm_operations *nvm_ops;
};

/* hardware capability, feature, and workaround flags */
diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
index 2e8217e..9ce2d30 100644
--- a/drivers/net/e1000e/es2lan.c
+++ b/drivers/net/e1000e/es2lan.c
@@ -1408,7 +1408,7 @@ static const struct e1000_phy_operations es2_phy_ops = {
.cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
};

-static struct e1000_nvm_operations es2_nvm_ops = {
+static const struct e1000_nvm_operations es2_nvm_ops = {
.acquire = e1000_acquire_nvm_80003es2lan,
.read = e1000e_read_nvm_eerd,
.release = e1000_release_nvm_80003es2lan,
diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
index a51cbeb..d40e9af 100644
--- a/drivers/net/e1000e/hw.h
+++ b/drivers/net/e1000e/hw.h
@@ -781,13 +781,13 @@ struct e1000_phy_operations {

/* Function pointers for the NVM. */
struct e1000_nvm_operations {
- s32 (*acquire)(struct e1000_hw *);
- s32 (*read)(struct e1000_hw *, u16, u16, u16 *);
- void (*release)(struct e1000_hw *);
- s32 (*update)(struct e1000_hw *);
- s32 (*valid_led_default)(struct e1000_hw *, u16 *);
- s32 (*validate)(struct e1000_hw *);
- s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
+ s32 (* const acquire)(struct e1000_hw *);
+ s32 (* const read)(struct e1000_hw *, u16, u16, u16 *);
+ void (* const release)(struct e1000_hw *);
+ s32 (* const update)(struct e1000_hw *);
+ s32 (* const valid_led_default)(struct e1000_hw *, u16 *);
+ s32 (* const validate)(struct e1000_hw *);
+ s32 (* const write)(struct e1000_hw *, u16, u16, u16 *);
};

struct e1000_mac_info {
@@ -863,7 +863,7 @@ struct e1000_phy_info {
};

struct e1000_nvm_info {
- struct e1000_nvm_operations ops;
+ const struct e1000_nvm_operations ops;

enum e1000_nvm_type type;
enum e1000_nvm_override override;
diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
index eefef85..e3efb4a 100644
--- a/drivers/net/e1000e/ich8lan.c
+++ b/drivers/net/e1000e/ich8lan.c
@@ -3323,7 +3323,7 @@ static const struct e1000_phy_operations ich8_phy_ops = {
.write_reg = e1000e_write_phy_reg_igp,
};

-static struct e1000_nvm_operations ich8_nvm_ops = {
+static const struct e1000_nvm_operations ich8_nvm_ops = {
.acquire = e1000_acquire_nvm_ich8lan,
.read = e1000_read_nvm_ich8lan,
.release = e1000_release_nvm_ich8lan,
diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
index 050dc32..0c52265 100644
--- a/drivers/net/igb/e1000_82575.c
+++ b/drivers/net/igb/e1000_82575.c
@@ -1599,7 +1599,7 @@ static const struct e1000_phy_operations e1000_phy_ops_82575 = {
.release = igb_release_phy_82575,
};

-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
.acquire = igb_acquire_nvm_82575,
.read = igb_read_nvm_eerd,
.release = igb_release_nvm_82575,
diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
index 937540f..678f006 100644
--- a/drivers/net/igb/e1000_hw.h
+++ b/drivers/net/igb/e1000_hw.h
@@ -326,7 +326,7 @@ struct e1000_info {
s32 (*get_invariants)(struct e1000_hw *);
const struct e1000_mac_operations *mac_ops;
struct e1000_phy_operations *phy_ops;
- struct e1000_nvm_operations *nvm_ops;
+ const struct e1000_nvm_operations *nvm_ops;
};

extern const struct e1000_info e1000_82575_info;
@@ -414,6 +414,7 @@ struct e1000_phy_info {
};

struct e1000_nvm_info {
+ /* cannot be const, see drivers/net/igb/igb_main.c:igb_probe */
struct e1000_nvm_operations ops;

enum e1000_nvm_type type;
--
1.6.5.3