@@ -189,27 +189,30 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
189189 idxd -> wq_enable_map = bitmap_zalloc_node (idxd -> max_wqs , GFP_KERNEL , dev_to_node (dev ));
190190 if (!idxd -> wq_enable_map ) {
191191 rc = - ENOMEM ;
192- goto err_bitmap ;
192+ goto err_free_wqs ;
193193 }
194194
195195 for (i = 0 ; i < idxd -> max_wqs ; i ++ ) {
196196 wq = kzalloc_node (sizeof (* wq ), GFP_KERNEL , dev_to_node (dev ));
197197 if (!wq ) {
198198 rc = - ENOMEM ;
199- goto err ;
199+ goto err_unwind ;
200200 }
201201
202202 idxd_dev_set_type (& wq -> idxd_dev , IDXD_DEV_WQ );
203203 conf_dev = wq_confdev (wq );
204204 wq -> id = i ;
205205 wq -> idxd = idxd ;
206- device_initialize (wq_confdev ( wq ) );
206+ device_initialize (conf_dev );
207207 conf_dev -> parent = idxd_confdev (idxd );
208208 conf_dev -> bus = & dsa_bus_type ;
209209 conf_dev -> type = & idxd_wq_device_type ;
210210 rc = dev_set_name (conf_dev , "wq%d.%d" , idxd -> id , wq -> id );
211- if (rc < 0 )
212- goto err ;
211+ if (rc < 0 ) {
212+ put_device (conf_dev );
213+ kfree (wq );
214+ goto err_unwind ;
215+ }
213216
214217 mutex_init (& wq -> wq_lock );
215218 init_waitqueue_head (& wq -> err_queue );
@@ -220,15 +223,20 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
220223 wq -> enqcmds_retries = IDXD_ENQCMDS_RETRIES ;
221224 wq -> wqcfg = kzalloc_node (idxd -> wqcfg_size , GFP_KERNEL , dev_to_node (dev ));
222225 if (!wq -> wqcfg ) {
226+ put_device (conf_dev );
227+ kfree (wq );
223228 rc = - ENOMEM ;
224- goto err ;
229+ goto err_unwind ;
225230 }
226231
227232 if (idxd -> hw .wq_cap .op_config ) {
228233 wq -> opcap_bmap = bitmap_zalloc (IDXD_MAX_OPCAP_BITS , GFP_KERNEL );
229234 if (!wq -> opcap_bmap ) {
235+ kfree (wq -> wqcfg );
236+ put_device (conf_dev );
237+ kfree (wq );
230238 rc = - ENOMEM ;
231- goto err_opcap_bmap ;
239+ goto err_unwind ;
232240 }
233241 bitmap_copy (wq -> opcap_bmap , idxd -> opcap_bmap , IDXD_MAX_OPCAP_BITS );
234242 }
@@ -239,13 +247,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
239247
240248 return 0 ;
241249
242- err_opcap_bmap :
243- kfree (wq -> wqcfg );
244-
245- err :
246- put_device (conf_dev );
247- kfree (wq );
248-
250+ err_unwind :
249251 while (-- i >= 0 ) {
250252 wq = idxd -> wqs [i ];
251253 if (idxd -> hw .wq_cap .op_config )
@@ -254,11 +256,10 @@ static int idxd_setup_wqs(struct idxd_device *idxd)
254256 conf_dev = wq_confdev (wq );
255257 put_device (conf_dev );
256258 kfree (wq );
257-
258259 }
259260 bitmap_free (idxd -> wq_enable_map );
260261
261- err_bitmap :
262+ err_free_wqs :
262263 kfree (idxd -> wqs );
263264
264265 return rc ;
@@ -1291,10 +1292,12 @@ static void idxd_remove(struct pci_dev *pdev)
12911292 device_unregister (idxd_confdev (idxd ));
12921293 idxd_shutdown (pdev );
12931294 idxd_device_remove_debugfs (idxd );
1294- idxd_cleanup (idxd );
1295+ perfmon_pmu_remove (idxd );
1296+ idxd_cleanup_interrupts (idxd );
1297+ if (device_pasid_enabled (idxd ))
1298+ idxd_disable_system_pasid (idxd );
12951299 pci_iounmap (pdev , idxd -> reg_base );
12961300 put_device (idxd_confdev (idxd ));
1297- idxd_free (idxd );
12981301 pci_disable_device (pdev );
12991302}
13001303
0 commit comments