nvmap: Register nvmap device towards end of probe

On TOT, in nvmap probe function, platform_set_drvdata is called after
misc register. So nvmap node is created and clients can open it even
before platform driver data is set. Because of which, the call to
dev_get_drvdata returns NULL and BUG_ON condition is hit. Move misc
register call towards end of the nvmap probe, so that /dev/nvmap is
exposed once all initilization is completed.
As misc register being moved to end of probe, the functions which are
called before misc register and which make use of dev_user field from
nvmap_device for calling dev_err/dev_info function will see the dev
field as NULL. Hence replace such calls with pr_err/pr_info.

Bug 3853486

Change-Id: Ifdd8443812a621aceada7739cf9b02fcf00568b4
Signed-off-by: Ketan Patil <ketanp@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2803672
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: svc_kernel_abi <svc_kernel_abi@nvidia.com>
Reviewed-by: Sachin Nikam <snikam@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
Ketan Patil
2022-11-05 17:13:28 +00:00
committed by Laxman Dewangan
parent 92f34279ba
commit 596156cc4b
3 changed files with 15 additions and 22 deletions

View File

@@ -1425,13 +1425,6 @@ int __init nvmap_probe(struct platform_device *pdev)
mutex_init(&dev->tags_lock); mutex_init(&dev->tags_lock);
mutex_init(&dev->carveout_lock); mutex_init(&dev->carveout_lock);
e = misc_register(&dev->dev_user);
if (e) {
dev_err(&pdev->dev, "unable to register miscdevice %s\n",
dev->dev_user.name);
goto fail;
}
nvmap_debug_root = debugfs_create_dir("nvmap", NULL); nvmap_debug_root = debugfs_create_dir("nvmap", NULL);
nvmap_dev->debug_root = nvmap_debug_root; nvmap_dev->debug_root = nvmap_debug_root;
if (IS_ERR_OR_NULL(nvmap_debug_root)) if (IS_ERR_OR_NULL(nvmap_debug_root))
@@ -1503,11 +1496,15 @@ int __init nvmap_probe(struct platform_device *pdev)
} }
#endif /* CVNAS_BUILTIN */ #endif /* CVNAS_BUILTIN */
e = misc_register(&dev->dev_user);
if (e) {
dev_err(&pdev->dev, "unable to register miscdevice %s\n",
dev->dev_user.name);
goto fail_sci_ipc;
}
goto finish; goto finish;
#ifdef CVNAS_BUILTIN
fail_sci_ipc: fail_sci_ipc:
nvmap_sci_ipc_exit(); nvmap_sci_ipc_exit();
#endif /* CVNAS_BUILTIN */
fail_heaps: fail_heaps:
debugfs_remove_recursive(nvmap_dev->debug_root); debugfs_remove_recursive(nvmap_dev->debug_root);
for (i = 0; i < dev->nr_carveouts; i++) { for (i = 0; i < dev->nr_carveouts; i++) {

View File

@@ -442,7 +442,7 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent,
h = kzalloc(sizeof(*h), GFP_KERNEL); h = kzalloc(sizeof(*h), GFP_KERNEL);
if (!h) { if (!h) {
dev_err(parent, "%s: out of memory\n", __func__); pr_err("%s: out of memory\n", __func__);
return NULL; return NULL;
} }
@@ -460,7 +460,7 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent,
h->cma_dev = co->cma_dev; h->cma_dev = co->cma_dev;
#endif #endif
#else #else
dev_err(parent, "invalid resize config for carveout %s\n", pr_err("invalid resize config for carveout %s\n",
co->name); co->name);
goto fail; goto fail;
#endif #endif
@@ -480,12 +480,10 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent,
#else #else
if (err & DMA_MEMORY_NOMAP) { if (err & DMA_MEMORY_NOMAP) {
#endif #endif
dev_info(parent, pr_info("%s :dma coherent mem declare %pa,%zu\n",
"%s :dma coherent mem declare %pa,%zu\n",
co->name, &base, len); co->name, &base, len);
} else { } else {
dev_err(parent, pr_err("%s: dma coherent declare fail %pa,%zu\n",
"%s: dma coherent declare fail %pa,%zu\n",
co->name, &base, len); co->name, &base, len);
goto fail; goto fail;
} }
@@ -521,7 +519,7 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent,
if (!co->no_cpu_access && co->usage_mask != NVMAP_HEAP_CARVEOUT_VPR if (!co->no_cpu_access && co->usage_mask != NVMAP_HEAP_CARVEOUT_VPR
&& nvmap_cache_maint_phys_range(NVMAP_CACHE_OP_WB_INV, && nvmap_cache_maint_phys_range(NVMAP_CACHE_OP_WB_INV,
base, base + len, true, true)) { base, base + len, true, true)) {
dev_err(parent, "cache flush failed\n"); pr_err("cache flush failed\n");
goto fail; goto fail;
} }
} }
@@ -533,7 +531,7 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent,
if (co->no_cpu_access) if (co->no_cpu_access)
nvmap_dev->cpu_access_mask &= ~co->usage_mask; nvmap_dev->cpu_access_mask &= ~co->usage_mask;
dev_info(parent, "created heap %s base 0x%px size (%zuKiB)\n", pr_info("created heap %s base 0x%px size (%zuKiB)\n",
co->name, (void *)(uintptr_t)base, len/1024); co->name, (void *)(uintptr_t)base, len/1024);
return h; return h;
fail: fail:

View File

@@ -683,14 +683,12 @@ static int __init nvmap_co_device_init(struct reserved_mem *rmem,
#else #else
if (err & DMA_MEMORY_NOMAP) { if (err & DMA_MEMORY_NOMAP) {
#endif #endif
dev_info(dev, pr_info("%s :dma coherent mem declare %pa,%zu\n",
"%s :dma coherent mem declare %pa,%zu\n",
co->name, &co->base, co->size); co->name, &co->base, co->size);
co->init_done = true; co->init_done = true;
err = 0; err = 0;
} else } else
dev_err(dev, pr_err("%s :dma coherent mem declare fail %pa,%zu,err:%d\n",
"%s :dma coherent mem declare fail %pa,%zu,err:%d\n",
co->name, &co->base, co->size, err); co->name, &co->base, co->size, err);
} else { } else {
#ifdef NVMAP_CONFIG_VPR_RESIZE #ifdef NVMAP_CONFIG_VPR_RESIZE
@@ -710,7 +708,7 @@ static int __init nvmap_co_device_init(struct reserved_mem *rmem,
err = dma_declare_coherent_resizable_cma_memory( err = dma_declare_coherent_resizable_cma_memory(
co->dma_dev, co->dma_info); co->dma_dev, co->dma_info);
if (err) if (err)
dev_err(dev, "%s coherent memory declaration failed\n", pr_err("%s coherent memory declaration failed\n",
co->name); co->name);
else else
#endif #endif