]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - lib/842/842_decompress.c
treewide: Fix typo in printk
[karo-tx-linux.git] / lib / 842 / 842_decompress.c
index 5446ff0c9ba0f186448cffc34942858dc1a7d0a9..a2a941f8112ddb9bb32f00afa2c0f2299ccf1950 100644 (file)
@@ -250,7 +250,7 @@ static int do_op(struct sw842_param *p, u8 o)
                case OP_ACTION_NOOP:
                        break;
                default:
-                       pr_err("Interal error, invalid op %x\n", op);
+                       pr_err("Internal error, invalid op %x\n", op);
                        return -EINVAL;
                }
 
@@ -285,6 +285,7 @@ int sw842_decompress(const u8 *in, unsigned int ilen,
        struct sw842_param p;
        int ret;
        u64 op, rep, tmp, bytes, total;
+       u64 crc;
 
        p.in = (u8 *)in;
        p.bit = 0;
@@ -375,6 +376,22 @@ int sw842_decompress(const u8 *in, unsigned int ilen,
                }
        } while (op != OP_END);
 
+       /*
+        * crc(0:31) is saved in compressed data starting with the
+        * next bit after End of stream template.
+        */
+       ret = next_bits(&p, &crc, CRC_BITS);
+       if (ret)
+               return ret;
+
+       /*
+        * Validate CRC saved in compressed data.
+        */
+       if (crc != (u64)crc32_be(0, out, total - p.olen)) {
+               pr_debug("CRC mismatch for decompression\n");
+               return -EINVAL;
+       }
+
        if (unlikely((total - p.olen) > UINT_MAX))
                return -ENOSPC;