842_decompress.c (01b944fe1cd4e21a2a9ed51adbdbafe2d5e905ba) 842_decompress.c (ea0b3984c1cc8b28de27a3bec285102b4e366a4c)
1/*
2 * 842 Software Decompression
3 *
4 * Copyright (C) 2015 Dan Streetman, IBM Corp
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 271 unchanged lines hidden (view full) ---

280 * 0 on error.
281 */
282int sw842_decompress(const u8 *in, unsigned int ilen,
283 u8 *out, unsigned int *olen)
284{
285 struct sw842_param p;
286 int ret;
287 u64 op, rep, tmp, bytes, total;
1/*
2 * 842 Software Decompression
3 *
4 * Copyright (C) 2015 Dan Streetman, IBM Corp
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 271 unchanged lines hidden (view full) ---

280 * 0 on error.
281 */
282int sw842_decompress(const u8 *in, unsigned int ilen,
283 u8 *out, unsigned int *olen)
284{
285 struct sw842_param p;
286 int ret;
287 u64 op, rep, tmp, bytes, total;
288 u64 crc;
288
289 p.in = (u8 *)in;
290 p.bit = 0;
291 p.ilen = ilen;
292 p.out = out;
293 p.ostart = out;
294 p.olen = *olen;
295

--- 74 unchanged lines hidden (view full) ---

370 default: /* use template */
371 ret = do_op(&p, op);
372 if (ret)
373 return ret;
374 break;
375 }
376 } while (op != OP_END);
377
289
290 p.in = (u8 *)in;
291 p.bit = 0;
292 p.ilen = ilen;
293 p.out = out;
294 p.ostart = out;
295 p.olen = *olen;
296

--- 74 unchanged lines hidden (view full) ---

371 default: /* use template */
372 ret = do_op(&p, op);
373 if (ret)
374 return ret;
375 break;
376 }
377 } while (op != OP_END);
378
379 /*
380 * crc(0:31) is saved in compressed data starting with the
381 * next bit after End of stream template.
382 */
383 ret = next_bits(&p, &crc, CRC_BITS);
384 if (ret)
385 return ret;
386
387 /*
388 * Validate CRC saved in compressed data.
389 */
390 if (crc != (u64)crc32_be(0, out, total - p.olen)) {
391 pr_debug("CRC mismatch for decompression\n");
392 return -EINVAL;
393 }
394
378 if (unlikely((total - p.olen) > UINT_MAX))
379 return -ENOSPC;
380
381 *olen = total - p.olen;
382
383 return 0;
384}
385EXPORT_SYMBOL_GPL(sw842_decompress);

--- 20 unchanged lines hidden ---
395 if (unlikely((total - p.olen) > UINT_MAX))
396 return -ENOSPC;
397
398 *olen = total - p.olen;
399
400 return 0;
401}
402EXPORT_SYMBOL_GPL(sw842_decompress);

--- 20 unchanged lines hidden ---