Skip to contentSkip to conversation

proc: Remove redundant size checks in proc_bus_pci_read/write()

PATCH New Kaushlendra Kumar 1 participant 1 message Sep 29, 2025 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc: Remove redundant size checks in proc_bus_pci_read/write()

Remove redundant "if (nbytes >= size)" checks in proc_bus_pci_read() and proc_bus_pci_write() functions. The subsequent "if (pos + nbytes

Quoted 1 line

size)" check already handles this condition by adjusting nbytes to

"size - pos", making the earlier check unnecessary.

This simplifies the logic without changing functionality since both checks serve the same purpose of preventing reads/writes beyond the available size.

---
 drivers/pci/proc.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/pci/proc.c +0 -4
index 9348a0fb8084..da19e6a65ee4 100644
@@ -47,8 +47,6 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,
 
 	if (pos >= size)
 		return 0;
-	if (nbytes >= size)
-		nbytes = size;
 	if (pos + nbytes > size)
 		nbytes = size - pos;
 	cnt = nbytes;
@@ -123,8 +121,6 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
 
 	if (pos >= size)
 		return 0;
-	if (nbytes >= size)
-		nbytes = size;
 	if (pos + nbytes > size)
 		nbytes = size - pos;
 	cnt = nbytes;
Signature · 1 line
2.34.1