Skip to contentSkip to conversation

pch_gbe: few clean ups to the driver

PATCH Superseded Andy Shevchenko 3 participants 7 messages Jun 26, 2013 – Jun 27, 2013

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover pch_gbe: few clean ups to the driver

There are three clean ups to the driver.
Darren, can you incorporate this series to your Minnow board support? Or if this goes first, consider rebase on top.

Andy Shevchenko (3):
pch_gbe: remove inline keyword for exported functions
pch_gbe: convert pr_* to netdev_*
pch_gbe: use managed functions pcim_* and devm_*

 drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.h    |   2 +
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_api.c    |  48 ++--
 .../ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c    |   2 +-
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c   | 279 +++++++++++----------
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c  |  61 +++--
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_phy.c    |  23 +-
 drivers/staging/media/lirc/lirc_igorplugusb.c      |   2 +-
 7 files changed, 237 insertions(+), 180 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/3 pch_gbe: remove inline keyword for exported functions

There is no much sense to mark functions inline that are going to be used in the other compile modules.

---
 drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_api.c | 21 +++++++++++----------
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c    |  2 +-
 drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_phy.c |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_api.c +11 -10
index 5ae03e8..82e72b2 100644
@@ -19,6 +19,7 @@
  */
 #include "pch_gbe.h"
 #include "pch_gbe_phy.h"
+#include "pch_gbe_api.h"
 
 /* bus type values */
 #define pch_gbe_bus_type_unknown	0
@@ -112,7 +113,7 @@ static void pch_gbe_plat_init_function_pointers(struct pch_gbe_hw *hw)
  *	0:	Successfully
  *	ENOSYS:	Function is not registered
  */
-inline s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw)
+s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw)
 {
 	if (!hw->reg) {
 		pr_err("ERROR: Registers not mapped\n");
@@ -126,7 +127,7 @@ inline s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw)
  * pch_gbe_hal_get_bus_info - Obtain bus information for adapter
  * @hw:	Pointer to the HW structure
  */
-inline void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw)
+void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw)
 {
 	if (!hw->func->get_bus_info)
 		pr_err("ERROR: configuration\n");
@@ -141,7 +142,7 @@ inline void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw)
  *	0:	Successfully
  *	ENOSYS:	Function is not registered
  */
