Skip to content

Commit 3219122

Browse files
committed
pstore/ram: Consolidate kfree() paths
There's no reason to keep separate kfree() paths: either all allocations succeeded, or not. Everything is torn down in the case of failure, so adjust the callers to reflect this. Cc: Anton Vorontsov <[email protected]> Cc: Colin Cross <[email protected]> Cc: Tony Luck <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-and-tested-by: Guilherme G. Piccoli <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 893c5f1 commit 3219122

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

fs/pstore/ram.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,12 @@ static void ramoops_free_przs(struct ramoops_context *cxt)
451451
{
452452
int i;
453453

454+
/* Free pmsg PRZ */
455+
persistent_ram_free(cxt->mprz);
456+
457+
/* Free console PRZ */
458+
persistent_ram_free(cxt->cprz);
459+
454460
/* Free dump PRZs */
455461
if (cxt->dprzs) {
456462
for (i = 0; i < cxt->max_dump_cnt; i++)
@@ -772,12 +778,12 @@ static int ramoops_probe(struct platform_device *pdev)
772778
dump_mem_sz, cxt->record_size,
773779
&cxt->max_dump_cnt, 0, 0);
774780
if (err)
775-
goto fail_out;
781+
goto fail_init;
776782

777783
err = ramoops_init_prz("console", dev, cxt, &cxt->cprz, &paddr,
778784
cxt->console_size, 0);
779785
if (err)
780-
goto fail_init_cprz;
786+
goto fail_init;
781787

782788
cxt->max_ftrace_cnt = (cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)
783789
? nr_cpu_ids
@@ -788,12 +794,12 @@ static int ramoops_probe(struct platform_device *pdev)
788794
(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)
789795
? PRZ_FLAG_NO_LOCK : 0);
790796
if (err)
791-
goto fail_init_fprz;
797+
goto fail_init;
792798

793799
err = ramoops_init_prz("pmsg", dev, cxt, &cxt->mprz, &paddr,
794800
cxt->pmsg_size, 0);
795801
if (err)
796-
goto fail_init_mprz;
802+
goto fail_init;
797803

798804
cxt->pstore.data = cxt;
799805
/*
@@ -857,11 +863,7 @@ static int ramoops_probe(struct platform_device *pdev)
857863
kfree(cxt->pstore.buf);
858864
fail_clear:
859865
cxt->pstore.bufsize = 0;
860-
persistent_ram_free(cxt->mprz);
861-
fail_init_mprz:
862-
fail_init_fprz:
863-
persistent_ram_free(cxt->cprz);
864-
fail_init_cprz:
866+
fail_init:
865867
ramoops_free_przs(cxt);
866868
fail_out:
867869
return err;
@@ -876,8 +878,6 @@ static int ramoops_remove(struct platform_device *pdev)
876878
kfree(cxt->pstore.buf);
877879
cxt->pstore.bufsize = 0;
878880

879-
persistent_ram_free(cxt->mprz);
880-
persistent_ram_free(cxt->cprz);
881881
ramoops_free_przs(cxt);
882882

883883
return 0;

0 commit comments

Comments
 (0)