Re: [PATCH -next] acpi/hmat: fix memory leaks in hmat_init()

From: Rafael J. Wysocki
Date: Tue Apr 09 2019 - 17:34:55 EST


On Tue, Apr 9, 2019 at 5:33 PM Qian Cai <cai@xxxxxx> wrote:
>
> On Tue, 2019-04-09 at 16:54 +0200, Rafael J. Wysocki wrote:
> > Fewer jumps are easier to follow in general, so avoiding ones that can
> > be avoided is helpful.
> >
> > I'm not buying the argument about more code line changes needed if the
> > function name changes. It's meaningless.
> >
> > And if you check the return value of acpi_get_table() for SRAT after
> > calling acpi_put_table(tbl), you will only need the out_free label, if
> > I'm not mistaken.
>
> I don't really understand this.

Sorry, I didn't have the original code in front of me when I was
writing my reply.

I was thinking about checking the return value of
acpi_table_parse_entries() after calling acpi_put_table(tbl). Then,
if it returns an error, you only need to call hmat_free_structures().

Similarly, if acpi_get_table(ACPI_SIG_HMAT, 0, &tbl) returns an error,
you only need to call hmat_free_structures().

But I didn't remember the other jumps to out_put.

Still, since it is valid to pass NULL to acpi_put_table(), you can
jump to out_put if acpi_get_table(ACPI_SIG_HMAT, 0, &tbl) returns an
error too.