-inline s32 pch_gbe_hal_init_hw(struct pch_gbe_hw *hw)
+s32 pch_gbe_hal_init_hw(struct pch_gbe_hw *hw)
 {
 	if (!hw->func->init_hw) {
 		pr_err("ERROR: configuration\n");
@@ -159,7 +160,7 @@ inline s32 pch_gbe_hal_init_hw(struct pch_gbe_hw *hw)
  *	0:	Successfully
  *	Negative value:	Failed
  */
-inline s32 pch_gbe_hal_read_phy_reg(struct pch_gbe_hw *hw, u32 offset,
+s32 pch_gbe_hal_read_phy_reg(struct pch_gbe_hw *hw, u32 offset,
 					u16 *data)
 {
 	if (!hw->func->read_phy_reg)
@@ -176,7 +177,7 @@ inline s32 pch_gbe_hal_read_phy_reg(struct pch_gbe_hw *hw, u32 offset,
  *	0:	Successfully
  *	Negative value:	Failed
  */
-inline s32 pch_gbe_hal_write_phy_reg(struct pch_gbe_hw *hw, u32 offset,
+s32 pch_gbe_hal_write_phy_reg(struct pch_gbe_hw *hw, u32 offset,
 					u16 data)
 {
 	if (!hw->func->write_phy_reg)
@@ -188,7 +189,7 @@ inline s32 pch_gbe_hal_write_phy_reg(struct pch_gbe_hw *hw, u32 offset,
  * pch_gbe_hal_phy_hw_reset - Hard PHY reset
  * @hw:	    Pointer to the HW structure
  */
-inline void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw)
+void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw)
 {
 	if (!hw->func->reset_phy)
 		pr_err("ERROR: configuration\n");
@@ -200,7 +201,7 @@ inline void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw)
  * pch_gbe_hal_phy_sw_reset - Soft PHY reset
  * @hw:	    Pointer to the HW structure
  */
-inline void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw)
+void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw)
 {
 	if (!hw->func->sw_reset_phy)
 		pr_err("ERROR: configuration\n");
@@ -215,7 +216,7 @@ inline void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw)
  *	0:	Successfully
  *	ENOSYS:	Function is not registered
  */
-inline s32 pch_gbe_hal_read_mac_addr(struct pch_gbe_hw *hw)
+s32 pch_gbe_hal_read_mac_addr(struct pch_gbe_hw *hw)
 {
 	if (!hw->func->read_mac_addr) {
 		pr_err("ERROR: configuration\n");
@@ -228,7 +229,7 @@ inline s32 pch_gbe_hal_read_mac_addr(struct pch_gbe_hw *hw)
  * pch_gbe_hal_power_up_phy - Power up PHY
  * @hw:	Pointer to the HW structure
  */
-inline void pch_gbe_hal_power_up_phy(struct pch_gbe_hw *hw)
+void pch_gbe_hal_power_up_phy(struct pch_gbe_hw *hw)
 {
 	if (hw->func->power_up_phy)
 		hw->func->power_up_phy(hw);
@@ -238,7 +239,7 @@ inline void pch_gbe_hal_power_up_phy(struct pch_gbe_hw *hw)
  * pch_gbe_hal_power_down_phy - Power down PHY
  * @hw:	Pointer to the HW structure
  */
-inline void pch_gbe_hal_power_down_phy(struct pch_gbe_hw *hw)
+void pch_gbe_hal_power_down_phy(struct pch_gbe_hw *hw)
 {
 	if (hw->func->power_down_phy)
 		hw->func->power_down_phy(hw);
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +1 -1
index 0c1c65a..16d5ffa 100644
@@ -287,7 +287,7 @@ static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
 	return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
 }
 
-inline void pch_gbe_mac_load_mac_addr(struct pch_gbe_hw *hw)
+static inline void pch_gbe_mac_load_mac_addr(struct pch_gbe_hw *hw)
 {
 	iowrite32(0x01, &hw->reg->MAC_ADDR_LOAD);
 }
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_phy.c +1 -1
index 28bb960..423b3bf 100644
@@ -235,7 +235,7 @@ void pch_gbe_phy_power_down(struct pch_gbe_hw *hw)
  * pch_gbe_phy_set_rgmii - RGMII interface setting
  * @hw:	            Pointer to the HW structure
  */
-inline void pch_gbe_phy_set_rgmii(struct pch_gbe_hw *hw)
+void pch_gbe_phy_set_rgmii(struct pch_gbe_hw *hw)
 {
 	pch_gbe_phy_sw_reset(hw);
 }
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/3 pch_gbe: convert pr_* to netdev_*

In reply to Andy Shevchenko

We may use nice macros to prefix our messages with proper device name.

---
 drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.h    |   2 +
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_api.c    |  27 ++-
 .../ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c    |   2 +-
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c   | 227 ++++++++++++---------
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c  |  61 ++++--
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_phy.c    |  21 +-
 drivers/staging/media/lirc/lirc_igorplugusb.c      |   2 +-
 7 files changed, 209 insertions(+), 133 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.h +2 -0
index 7fb7e17..7779036 100644
@@ -633,6 +633,8 @@ struct pch_gbe_adapter {
 	struct pci_dev *ptp_pdev;
 };
 
+#define pch_gbe_hw_to_adapter(hw)	container_of(hw, struct pch_gbe_adapter, hw)
+
 extern const char pch_driver_version[];
 
 /* pch_gbe_main.c */
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_api.c +20 -7
index 82e72b2..fe5314e 100644
@@ -67,11 +67,12 @@ static void pch_gbe_plat_get_bus_info(struct pch_gbe_hw *hw)
  */
 static s32 pch_gbe_plat_init_hw(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
 	s32 ret_val;
 
 	ret_val = pch_gbe_phy_get_id(hw);
 	if (ret_val) {
-		pr_err("pch_gbe_phy_get_id error\n");
+		netdev_err(adapter->netdev, "pch_gbe_phy_get_id error\n");
 		return ret_val;
 	}
 	pch_gbe_phy_init_setting(hw);
@@ -115,8 +116,10 @@ static void pch_gbe_plat_init_function_pointers(struct pch_gbe_hw *hw)
  */
 s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
+
 	if (!hw->reg) {
-		pr_err("ERROR: Registers not mapped\n");
+		netdev_err(adapter->netdev, "ERROR: Registers not mapped\n");
 		return -ENOSYS;
 	}
 	pch_gbe_plat_init_function_pointers(hw);
@@ -129,8 +132,10 @@ s32 pch_gbe_hal_setup_init_funcs(struct pch_gbe_hw *hw)
  */
 void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
+
 	if (!hw->func->get_bus_info)
-		pr_err("ERROR: configuration\n");
+		netdev_err(adapter->netdev, "ERROR: configuration\n");
 	else
 		hw->func->get_bus_info(hw);
 }
@@ -144,8 +149,10 @@ void pch_gbe_hal_get_bus_info(struct pch_gbe_hw *hw)
  */
 s32 pch_gbe_hal_init_hw(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
+
 	if (!hw->func->init_hw) {
-		pr_err("ERROR: configuration\n");
+		netdev_err(adapter->netdev, "ERROR: configuration\n");
 		return -ENOSYS;
 	}
 	return hw->func->init_hw(hw);
@@ -191,8 +198,10 @@ s32 pch_gbe_hal_write_phy_reg(struct pch_gbe_hw *hw, u32 offset,
  */
 void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
+
 	if (!hw->func->reset_phy)
-		pr_err("ERROR: configuration\n");
+		netdev_err(adapter->netdev, "ERROR: configuration\n");
 	else
 		hw->func->reset_phy(hw);
 }
@@ -203,8 +212,10 @@ void pch_gbe_hal_phy_hw_reset(struct pch_gbe_hw *hw)
  */
 void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
+
 	if (!hw->func->sw_reset_phy)
-		pr_err("ERROR: configuration\n");
+		netdev_err(adapter->netdev, "ERROR: configuration\n");
 	else
 		hw->func->sw_reset_phy(hw);
 }
@@ -218,8 +229,10 @@ void pch_gbe_hal_phy_sw_reset(struct pch_gbe_hw *hw)
  */
 s32 pch_gbe_hal_read_mac_addr(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
+
 	if (!hw->func->read_mac_addr) {
-		pr_err("ERROR: configuration\n");
+		netdev_err(adapter->netdev, "ERROR: configuration\n");
 		return -ENOSYS;
 	}
 	return hw->func->read_mac_addr(hw);
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c +1 -1
index 24b787b..1129db0 100644
@@ -122,7 +122,7 @@ static int pch_gbe_set_settings(struct net_device *netdev,
 	}
 	ret = mii_ethtool_sset(&adapter->mii, ecmd);
 	if (ret) {
-		pr_err("Error: mii_ethtool_sset\n");
+		netdev_err(netdev, "Error: mii_ethtool_sset\n");
 		return ret;
 	}
 	hw->mac.link_speed = speed;
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +133 -94

661 lines not on this page · raw message

drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c +39 -22

155 lines not on this page · raw message

drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_phy.c +13 -8
index 423b3bf..5f3154a 100644
@@ -97,6 +97,7 @@
  */
 s32 pch_gbe_phy_get_id(struct pch_gbe_hw *hw)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
 	struct pch_gbe_phy_info *phy = &hw->phy;
 	s32 ret;
 	u16 phy_id1;
@@ -115,8 +116,9 @@ s32 pch_gbe_phy_get_id(struct pch_gbe_hw *hw)
 	phy->id = (u32)phy_id1;
 	phy->id = ((phy->id << 6) | ((phy_id2 & 0xFC00) >> 10));
 	phy->revision = (u32) (phy_id2 & 0x000F);
-	pr_debug("phy->id : 0x%08x  phy->revision : 0x%08x\n",
-		 phy->id, phy->revision);
+	netdev_dbg(adapter->netdev,
+		   "phy->id : 0x%08x  phy->revision : 0x%08x\n",
+		   phy->id, phy->revision);
 	return 0;
 }
 
@@ -131,10 +133,12 @@ s32 pch_gbe_phy_get_id(struct pch_gbe_hw *hw)
  */
 s32 pch_gbe_phy_read_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 *data)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
 	struct pch_gbe_phy_info *phy = &hw->phy;
 
 	if (offset > PHY_MAX_REG_ADDRESS) {
-		pr_err("PHY Address %d is out of range\n", offset);
+		netdev_err(adapter->netdev, "PHY Address %d is out of range\n",
+			   offset);
 		return -EINVAL;
 	}
 	*data = pch_gbe_mac_ctrl_miim(hw, phy->addr, PCH_GBE_HAL_MIIM_READ,
@@ -153,10 +157,12 @@ s32 pch_gbe_phy_read_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 *data)
  */
 s32 pch_gbe_phy_write_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 data)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
 	struct pch_gbe_phy_info *phy = &hw->phy;
 
 	if (offset > PHY_MAX_REG_ADDRESS) {
-		pr_err("PHY Address %d is out of range\n", offset);
+		netdev_err(adapter->netdev, "PHY Address %d is out of range\n",
+			   offset);
 		return -EINVAL;
 	}
 	pch_gbe_mac_ctrl_miim(hw, phy->addr, PCH_GBE_HAL_MIIM_WRITE,
@@ -246,15 +252,14 @@ void pch_gbe_phy_set_rgmii(struct pch_gbe_hw *hw)
  */
 void pch_gbe_phy_init_setting(struct pch_gbe_hw *hw)
 {
-	struct pch_gbe_adapter *adapter;
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
 	struct ethtool_cmd     cmd = { .cmd = ETHTOOL_GSET };
 	int ret;
 	u16 mii_reg;
 
-	adapter = container_of(hw, struct pch_gbe_adapter, hw);
 	ret = mii_ethtool_gset(&adapter->mii, &cmd);
 	if (ret)
-		pr_err("Error: mii_ethtool_gset\n");
+		netdev_err(adapter->netdev, "Error: mii_ethtool_gset\n");
 
 	ethtool_cmd_speed_set(&cmd, hw->mac.link_speed);
 	cmd.duplex = hw->mac.link_duplex;
@@ -263,7 +268,7 @@ void pch_gbe_phy_init_setting(struct pch_gbe_hw *hw)
 	pch_gbe_phy_write_reg_miic(hw, MII_BMCR, BMCR_RESET);
 	ret = mii_ethtool_sset(&adapter->mii, &cmd);
 	if (ret)
-		pr_err("Error: mii_ethtool_sset\n");
+		netdev_err(adapter->netdev, "Error: mii_ethtool_sset\n");
 
 	pch_gbe_phy_sw_reset(hw);
 
drivers/staging/media/lirc/lirc_igorplugusb.c +1 -1
index 28c8b0b..25df7cf 100644
@@ -408,7 +408,7 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
 	dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n",
 		devnum, CODE_LENGTH, maxp);
 
-	ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
+	ir = devm_kzalloc(&dev->dev, sizeof(*ir), GFP_KERNEL);
 	if (!ir)
 		return -ENOMEM;
 
Signature · 1 line
1.8.3.1
maintainer
#3 lore raw

Re: [PATCH v1 2/3] pch_gbe: convert pr_* to netdev_*

From: Andy Shevchenko <[email protected]>
Date: Wed, 26 Jun 2013 19:13:36 +0300

drivers/staging/media/lirc/lirc_igorplugusb.c static int igorplugusb_remote_probe(struct usb_interface *intf, · line 414

Quoted 13 lines
drivers/staging/media/lirc/lirc_igorplugusb.c +1 -1
index 28c8b0b..25df7cf 100644
@@ -408,7 +408,7 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
 	dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n",
 		devnum, CODE_LENGTH, maxp);
 
-	ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
+	ir = devm_kzalloc(&dev->dev, sizeof(*ir), GFP_KERNEL);
 	if (!ir)
 		return -ENOMEM;
 

This definitely wasn't supposed to be in this patch series.

Please repost this set with this hunk removed.

#4 lore raw

Re: [PATCH v1 2/3] pch_gbe: convert pr_* to netdev_*

Quoted 19 lines · David Miller

From: Andy Shevchenko <[email protected]>
Date: Wed, 26 Jun 2013 19:13:36 +0300

drivers/staging/media/lirc/lirc_igorplugusb.c static int igorplugusb_remote_probe(struct usb_interface *intf, · line 414

Quoted 13 lines
drivers/staging/media/lirc/lirc_igorplugusb.c +1 -1
index 28c8b0b..25df7cf 100644
@@ -408,7 +408,7 @@ static int igorplugusb_remote_probe(struct usb_interface *intf,
 	dprintk(DRIVER_NAME "[%d]: bytes_in_key=%zu maxp=%d\n",
 		devnum, CODE_LENGTH, maxp);
 
-	ir = devm_kzalloc(&intf->dev, sizeof(*ir), GFP_KERNEL);
+	ir = devm_kzalloc(&dev->dev, sizeof(*ir), GFP_KERNEL);
 	if (!ir)
 		return -ENOMEM;
 

This definitely wasn't supposed to be in this patch series.

Quoted 1 line

Please repost this set with this hunk removed.

Oops, sure.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#5 lore raw

Re: [PATCH v1 2/3] pch_gbe: convert pr_* to netdev_*

In reply to Andy Shevchenko
Quoted 1 line · Andy Shevchenko

We may use nice macros to prefix our messages with proper device name.

[]

drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c

Quoted 1 line
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c +0 -0

[]

drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c s32 pch_gbe_phy_get_id(struct pch_gbe_hw *hw) · line 141

Quoted 11 lines
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c +3 -1
@@ -131,10 +133,12 @@ s32 pch_gbe_phy_get_id(struct pch_gbe_hw *hw)
  */
 s32 pch_gbe_phy_read_reg_miic(struct pch_gbe_hw *hw, u32 offset, u16 *data)
 {
+	struct pch_gbe_adapter *adapter = pch_gbe_hw_to_adapter(hw);
 	struct pch_gbe_phy_info *phy = &hw->phy;
 
 	if (offset > PHY_MAX_REG_ADDRESS) {
-		pr_err("PHY Address %d is out of range\n", offset);
+		netdev_err(adapter->netdev, "PHY Address %d is out of range\n",
+			   offset);

For all the patch blocks in this set, I suggest taking these reverences only when necessary.

Assigning them at the beginning of the function seems wasteful when these may not be used at all.

#6 lore raw

PATCH 3/3 pch_gbe: use managed functions pcim_* and devm_*

In reply to Andy Shevchenko

This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier.

---
 .../net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c   | 50 +++++++---------------
 1 file changed, 15 insertions(+), 35 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +15 -35
index c2a6dc4..1f13556 100644
@@ -634,15 +634,15 @@ static void pch_gbe_mac_set_pause_packet(struct pch_gbe_hw *hw)
  */
 static int pch_gbe_alloc_queues(struct pch_gbe_adapter *adapter)
 {
-	adapter->tx_ring = kzalloc(sizeof(*adapter->tx_ring), GFP_KERNEL);
+	adapter->tx_ring = devm_kzalloc(&adapter->pdev->dev,
+					sizeof(*adapter->tx_ring), GFP_KERNEL);
 	if (!adapter->tx_ring)
 		return -ENOMEM;
 
-	adapter->rx_ring = kzalloc(sizeof(*adapter->rx_ring), GFP_KERNEL);
-	if (!adapter->rx_ring) {
-		kfree(adapter->tx_ring);
+	adapter->rx_ring = devm_kzalloc(&adapter->pdev->dev,
+					sizeof(*adapter->rx_ring), GFP_KERNEL);
+	if (!adapter->rx_ring)
 		return -ENOMEM;
-	}
 	return 0;
 }
 
@@ -2584,13 +2584,7 @@ static void pch_gbe_remove(struct pci_dev *pdev)
 
 	pch_gbe_hal_phy_hw_reset(&adapter->hw);
 
-	kfree(adapter->tx_ring);
-	kfree(adapter->rx_ring);
-
-	iounmap(adapter->hw.reg);
-	pci_release_regions(pdev);
 	free_netdev(netdev);
-	pci_disable_device(pdev);
 }
 
 static int pch_gbe_probe(struct pci_dev *pdev,
@@ -2600,7 +2594,7 @@ static int pch_gbe_probe(struct pci_dev *pdev,
 	struct pch_gbe_adapter *adapter;
 	int ret;
 
-	ret = pci_enable_device(pdev);
+	ret = pcim_enable_device(pdev);
 	if (ret)
 		return ret;
 
@@ -2613,24 +2607,22 @@ static int pch_gbe_probe(struct pci_dev *pdev,
 			if (ret) {
 				dev_err(&pdev->dev, "ERR: No usable DMA "
 					"configuration, aborting\n");
-				goto err_disable_device;
+				return ret;
 			}
 		}
 	}
 
-	ret = pci_request_regions(pdev, KBUILD_MODNAME);
+	ret = pcim_iomap_regions(pdev, 1 << PCH_GBE_PCI_BAR, pci_name(pdev));
 	if (ret) {
 		dev_err(&pdev->dev,
 			"ERR: Can't reserve PCI I/O and memory resources\n");
-		goto err_disable_device;
+		return ret;
 	}
 	pci_set_master(pdev);
 
 	netdev = alloc_etherdev((int)sizeof(struct pch_gbe_adapter));
-	if (!netdev) {
-		ret = -ENOMEM;
-		goto err_release_pci;
-	}
+	if (!netdev)
+		return -ENOMEM;
 	SET_NETDEV_DEV(netdev, &pdev->dev);
 
 	pci_set_drvdata(pdev, netdev);
@@ -2638,18 +2630,14 @@ static int pch_gbe_probe(struct pci_dev *pdev,
 	adapter->netdev = netdev;
 	adapter->pdev = pdev;
 	adapter->hw.back = adapter;
-	adapter->hw.reg = pci_iomap(pdev, PCH_GBE_PCI_BAR, 0);
-	if (!adapter->hw.reg) {
-		ret = -EIO;
-		dev_err(&pdev->dev, "Can't ioremap\n");
-		goto err_free_netdev;
-	}
+	adapter->hw.reg = pcim_iomap_table(pdev)[PCH_GBE_PCI_BAR];
 
 	adapter->ptp_pdev = pci_get_bus_and_slot(adapter->pdev->bus->number,
 					       PCI_DEVFN(12, 4));
 	if (ptp_filter_init(ptp_filter, ARRAY_SIZE(ptp_filter))) {
 		dev_err(&pdev->dev, "Bad ptp filter\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_free_netdev;
 	}
 
 	netdev->netdev_ops = &pch_gbe_netdev_ops;
@@ -2667,7 +2655,7 @@ static int pch_gbe_probe(struct pci_dev *pdev,
 	/* setup the private structure */
 	ret = pch_gbe_sw_init(adapter);
 	if (ret)
-		goto err_iounmap;
+		goto err_free_netdev;
 
 	/* Initialize PHY */
 	ret = pch_gbe_init_phy(adapter);
@@ -2723,16 +2711,8 @@ static int pch_gbe_probe(struct pci_dev *pdev,
 
 err_free_adapter:
 	pch_gbe_hal_phy_hw_reset(&adapter->hw);
-	kfree(adapter->tx_ring);
-	kfree(adapter->rx_ring);
-err_iounmap:
-	iounmap(adapter->hw.reg);
 err_free_netdev:
 	free_netdev(netdev);
-err_release_pci:
-	pci_release_regions(pdev);
-err_disable_device:
-	pci_disable_device(pdev);
 	return ret;
 }
 
Signature · 1 line
1.8.3.1