Sascha Hauer b33528863d PCI/sysfs: Fix double free in error path
commit aa382ffa705bea9931ec92b6f3c70e1fdb372195 upstream.

When pci_create_attr() fails, pci_remove_resource_files() is called which
will iterate over the res_attr[_wc] arrays and frees every non NULL entry.
To avoid a double free here set the array entry only after it's clear we
successfully initialized it.

Fixes: b562ec8f74e4 ("PCI: Don't leak memory if sysfs_create_bin_file() fails")
Link: https://lore.kernel.org/r/20221007070735.GX986@pengutronix.de/
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-01-07 11:11:53 +01:00
..
2022-10-05 17:32:53 -05:00
2021-06-16 17:20:40 -05:00
2022-03-07 12:06:10 -07:00
2022-08-10 11:07:26 -07:00
2022-05-31 09:56:54 -07:00
2022-10-05 17:32:57 -05:00
2021-02-10 16:46:29 -06:00
2021-09-28 13:43:17 -05:00
2020-08-05 18:23:14 -05:00