@@ -75,20 +75,24 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
7575 plat -> mdio_bus_data = devm_kzalloc (& pdev -> dev ,
7676 sizeof (* plat -> mdio_bus_data ),
7777 GFP_KERNEL );
78- if (!plat -> mdio_bus_data )
79- return - ENOMEM ;
78+ if (!plat -> mdio_bus_data ) {
79+ ret = - ENOMEM ;
80+ goto err_put_node ;
81+ }
8082 plat -> mdio_bus_data -> needs_reset = true;
8183 }
8284
8385 plat -> dma_cfg = devm_kzalloc (& pdev -> dev , sizeof (* plat -> dma_cfg ), GFP_KERNEL );
84- if (!plat -> dma_cfg )
85- return - ENOMEM ;
86+ if (!plat -> dma_cfg ) {
87+ ret = - ENOMEM ;
88+ goto err_put_node ;
89+ }
8690
8791 /* Enable pci device */
8892 ret = pci_enable_device (pdev );
8993 if (ret ) {
9094 dev_err (& pdev -> dev , "%s: ERROR: failed to enable device\n" , __func__ );
91- return ret ;
95+ goto err_put_node ;
9296 }
9397
9498 /* Get the base address of device */
@@ -97,7 +101,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
97101 continue ;
98102 ret = pcim_iomap_regions (pdev , BIT (0 ), pci_name (pdev ));
99103 if (ret )
100- return ret ;
104+ goto err_disable_device ;
101105 break ;
102106 }
103107
@@ -108,7 +112,8 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
108112 phy_mode = device_get_phy_mode (& pdev -> dev );
109113 if (phy_mode < 0 ) {
110114 dev_err (& pdev -> dev , "phy_mode not found\n" );
111- return phy_mode ;
115+ ret = phy_mode ;
116+ goto err_disable_device ;
112117 }
113118
114119 plat -> phy_interface = phy_mode ;
@@ -125,6 +130,7 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
125130 if (res .irq < 0 ) {
126131 dev_err (& pdev -> dev , "IRQ macirq not found\n" );
127132 ret = - ENODEV ;
133+ goto err_disable_msi ;
128134 }
129135
130136 res .wol_irq = of_irq_get_byname (np , "eth_wake_irq" );
@@ -137,15 +143,31 @@ static int loongson_dwmac_probe(struct pci_dev *pdev, const struct pci_device_id
137143 if (res .lpi_irq < 0 ) {
138144 dev_err (& pdev -> dev , "IRQ eth_lpi not found\n" );
139145 ret = - ENODEV ;
146+ goto err_disable_msi ;
140147 }
141148
142- return stmmac_dvr_probe (& pdev -> dev , plat , & res );
149+ ret = stmmac_dvr_probe (& pdev -> dev , plat , & res );
150+ if (ret )
151+ goto err_disable_msi ;
152+
153+ return ret ;
154+
155+ err_disable_msi :
156+ pci_disable_msi (pdev );
157+ err_disable_device :
158+ pci_disable_device (pdev );
159+ err_put_node :
160+ of_node_put (plat -> mdio_node );
161+ return ret ;
143162}
144163
145164static void loongson_dwmac_remove (struct pci_dev * pdev )
146165{
166+ struct net_device * ndev = dev_get_drvdata (& pdev -> dev );
167+ struct stmmac_priv * priv = netdev_priv (ndev );
147168 int i ;
148169
170+ of_node_put (priv -> plat -> mdio_node );
149171 stmmac_dvr_remove (& pdev -> dev );
150172
151173 for (i = 0 ; i < PCI_STD_NUM_BARS ; i ++ ) {
@@ -155,6 +177,7 @@ static void loongson_dwmac_remove(struct pci_dev *pdev)
155177 break ;
156178 }
157179
180+ pci_disable_msi (pdev );
158181 pci_disable_device (pdev );
159182}
160183
0 commit comments