@@ -274,36 +274,56 @@ static int pstore_decompress(void *in, void *out,
274
274
275
275
static 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
282
if (!IS_ENABLED (CONFIG_PSTORE_COMPRESS ) || !zbackend )
278
283
return ;
279
284
285
+ /* Skip if no pstore backend yet or compression init already done. */
286
+ if (!psinfo || tfm )
287
+ return ;
288
+
280
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
291
return ;
283
292
}
284
293
285
- big_oops_buf_sz = zbackend -> zbufsize (psinfo -> bufsize );
286
- if (big_oops_buf_sz <= 0 )
294
+ size = zbackend -> zbufsize (psinfo -> bufsize );
295
+ if (size <= 0 ) {
296
+ pr_err ("Invalid compression size for %s: %d\n" ,
297
+ zbackend -> name , size );
287
298
return ;
299
+ }
288
300
289
- big_oops_buf = kmalloc (big_oops_buf_sz , GFP_KERNEL );
290
- if (!big_oops_buf ) {
291
- pr_err ("allocate compression buffer error!\n" );
301
+ buf = kmalloc (size , GFP_KERNEL );
302
+ if (!buf ) {
303
+ pr_err ("Failed %d byte compression buffer allocation for: %s\n" ,
304
+ size , zbackend -> name );
292
305
return ;
293
306
}
294
307
295
- tfm = crypto_alloc_comp (zbackend -> name , 0 , 0 );
296
- if (IS_ERR_OR_NULL (tfm )) {
297
- kfree (big_oops_buf );
298
- big_oops_buf = NULL ;
299
- pr_err ( "crypto_alloc_comp() failed!\n" );
308
+ ctx = crypto_alloc_comp (zbackend -> name , 0 , 0 );
309
+ if (IS_ERR_OR_NULL (ctx )) {
310
+ kfree (buf );
311
+ pr_err ( "crypto_alloc_comp('%s') failed: %ld\n" , zbackend -> name ,
312
+ PTR_ERR ( ctx ) );
300
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
304
324
static 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
327
crypto_free_comp (tfm );
308
328
kfree (big_oops_buf );
309
329
big_oops_buf = NULL ;
@@ -774,7 +794,6 @@ void __init pstore_choose_compression(void)
774
794
for (step = zbackends ; step -> name ; step ++ ) {
775
795
if (!strcmp (compress , step -> name )) {
776
796
zbackend = step ;
777
- pr_info ("using %s compression\n" , zbackend -> name );
778
797
return ;
779
798
}
780
799
}
@@ -791,8 +810,7 @@ static int __init pstore_init(void)
791
810
* initialize compression because crypto was not ready. If so,
792
811
* initialize compression now.
793
812
*/
794
- if (psinfo && !tfm )
795
- allocate_buf_for_compression ();
813
+ allocate_buf_for_compression ();
796
814
797
815
ret = pstore_init_fs ();
798
816
if (ret )
0 commit comments