PCI/VGA: fix inverted vga_tryget() return check and clear removed pci_dev
Subsystems (2)
PATCH 1/1 PCI/VGA: fix inverted vga_tryget() return check and clear removed pci_dev
Fix two issues in drivers/pci/vgaarb.c:
1. In vga_arb_device_init() / vga_arbiter_From_pci_dev(), vga_tryget() returns 0 on success and a negative errno on failure, so checking if (!vga_tryget(...)) is inverted and skips unlocking on success.
2. In vga_arbiter_del_pci_device(), clear any open vga_arb_user_init priv->target references pointing to the removed pci_dev so subsequent writes or close() on /dev/vga_arbiter do not dereference a freed pci_dev.
---
drivers/pci/vgaarb.c +45 -28
@@ -818,11 +818,33 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)return false; } +#define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS +#define PCI_INVALID_CARD ((struct pci_dev *)-1UL) + +/* Each user has an array of these, tracking which cards have locks */ +struct vga_arb_user_card { +struct pci_dev *pdev; +unsigned int mem_cnt; +unsigned int io_cnt; +}; + +struct vga_arb_private { +struct list_head list; +struct pci_dev *target; +struct vga_arb_user_card cards[MAX_USER_CARDS ]; +spinlock_t lock; +}; + +static LIST_HEAD (vga_user_list); +static DEFINE_SPINLOCK (vga_user_lock); +static bool vga_arbiter_del_pci_device (struct pci_dev *pdev) {struct vga_device *vgadev; +struct vga_arb_private *priv;unsigned long flags;bool ret = true; +int i;spin_lock_irqsave (&vga_lock, flags); vgadev =vgadev_find (pdev);
@@ -845,6 +867,21 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev)wake_up_all (&vga_wait_queue); bail:spin_unlock_irqrestore (&vga_lock, flags); +if (ret) { +spin_lock_irqsave (&vga_user_lock, flags); +list_for_each_entry (priv, &vga_user_list, list) { +if (priv->target == pdev) + priv->target =PCI_INVALID_CARD ; +for (i =0 ; i <MAX_USER_CARDS ; i++) { +if (priv->cards[i].pdev == pdev) { + priv->cards[i].pdev =PCI_INVALID_CARD ; + priv->cards[i].io_cnt =0 ; + priv->cards[i].mem_cnt =0 ; + } + } + } +spin_unlock_irqrestore (&vga_user_lock, flags); + }kfree (vgadev);return ret; }
@@ -1025,27 +1062,6 @@ EXPORT_SYMBOL(vga_client_register);* the arbiter. */ -#define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS -#define PCI_INVALID_CARD ((struct pci_dev *)-1UL) - -/* Each user has an array of these, tracking which cards have locks */ -struct vga_arb_user_card { -struct pci_dev *pdev; -unsigned int mem_cnt; -unsigned int io_cnt; -}; - -struct vga_arb_private { -struct list_head list; -struct pci_dev *target; -struct vga_arb_user_card cards[MAX_USER_CARDS ]; -spinlock_t lock; -}; - -static LIST_HEAD (vga_user_list); -static DEFINE_SPINLOCK (vga_user_lock); - -/* * Take a string in the format: "PCI:domain:bus:dev.fn" and return the * respective values. If the string is not in this format, return 0.
@@ -1168,7 +1184,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }
@@ -1215,7 +1231,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }
@@ -1266,12 +1282,12 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,*/ pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; } -if (vga_tryget (pdev, io_state)) { +if (vga_tryget (pdev, io_state) ==0 ) {/* Update the client's locks lists... */ for (i =0 ; i <MAX_USER_CARDS ; i++) {if (priv->cards[i].pdev == pdev) {
@@ -1335,7 +1351,8 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,for (i =0 ; i <MAX_USER_CARDS ; i++) {if (priv->cards[i].pdev == pdev)break ; -if (priv->cards[i].pdev ==NULL ) { +if (priv->cards[i].pdev ==NULL || + priv->cards[i].pdev ==PCI_INVALID_CARD ) { priv->cards[i].pdev = pdev; priv->cards[i].io_cnt =0 ; priv->cards[i].mem_cnt =0 ;
@@ -1366,7 +1383,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, goto done; } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }
@@ -1429,7 +1446,7 @@ static int vga_arb_release(struct inode *inode, struct file *file)list_del (&priv->list);for (i =0 ; i <MAX_USER_CARDS ; i++) { uc = &priv->cards[i]; -if (uc->pdev ==NULL ) +if (uc->pdev ==NULL || uc->pdev ==PCI_INVALID_CARD )continue ;vgaarb_dbg (&uc->pdev->dev,"uc->io_cnt == %d, uc->mem_cnt == %d\n" , uc->io_cnt, uc->mem_cnt);
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] commit message references incorrect functions for vga_tryget() fix --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] commit message references incorrect functions for vga_tryget() fix --
commit 341d48fbd447d6890560b76963b8d28bd58bbe29
Author: Hui Peng <[email protected]>
PCI/VGA: fix inverted vga_tryget() return check and clear removed pci_dev
This commit fixes an inverted return check for vga_tryget() and clears open references pointing to a removed pci_dev in vga_arbiter_del_pci_device() to prevent dereferencing a freed pci_dev.
Quoted 3 lines
1. In
vga_arb_device_init()/vga_arbiter_From_pci_dev(),vga_tryget()returns 0 on success and a negative errno on failure, so checking if (!vga_tryget(...)) is inverted and skips unlocking on success.
[Severity: Medium]
The commit message references incorrect functions for the vga_tryget() fix.
Reading the commit message suggests looking at vga_arb_device_init() or vga_arbiter_From_pci_dev() for the vga_tryget() fix. However, vga_arb_device_init() does not call vga_tryget(), and vga_arbiter_From_pci_dev() does not exist in the codebase.
The actual code modified to fix the inverted return check is in vga_arb_write().
Could the commit message be updated to accurately reflect the function where the fix is applied?
Quoted 4 lines
drivers/pci/vgaarb.c +0
-0
[ ... ]
Quoted 13 lines
drivers/pci/vgaarb.c +2
-2@@ -1266,12 +1282,12 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,*/ pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; } -if (vga_tryget (pdev, io_state)) { +if (vga_tryget (pdev, io_state) ==0 ) {/* Update the client's locks lists... */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 1/2 PCI/VGA: fix inverted vga_tryget() return check in vga_arb_write()
In reply to Hui PengIn vga_arb_write(), the "trylock" command handler calls vga_tryget(pdev, io_state) and checks:
if (vga_tryget(pdev, io_state)) {
/* Update the client's locks lists... */However, vga_tryget() returns 0 on success and a negative errno (-EBUSY) when the VGA resources are already locked. Because the check tests for a non-zero return value, a successful vga_tryget() skips incrementing priv->cards[i].io_cnt / mem_cnt and skips reporting success, leaking the acquired VGA lock, whereas a failed vga_tryget() (-EBUSY) erroneously records the lock in priv->cards[i] so a subsequent "unlock" or file release decrements the lock count without holding the lock.
Check if (vga_tryget(pdev, io_state) == 0) in vga_arb_write().
Tested in QEMU against Linux 7.3.0-rc3 by opening /dev/vga_arbiter and writing "trylock io+mem" followed by closing the file descriptor. On the unfixed kernel, write("trylock io+mem") acquires the VGA lock (locks=io+mem(1:1)) but takes the error branch and returns -EBUSY (-16) without recording the lock in priv->cards[], permanently leaking the lock on close(); with this patch applied, write("trylock io+mem") succeeds (ret = 14) and close() cleanly releases the lock (locks=none(0:0)).
---
Changes in v2:
- Split the vga_tryget() return check fix in vga_arb_write() from the PCI_INVALID_CARD hot-unplug cleanup fix into a 2-patch series, and fix the commit message to reference vga_arb_write(), as noted by Sashiko.
- Update Fixes: tag from the file-move commit 1d38fe6ee6a8 to deb2d2ecd43d ("PCI/GPU: implement VGA arbitration on Linux").
drivers/pci/vgaarb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/vgaarb.c +1 -1
@@ -1272,7 +1272,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, goto done; } -if (vga_tryget (pdev, io_state)) { +if (vga_tryget (pdev, io_state) ==0 ) {/* Update the client's locks lists... */ for (i =0 ; i <MAX_USER_CARDS ; i++) {if (priv->cards[i].pdev == pdev) {
Signature · 1 line
2.49.0
PATCH v2 2/2 PCI/VGA: invalidate open user references in vga_arbiter_del_pci_device()
When a PCI VGA device is removed while /dev/vga_arbiter is open, vga_arbiter_del_pci_device() removes and frees the vgadev entry, but any open struct vga_arb_private on vga_user_list retains dangling pointers to the removed pdev in priv->target and priv->cards[i].pdev. Subsequent writes to /dev/vga_arbiter or closing the file descriptor in vga_arb_release() dereference the removed pdev.
Mark matching priv->target and priv->cards[i].pdev entries as PCI_INVALID_CARD under vga_user_lock in vga_arbiter_del_pci_device(), and treat PCI_INVALID_CARD like NULL in vga_arb_write() and vga_arb_release().
Tested in QEMU against Linux 7.3.0-rc3 by opening /dev/vga_arbiter, selecting PCI:0000:00:02.0, hot-removing the PCI VGA device via /sys/bus/pci/devices/0000:00:02.0/remove, and writing "unlock io+mem". On the unfixed kernel, priv->target retains a dangling pointer to the removed pci_dev so write("unlock io+mem") proceeds past the NULL check and returns -EINVAL (-22); with this patch applied, priv->target is set to PCI_INVALID_CARD on removal and write("unlock io+mem") immediately returns -ENODEV (-19).
---
Changes in v2:
- Split out from the vga_tryget() return check fix into patch 2/2.
- Update Fixes: tag from the file-move commit 1d38fe6ee6a8 to deb2d2ecd43d ("PCI/GPU: implement VGA arbitration on Linux").
drivers/pci/vgaarb.c | 71 +++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 27 deletions(-)
drivers/pci/vgaarb.c +44 -27
@@ -818,11 +818,33 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)return false; } +#define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS +#define PCI_INVALID_CARD ((struct pci_dev *)-1UL) + +/* Each user has an array of these, tracking which cards have locks */ +struct vga_arb_user_card { +struct pci_dev *pdev; +unsigned int mem_cnt; +unsigned int io_cnt; +}; + +struct vga_arb_private { +struct list_head list; +struct pci_dev *target; +struct vga_arb_user_card cards[MAX_USER_CARDS ]; +spinlock_t lock; +}; + +static LIST_HEAD (vga_user_list); +static DEFINE_SPINLOCK (vga_user_lock); +static bool vga_arbiter_del_pci_device (struct pci_dev *pdev) {struct vga_device *vgadev; +struct vga_arb_private *priv;unsigned long flags;bool ret = true; +int i;spin_lock_irqsave (&vga_lock, flags); vgadev =vgadev_find (pdev);
@@ -845,6 +867,21 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev)wake_up_all (&vga_wait_queue); bail:spin_unlock_irqrestore (&vga_lock, flags); +if (ret) { +spin_lock_irqsave (&vga_user_lock, flags); +list_for_each_entry (priv, &vga_user_list, list) { +if (priv->target == pdev) + priv->target =PCI_INVALID_CARD ; +for (i =0 ; i <MAX_USER_CARDS ; i++) { +if (priv->cards[i].pdev == pdev) { + priv->cards[i].pdev =PCI_INVALID_CARD ; + priv->cards[i].io_cnt =0 ; + priv->cards[i].mem_cnt =0 ; + } + } + } +spin_unlock_irqrestore (&vga_user_lock, flags); + }kfree (vgadev);return ret; }
@@ -1025,27 +1062,6 @@ EXPORT_SYMBOL(vga_client_register);* the arbiter. */ -#define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS -#define PCI_INVALID_CARD ((struct pci_dev *)-1UL) - -/* Each user has an array of these, tracking which cards have locks */ -struct vga_arb_user_card { -struct pci_dev *pdev; -unsigned int mem_cnt; -unsigned int io_cnt; -}; - -struct vga_arb_private { -struct list_head list; -struct pci_dev *target; -struct vga_arb_user_card cards[MAX_USER_CARDS ]; -spinlock_t lock; -}; - -static LIST_HEAD (vga_user_list); -static DEFINE_SPINLOCK (vga_user_lock); - -/* * Take a string in the format: "PCI:domain:bus:dev.fn" and return the * respective values. If the string is not in this format, return 0.
@@ -1168,7 +1184,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }
@@ -1215,7 +1231,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }
@@ -1266,7 +1282,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,*/ pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }
@@ -1335,7 +1351,8 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,for (i =0 ; i <MAX_USER_CARDS ; i++) {if (priv->cards[i].pdev == pdev)break ; -if (priv->cards[i].pdev ==NULL ) { +if (priv->cards[i].pdev ==NULL || + priv->cards[i].pdev ==PCI_INVALID_CARD ) { priv->cards[i].pdev = pdev; priv->cards[i].io_cnt =0 ; priv->cards[i].mem_cnt =0 ;
@@ -1366,7 +1383,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, goto done; } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }
@@ -1429,7 +1446,7 @@ static int vga_arb_release(struct inode *inode, struct file *file)list_del (&priv->list);for (i =0 ; i <MAX_USER_CARDS ; i++) { uc = &priv->cards[i]; -if (uc->pdev ==NULL ) +if (uc->pdev ==NULL || uc->pdev ==PCI_INVALID_CARD )continue ;vgaarb_dbg (&uc->pdev->dev,"uc->io_cnt == %d, uc->mem_cnt == %d\n" , uc->io_cnt, uc->mem_cnt);
Signature · 1 line
2.49.0
[email protected]
AI reviewRe: [PATCH v2 2/2] PCI/VGA: invalidate open user references in vga_arbiter_del_pci_device()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 20 lines
When a PCI VGA device is removed while
/dev/vga_arbiteris open,vga_arbiter_del_pci_device()removes and frees the vgadev entry, but any open structvga_arb_privateonvga_user_listretains dangling pointers to the removed pdev inpriv->targetand priv->cards[i].pdev. Subsequent writes to/dev/vga_arbiteror closing the file descriptor invga_arb_release()dereference the removed pdev.Mark matching
priv->targetand priv->cards[i].pdev entries asPCI_INVALID_CARDundervga_user_lockinvga_arbiter_del_pci_device(), and treatPCI_INVALID_CARDlike NULL invga_arb_write()andvga_arb_release().Tested in QEMU against Linux 7.3.0-rc3 by opening
/dev/vga_arbiter, selecting PCI:0000:00:02.0, hot-removing the PCI VGA device via /sys/bus/pci/devices/0000:00:02.0/remove, and writing "unlock io+mem". On the unfixed kernel,priv->targetretains a dangling pointer to the removedpci_devsowrite("unlock io+mem")proceeds past the NULL check and returns-EINVAL(-22); with this patch applied,priv->targetis set toPCI_INVALID_CARDon removal andwrite("unlock io+mem")immediately returns-ENODEV(-19).
Quoted 4 lines
Fixes deb2d2ecd43d ("PCI/GPU: implement VGA arbitration on Linux")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v2 1/2] PCI/VGA: fix inverted vga_tryget() return check in vga_arb_write()
In reply to Hui PengSashiko has reviewed this patch and found no issues. It looks great!
Quoted 25 lines
In
vga_arb_write(), the "trylock" command handler callsvga_tryget(pdev, io_state)and checks:if (vga_tryget(pdev, io_state)) { /* Update the client's locks lists... */However,
vga_tryget()returns 0 on success and a negative errno (-EBUSY) when the VGA resources are already locked. Because the check tests for a non-zero return value, a successfulvga_tryget()skips incrementing priv->cards[i].io_cnt /mem_cntand skips reporting success, leaking the acquired VGA lock, whereas a failedvga_tryget()(-EBUSY) erroneously records the lock in priv->cards[i] so a subsequent "unlock" or file release decrements the lock count without holding the lock.Check if (
vga_tryget(pdev, io_state)== 0) invga_arb_write().Tested in QEMU against Linux 7.3.0-rc3 by opening
/dev/vga_arbiterand writing "trylock io+mem" followed by closing the file descriptor. On the unfixed kernel,write("trylock io+mem")acquires the VGA lock (locks=io+mem(1:1)) but takes the error branch and returns-EBUSY(-16) without recording the lock in priv->cards[], permanently leaking the lock onclose(); with this patch applied,write("trylock io+mem")succeeds (ret = 14) andclose()cleanly releases the lock (locks=none(0:0)).
Quoted 4 lines
Fixes deb2d2ecd43d ("PCI/GPU: implement VGA arbitration on Linux")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 1 line · Hui Peng
Fix two issues in
drivers/pci/vgaarb.c:
One change per patch, please.
Quoted 162 lines
1. In
vga_arb_device_init()/vga_arbiter_From_pci_dev(),vga_tryget()returns 0 on success and a negative errno on failure, so checking if (!vga_tryget(...)) is inverted and skips unlocking on success.
2. Invga_arbiter_del_pci_device(), clear any openvga_arb_user_initpriv->targetreferences pointing to the removedpci_devso subsequent writes orclose()on/dev/vga_arbiterdo not dereference a freedpci_dev.Fixes 1d38fe6ee6a8 ("PCI/VGA: Move vgaarb to drivers/pci")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>---
drivers/pci/vgaarb.c +45
-28@@ -818,11 +818,33 @@ static bool vga_arbiter_add_pci_device(struct pci_dev *pdev)return false; } +#define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS +#define PCI_INVALID_CARD ((struct pci_dev *)-1UL) + +/* Each user has an array of these, tracking which cards have locks */ +struct vga_arb_user_card { +struct pci_dev *pdev; +unsigned int mem_cnt; +unsigned int io_cnt; +}; + +struct vga_arb_private { +struct list_head list; +struct pci_dev *target; +struct vga_arb_user_card cards[MAX_USER_CARDS ]; +spinlock_t lock; +}; + +static LIST_HEAD (vga_user_list); +static DEFINE_SPINLOCK (vga_user_lock); +static bool vga_arbiter_del_pci_device (struct pci_dev *pdev) {struct vga_device *vgadev; +struct vga_arb_private *priv;unsigned long flags;bool ret = true; +int i;spin_lock_irqsave (&vga_lock, flags); vgadev =vgadev_find (pdev);@@ -845,6 +867,21 @@ static bool vga_arbiter_del_pci_device(struct pci_dev *pdev)wake_up_all (&vga_wait_queue); bail:spin_unlock_irqrestore (&vga_lock, flags); +if (ret) { +spin_lock_irqsave (&vga_user_lock, flags); +list_for_each_entry (priv, &vga_user_list, list) { +if (priv->target == pdev) + priv->target =PCI_INVALID_CARD ; +for (i =0 ; i <MAX_USER_CARDS ; i++) { +if (priv->cards[i].pdev == pdev) { + priv->cards[i].pdev =PCI_INVALID_CARD ; + priv->cards[i].io_cnt =0 ; + priv->cards[i].mem_cnt =0 ; + } + } + } +spin_unlock_irqrestore (&vga_user_lock, flags); + }kfree (vgadev);return ret; }@@ -1025,27 +1062,6 @@ EXPORT_SYMBOL(vga_client_register);* the arbiter. */ -#define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS -#define PCI_INVALID_CARD ((struct pci_dev *)-1UL) - -/* Each user has an array of these, tracking which cards have locks */ -struct vga_arb_user_card { -struct pci_dev *pdev; -unsigned int mem_cnt; -unsigned int io_cnt; -}; - -struct vga_arb_private { -struct list_head list; -struct pci_dev *target; -struct vga_arb_user_card cards[MAX_USER_CARDS ]; -spinlock_t lock; -}; - -static LIST_HEAD (vga_user_list); -static DEFINE_SPINLOCK (vga_user_lock); - -/* * Take a string in the format: "PCI:domain:bus:dev.fn" and return the * respective values. If the string is not in this format, return 0. @@ -1168,7 +1184,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }@@ -1215,7 +1231,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }@@ -1266,12 +1282,12 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,*/ pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; } -if (vga_tryget (pdev, io_state)) { +if (vga_tryget (pdev, io_state) ==0 ) {/* Update the client's locks lists... */ for (i =0 ; i <MAX_USER_CARDS ; i++) {if (priv->cards[i].pdev == pdev) {@@ -1335,7 +1351,8 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,for (i =0 ; i <MAX_USER_CARDS ; i++) {if (priv->cards[i].pdev == pdev)break ; -if (priv->cards[i].pdev ==NULL ) { +if (priv->cards[i].pdev ==NULL || + priv->cards[i].pdev ==PCI_INVALID_CARD ) { priv->cards[i].pdev = pdev; priv->cards[i].io_cnt =0 ; priv->cards[i].mem_cnt =0 ;@@ -1366,7 +1383,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf, goto done; } pdev = priv->target; -if (priv->target ==NULL ) { +if (priv->target ==NULL || priv->target ==PCI_INVALID_CARD ) { ret_val = -ENODEV ; goto done; }@@ -1429,7 +1446,7 @@ static int vga_arb_release(struct inode *inode, struct file *file)list_del (&priv->list);for (i =0 ; i <MAX_USER_CARDS ; i++) { uc = &priv->cards[i]; -if (uc->pdev ==NULL ) +if (uc->pdev ==NULL || uc->pdev ==PCI_INVALID_CARD )continue ;vgaarb_dbg (&uc->pdev->dev,"uc->io_cnt == %d, uc->mem_cnt == %d\n" , uc->io_cnt, uc->mem_cnt);
Signature · 1 line
Jani Nikula, Intel
Quoted 10 lines · Hui Peng
Fix two issues in
drivers/pci/vgaarb.c:1. In
vga_arb_device_init()/vga_arbiter_From_pci_dev(),vga_tryget()returns 0 on success and a negative errno on failure, so checking if (!vga_tryget(...)) is inverted and skips unlocking on success.
2. Invga_arbiter_del_pci_device(), clear any openvga_arb_user_initpriv->targetreferences pointing to the removedpci_devso subsequent writes orclose()on/dev/vga_arbiterdo not dereference a freedpci_dev.
Quoted 4 lines
Fixes 1d38fe6ee6a8 ("PCI/VGA: Move vgaarb to drivers/pci")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>---
You sent multiple independent patches, to multiple independent subsystems. The amount of these patches clearly suggest this was AI generated and most likely not tested.
More importantly, you sent all this work without properly organizing relevant patches into patchsets. This makes reviewing difficult and might cause multiple reviewers to address the same issue. Replying to the entire set is impossible and requires handling each patch independently, instead of applying or discarding the set. Maintainers also won't see the bigger picture of your work. Quite worrying.
This is on the verge of hostile patch: bomb us with so many contributions, we won't be able to handle them in efficient manner, like responding ONCE to ask you to slow down. Considering all this is untested and LLM generated, I have even more doubts whether this should be considered for review.
Please read kernel documentation BEFORE posting more work. It will explain you how to identify subsystems, how to organize your work per subsystem, how to document usage of LLM and how what you should not do if this was posted in a good faith.
Best regards,
Krzysztof