Skip to contentSkip to conversation

PCI/VGA: release vga_user_lock before vga_put()

PATCH New Kaushlendra Kumar 1 participant 1 message Oct 1, 2025 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI/VGA: release vga_user_lock before vga_put()

Release vga_user_lock immediately after list_del() and before calling vga_put(). The vga_put() function acquires vga_lock internally, and holding vga_user_lock while calling vga_put(). The VGA resource operations and loop iteration don't require lock protection, only the list removal needs lock protection.

This ensures consistent lock ordering and eliminates the deadlock risk during VGA resource cleanup operations.

---
 drivers/pci/vgaarb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/vgaarb.c +1 -1
index 78748e8d2dba..e86fe7fa3d6f 100644
@@ -1445,6 +1445,7 @@ static int vga_arb_release(struct inode *inode, struct file *file)
 
 	spin_lock_irqsave(&vga_user_lock, flags);
 	list_del(&priv->list);
+	spin_unlock_irqrestore(&vga_user_lock, flags);
 	for (i = 0; i < MAX_USER_CARDS; i++) {
 		uc = &priv->cards[i];
 		if (uc->pdev == NULL)
@@ -1456,7 +1457,6 @@ static int vga_arb_release(struct inode *inode, struct file *file)
 		while (uc->mem_cnt--)
 			vga_put(uc->pdev, VGA_RSRC_LEGACY_MEM);
 	}
-	spin_unlock_irqrestore(&vga_user_lock, flags);
 
 	kfree(priv);
 
Signature · 1 line
2.34.1