diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp
index ed22263b58f8..b7c07e896538 100644
--- a/src/libcamera/matrix.cpp
+++ b/src/libcamera/matrix.cpp
@@ -229,7 +229,7 @@ bool matrixInvert(Span<const T> dataIn, Span<T> dataOut, unsigned int dim,
 		 * Locate the next pivot. To improve numerical stability, use
 		 * the row with the largest value in the pivot's column.
 		 */
-		unsigned int row;
+		unsigned int row = pivot;
 		T maxValue{ 0 };
 
 		for (unsigned int i = pivot; i < dim; ++i) {
