mirror of
https://github.com/torvalds/linux.git
synced 2024-11-13 23:51:39 +00:00
cc87253e22
The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is ignored (apart from emitting a warning) and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new(), which already returns void. Eventually after all drivers are converted, .remove_new() will be renamed to .remove(). Trivially convert this driver from always returning zero in the remove callback to the void returning variant. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Juergen Gross <jgross@suse.com> Link: https://lore.kernel.org/r/20240307181135.191192-2-u.kleine-koenig@pengutronix.de Signed-off-by: Juergen Gross <jgross@suse.com>
84 lines
1.9 KiB
C
84 lines
1.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Stub IOMMU driver which does nothing.
|
|
* The main purpose of it being present is to reuse generic IOMMU device tree
|
|
* bindings by Xen grant DMA-mapping layer.
|
|
*
|
|
* Copyright (C) 2022 EPAM Systems Inc.
|
|
*/
|
|
|
|
#include <linux/iommu.h>
|
|
#include <linux/of.h>
|
|
#include <linux/platform_device.h>
|
|
|
|
struct grant_dma_iommu_device {
|
|
struct device *dev;
|
|
struct iommu_device iommu;
|
|
};
|
|
|
|
static struct iommu_device *grant_dma_iommu_probe_device(struct device *dev)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
/* Nothing is really needed here except a dummy probe_device callback */
|
|
static const struct iommu_ops grant_dma_iommu_ops = {
|
|
.probe_device = grant_dma_iommu_probe_device,
|
|
};
|
|
|
|
static const struct of_device_id grant_dma_iommu_of_match[] = {
|
|
{ .compatible = "xen,grant-dma" },
|
|
{ },
|
|
};
|
|
|
|
static int grant_dma_iommu_probe(struct platform_device *pdev)
|
|
{
|
|
struct grant_dma_iommu_device *mmu;
|
|
int ret;
|
|
|
|
mmu = devm_kzalloc(&pdev->dev, sizeof(*mmu), GFP_KERNEL);
|
|
if (!mmu)
|
|
return -ENOMEM;
|
|
|
|
mmu->dev = &pdev->dev;
|
|
|
|
ret = iommu_device_register(&mmu->iommu, &grant_dma_iommu_ops, &pdev->dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
platform_set_drvdata(pdev, mmu);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void grant_dma_iommu_remove(struct platform_device *pdev)
|
|
{
|
|
struct grant_dma_iommu_device *mmu = platform_get_drvdata(pdev);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
iommu_device_unregister(&mmu->iommu);
|
|
}
|
|
|
|
static struct platform_driver grant_dma_iommu_driver = {
|
|
.driver = {
|
|
.name = "grant-dma-iommu",
|
|
.of_match_table = grant_dma_iommu_of_match,
|
|
},
|
|
.probe = grant_dma_iommu_probe,
|
|
.remove_new = grant_dma_iommu_remove,
|
|
};
|
|
|
|
static int __init grant_dma_iommu_init(void)
|
|
{
|
|
struct device_node *iommu_np;
|
|
|
|
iommu_np = of_find_matching_node(NULL, grant_dma_iommu_of_match);
|
|
if (!iommu_np)
|
|
return 0;
|
|
|
|
of_node_put(iommu_np);
|
|
|
|
return platform_driver_register(&grant_dma_iommu_driver);
|
|
}
|
|
subsys_initcall(grant_dma_iommu_init);
|