PCI/sysfs: Fix double free in error path
authorSascha Hauer <s.hauer@pengutronix.de>
Tue, 8 Nov 2022 23:05:59 +0000 (17:05 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 9 Nov 2022 22:57:29 +0000 (16:57 -0600)
commitaa382ffa705bea9931ec92b6f3c70e1fdb372195
treea69627409a451028d100ef6b346027d6befb7a60
parent9abf2313adc1ca1b6180c508c25f22f9395cc780
PCI/sysfs: Fix double free in error path

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
drivers/pci/pci-sysfs.c