Skip to content

Commit 5529415

Browse files
thierryredinghtejun
authored andcommitted
ata: libahci: Fix devres cleanup on failure
Commit c7d7dde ("ata: libahci: Allow using multiple regulators") releases regulators during ahci_platform_put_resources(). That doesn't work because the function is run as part of the devres machinery. Such resources are torn down in reverse order. Since the array that holds pointers to the regulators is allocated using devres after the device context to which ahci_platform_put_resources() is attached, the memory will be freed before calling ahci_platform_put_resources() and thereby causing a use-after-free error. This commit fixes this by using regular allocations for the array. The memory can then be freed after the regulators have been released. This conserves the advantages of using the managed API. Reported-by: Paul Walmsley <paul@pwsan.com> Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent c7d7dde commit 5529415

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎drivers/ata/libahci_platform.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ static void ahci_platform_put_resources(struct device *dev, void *res)
276276
if (hpriv->target_pwrs && hpriv->target_pwrs[c])
277277
regulator_put(hpriv->target_pwrs[c]);
278278

279+
kfree(hpriv->target_pwrs);
279280
}
280281

281282
static int ahci_platform_get_phy(struct ahci_host_priv *hpriv, u32 port,
@@ -412,7 +413,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev)
412413
goto err_out;
413414
}
414415
sz = hpriv->nports * sizeof(*hpriv->target_pwrs);
415-
hpriv->target_pwrs = devm_kzalloc(dev, sz, GFP_KERNEL);
416+
hpriv->target_pwrs = kzalloc(sz, GFP_KERNEL);
416417
if (!hpriv->target_pwrs) {
417418
rc = -ENOMEM;
418419
goto err_out;

0 commit comments

Comments
 (0)