Commit 55879dad authored by Yang Yingliang's avatar Yang Yingliang Committed by Thierry Reding

gpu: host1x: Fix memory leak of device names

The device names allocated by dev_set_name() need be freed
before module unloading, but they can not be freed because
the kobject's refcount which was set in device_initialize()
has not be decreased to 0.

As comment of device_add() says, if it fails, use only
put_device() drop the refcount, then the name will be
freed in kobejct_cleanup().

device_del() and put_device() can be replaced with
device_unregister(), so call it to unregister the added
successfully devices, and just call put_device() to the
not added device.

Add a release() function to device to avoid null release()
function WARNING in device_release(), it's empty, because
the context devices are freed together in
host1x_memory_context_list_free().

Fixes: 8aa5bcb6 ("gpu: host1x: Add context device management code")
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
Reviewed-by: default avatarMikko Perttunen <mperttunen@nvidia.com>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
parent 8466ff24
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
#include "context.h" #include "context.h"
#include "dev.h" #include "dev.h"
static void host1x_memory_context_release(struct device *dev)
{
/* context device is freed in host1x_memory_context_list_free() */
}
int host1x_memory_context_list_init(struct host1x *host1x) int host1x_memory_context_list_init(struct host1x *host1x)
{ {
struct host1x_memory_context_list *cdl = &host1x->context_list; struct host1x_memory_context_list *cdl = &host1x->context_list;
...@@ -51,36 +56,38 @@ int host1x_memory_context_list_init(struct host1x *host1x) ...@@ -51,36 +56,38 @@ int host1x_memory_context_list_init(struct host1x *host1x)
dev_set_name(&ctx->dev, "host1x-ctx.%d", i); dev_set_name(&ctx->dev, "host1x-ctx.%d", i);
ctx->dev.bus = &host1x_context_device_bus_type; ctx->dev.bus = &host1x_context_device_bus_type;
ctx->dev.parent = host1x->dev; ctx->dev.parent = host1x->dev;
ctx->dev.release = host1x_memory_context_release;
dma_set_max_seg_size(&ctx->dev, UINT_MAX); dma_set_max_seg_size(&ctx->dev, UINT_MAX);
err = device_add(&ctx->dev); err = device_add(&ctx->dev);
if (err) { if (err) {
dev_err(host1x->dev, "could not add context device %d: %d\n", i, err); dev_err(host1x->dev, "could not add context device %d: %d\n", i, err);
goto del_devices; put_device(&ctx->dev);
goto unreg_devices;
} }
err = of_dma_configure_id(&ctx->dev, node, true, &i); err = of_dma_configure_id(&ctx->dev, node, true, &i);
if (err) { if (err) {
dev_err(host1x->dev, "IOMMU configuration failed for context device %d: %d\n", dev_err(host1x->dev, "IOMMU configuration failed for context device %d: %d\n",
i, err); i, err);
device_del(&ctx->dev); device_unregister(&ctx->dev);
goto del_devices; goto unreg_devices;
} }
if (!tegra_dev_iommu_get_stream_id(&ctx->dev, &ctx->stream_id) || if (!tegra_dev_iommu_get_stream_id(&ctx->dev, &ctx->stream_id) ||
!device_iommu_mapped(&ctx->dev)) { !device_iommu_mapped(&ctx->dev)) {
dev_err(host1x->dev, "Context device %d has no IOMMU!\n", i); dev_err(host1x->dev, "Context device %d has no IOMMU!\n", i);
device_del(&ctx->dev); device_unregister(&ctx->dev);
goto del_devices; goto unreg_devices;
} }
} }
return 0; return 0;
del_devices: unreg_devices:
while (i--) while (i--)
device_del(&cdl->devs[i].dev); device_unregister(&cdl->devs[i].dev);
kfree(cdl->devs); kfree(cdl->devs);
cdl->devs = NULL; cdl->devs = NULL;
...@@ -94,7 +101,7 @@ void host1x_memory_context_list_free(struct host1x_memory_context_list *cdl) ...@@ -94,7 +101,7 @@ void host1x_memory_context_list_free(struct host1x_memory_context_list *cdl)
unsigned int i; unsigned int i;
for (i = 0; i < cdl->len; i++) for (i = 0; i < cdl->len; i++)
device_del(&cdl->devs[i].dev); device_unregister(&cdl->devs[i].dev);
kfree(cdl->devs); kfree(cdl->devs);
cdl->len = 0; cdl->len = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment