rslib: Fix handling of of caller provided syndrome [Linux 4.4.187]

This Linux kernel change "rslib: Fix handling of of caller provided syndrome" is included in the Linux 4.4.187 release. This change is authored by Ferdinand Blomqvist <ferdinand.blomqvist [at] gmail.com> on Thu Jun 20 17:10:37 2019 +0300. The commit for this change in Linux stable tree is a672374 (patch) which is from upstream commit ef4d6a8. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream ef4d6a8.

rslib: Fix handling of of caller provided syndrome

[ Upstream commit ef4d6a8556b637ad27c8c2a2cff1dda3da38e9a9 ]

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

Signed-off-by: Ferdinand Blomqvist <ferdinand.blomqvist@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190620141039.9874-6-ferdinand.blomqvist@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>

There are 14 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 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 8eed0f9..a5d3133 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);

    /* 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) */

Leave a Reply

Your email address will not be published. Required fields are marked *