Skip to contentSkip to conversation

drm: nouveau: move bounds checking to the front in nouveau_svm_fault_buffer_dtor()

PATCH New Hangyu Hua 1 participant 1 message Sep 14, 2022

Subsystems (3)
lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

PATCH 1/1 drm: nouveau: move bounds checking to the front in nouveau_svm_fault_buffer_dtor()

It is better to check i before use it in array to avoid potential out of bound access.

---
 drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_svm.c +1 -1
index 31a5b81ee9fc..5c49a8eaf593 100644
@@ -957,7 +957,7 @@ nouveau_svm_fault_buffer_dtor(struct nouveau_svm *svm, int id)
 	int i;
 
 	if (buffer->fault) {
-		for (i = 0; buffer->fault[i] && i < buffer->entries; i++)
+		for (i = 0; i < buffer->entries && buffer->fault[i]; i++)
 			kfree(buffer->fault[i]);
 		kvfree(buffer->fault);
 	}
Signature · 1 line
2.34.1