Commit-ID:  ef4d6a8556b637ad27c8c2a2cff1dda3da38e9a9
Gitweb:     https://git.kernel.org/tip/ef4d6a8556b637ad27c8c2a2cff1dda3da38e9a9
Author:     Ferdinand Blomqvist <[email protected]>
AuthorDate: Thu, 20 Jun 2019 17:10:37 +0300
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Wed, 26 Jun 2019 14:55:47 +0200

rslib: Fix handling of of caller provided syndrome

Check if the syndrome provided by the caller is zero, and act
accordingly.

Signed-off-by: Ferdinand Blomqvist <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Link: 
https://lkml.kernel.org/r/[email protected]

---
 lib/reed_solomon/decode_rs.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/reed_solomon/decode_rs.c b/lib/reed_solomon/decode_rs.c
index 78629bbe6590..b7264a712d46 100644
--- a/lib/reed_solomon/decode_rs.c
+++ b/lib/reed_solomon/decode_rs.c
@@ -42,8 +42,18 @@
        BUG_ON(pad < 0 || pad >= nn - nroots);
 
        /* Does the caller provide the syndrome ? */
-       if (s != NULL)
-               goto decode;
+       if (s != NULL) {
+               for (i = 0; i < nroots; i++) {
+                       /* The syndrome is in index form,
+                        * so nn represents zero
+                        */
+                       if (s[i] != nn)
+                               goto decode;
+               }
+
+               /* syndrome is zero, no errors to correct  */
+               return 0;
+       }
 
        /* form the syndromes; i.e., evaluate data(x) at roots of
         * g(x) */

Reply via email to