aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/pstore/platform.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 578f178a695f..b821054ca3ed 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -274,36 +274,56 @@ static int pstore_decompress(void *in, void *out,
274 274
275static void allocate_buf_for_compression(void) 275static void allocate_buf_for_compression(void)
276{ 276{
277 struct crypto_comp *ctx;
278 int size;
279 char *buf;
280
281 /* Skip if not built-in or compression backend not selected yet. */
277 if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend) 282 if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend)
278 return; 283 return;
279 284
285 /* Skip if no pstore backend yet or compression init already done. */
286 if (!psinfo || tfm)
287 return;
288
280 if (!crypto_has_comp(zbackend->name, 0, 0)) { 289 if (!crypto_has_comp(zbackend->name, 0, 0)) {
281 pr_err("No %s compression\n", zbackend->name); 290 pr_err("Unknown compression: %s\n", zbackend->name);
282 return; 291 return;
283 } 292 }
284 293
285 big_oops_buf_sz = zbackend->zbufsize(psinfo->bufsize); 294 size = zbackend->zbufsize(psinfo->bufsize);
286 if (big_oops_buf_sz <= 0) 295 if (size <= 0) {
296 pr_err("Invalid compression size for %s: %d\n",
297 zbackend->name, size);
287 return; 298 return;
299 }
288 300
289 big_oops_buf = kmalloc(big_oops_buf_sz, GFP_KERNEL); 301 buf = kmalloc(size, GFP_KERNEL);
290 if (!big_oops_buf) { 302 if (!buf) {
291 pr_err("allocate compression buffer error!\n"); 303 pr_err("Failed %d byte compression buffer allocation for: %s\n",
304 size, zbackend->name);
292 return; 305 return;
293 } 306 }
294 307
295 tfm = crypto_alloc_comp(zbackend->name, 0, 0); 308 ctx = crypto_alloc_comp(zbackend->name, 0, 0);
296 if (IS_ERR_OR_NULL(tfm)) { 309 if (IS_ERR_OR_NULL(ctx)) {
297 kfree(big_oops_buf); 310 kfree(buf);
298 big_oops_buf = NULL; 311 pr_err("crypto_alloc_comp('%s') failed: %ld\n", zbackend->name,
299 pr_err("crypto_alloc_comp() failed!\n"); 312 PTR_ERR(ctx));
300 return; 313 return;
301 } 314 }
315
316 /* A non-NULL big_oops_buf indicates compression is available. */
317 tfm = ctx;
318 big_oops_buf_sz = size;
319 big_oops_buf = buf;
320
321 pr_info("Using compression: %s\n", zbackend->name);
302} 322}
303 323
304static void free_buf_for_compression(void) 324static void free_buf_for_compression(void)
305{ 325{
306 if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && !IS_ERR_OR_NULL(tfm)) 326 if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm)
307 crypto_free_comp(tfm); 327 crypto_free_comp(tfm);
308 kfree(big_oops_buf); 328 kfree(big_oops_buf);
309 big_oops_buf = NULL; 329 big_oops_buf = NULL;
@@ -774,7 +794,6 @@ void __init pstore_choose_compression(void)
774 for (step = zbackends; step->name; step++) { 794 for (step = zbackends; step->name; step++) {
775 if (!strcmp(compress, step->name)) { 795 if (!strcmp(compress, step->name)) {
776 zbackend = step; 796 zbackend = step;
777 pr_info("using %s compression\n", zbackend->name);
778 return; 797 return;
779 } 798 }
780 } 799 }
@@ -791,8 +810,7 @@ static int __init pstore_init(void)
791 * initialize compression because crypto was not ready. If so, 810 * initialize compression because crypto was not ready. If so,
792 * initialize compression now. 811 * initialize compression now.
793 */ 812 */
794 if (psinfo && !tfm) 813 allocate_buf_for_compression();
795 allocate_buf_for_compression();
796 814
797 ret = pstore_init_fs(); 815 ret = pstore_init_fs();
798 if (ret) 816 if (ret)