Skip to content

Commit 2ddbcea

Browse files
committed
Merge branch 'xen-netback-fixes'
Paul Durrant says: ==================== xen-netback: update memory leak fix to avoid BUG Commit 9a6cdf5 "xen-netback: fix memory leaks on XenBus disconnect" added missing code to fix a memory leak by calling vfree() in the appropriate place. Unfortunately subsequent commit f16f1df "xen-netback: protect resource cleaning on XenBus disconnect" then wrapped this call to vfree() in a spin lock, leading to a BUG due to incorrect context. Patch #1 makes the existing code more readable Patch #2 fixes the problem ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents f7bb3d8 + a254d8f commit 2ddbcea

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

drivers/net/xen-netback/xenbus.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -492,24 +492,31 @@ static int backend_create_xenvif(struct backend_info *be)
492492

493493
static void backend_disconnect(struct backend_info *be)
494494
{
495-
if (be->vif) {
495+
struct xenvif *vif = be->vif;
496+
497+
if (vif) {
496498
unsigned int queue_index;
499+
struct xenvif_queue *queues;
497500

498-
xen_unregister_watchers(be->vif);
501+
xen_unregister_watchers(vif);
499502
#ifdef CONFIG_DEBUG_FS
500-
xenvif_debugfs_delif(be->vif);
503+
xenvif_debugfs_delif(vif);
501504
#endif /* CONFIG_DEBUG_FS */
502-
xenvif_disconnect_data(be->vif);
503-
for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index)
504-
xenvif_deinit_queue(&be->vif->queues[queue_index]);
505+
xenvif_disconnect_data(vif);
506+
for (queue_index = 0;
507+
queue_index < vif->num_queues;
508+
++queue_index)
509+
xenvif_deinit_queue(&vif->queues[queue_index]);
510+
511+
spin_lock(&vif->lock);
512+
queues = vif->queues;
513+
vif->num_queues = 0;
514+
vif->queues = NULL;
515+
spin_unlock(&vif->lock);
505516

506-
spin_lock(&be->vif->lock);
507-
vfree(be->vif->queues);
508-
be->vif->num_queues = 0;
509-
be->vif->queues = NULL;
510-
spin_unlock(&be->vif->lock);
517+
vfree(queues);
511518

512-
xenvif_disconnect_ctrl(be->vif);
519+
xenvif_disconnect_ctrl(vif);
513520
}
514521
}
515522

0 commit comments

Comments
 (0)