RAS/AMD/FMPM: Fix off by one when unwinding on error
authorDan Carpenter <dan.carpenter@linaro.org>
Wed, 6 Mar 2024 05:30:46 +0000 (08:30 +0300)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 6 Mar 2024 09:22:19 +0000 (10:22 +0100)
Decrement the index variable i before the first iteration when freeing
the remaining elements on error. Depending on where this fails it could
free something from one element beyond the end of the fru_records[]
array.

  [ bp: Massage commit message. ]

Fixes: 6f15e617cc99 ("RAS: Introduce a FRU memory poison manager")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/6fdec71a-846b-4cd0-af69-e5f6cd12f4f6@moroto.mountain
drivers/ras/amd/fmpm.c

index 0963c9e7b853478ed9c75d52cb9c64f1389d42cd..2f4ac9591c8f5a24e6630bda848505b19ce5e3ba 100644 (file)
@@ -817,7 +817,7 @@ static int allocate_records(void)
        return ret;
 
 out_free:
-       for (; i >= 0; i--)
+       while (--i >= 0)
                kfree(fru_records[i]);
 
        kfree(fru_records);