From 596156cc4b3eebffa78edba31c21b5526a2083c2 Mon Sep 17 00:00:00 2001 From: Ketan Patil Date: Sat, 5 Nov 2022 17:13:28 +0000 Subject: [PATCH] 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 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2803672 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: svc_kernel_abi Reviewed-by: Sachin Nikam GVS: Gerrit_Virtual_Submit --- drivers/video/tegra/nvmap/nvmap_dev.c | 15 ++++++--------- drivers/video/tegra/nvmap/nvmap_heap.c | 14 ++++++-------- drivers/video/tegra/nvmap/nvmap_init.c | 8 +++----- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c index b4c6f2ac..5b8c913f 100644 --- a/drivers/video/tegra/nvmap/nvmap_dev.c +++ b/drivers/video/tegra/nvmap/nvmap_dev.c @@ -1425,13 +1425,6 @@ int __init nvmap_probe(struct platform_device *pdev) mutex_init(&dev->tags_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_dev->debug_root = 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 */ + 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; -#ifdef CVNAS_BUILTIN fail_sci_ipc: nvmap_sci_ipc_exit(); -#endif /* CVNAS_BUILTIN */ fail_heaps: debugfs_remove_recursive(nvmap_dev->debug_root); for (i = 0; i < dev->nr_carveouts; i++) { diff --git a/drivers/video/tegra/nvmap/nvmap_heap.c b/drivers/video/tegra/nvmap/nvmap_heap.c index 3d8371f5..8fcdf433 100644 --- a/drivers/video/tegra/nvmap/nvmap_heap.c +++ b/drivers/video/tegra/nvmap/nvmap_heap.c @@ -442,7 +442,7 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent, h = kzalloc(sizeof(*h), GFP_KERNEL); if (!h) { - dev_err(parent, "%s: out of memory\n", __func__); + pr_err("%s: out of memory\n", __func__); return NULL; } @@ -460,7 +460,7 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent, h->cma_dev = co->cma_dev; #endif #else - dev_err(parent, "invalid resize config for carveout %s\n", + pr_err("invalid resize config for carveout %s\n", co->name); goto fail; #endif @@ -480,12 +480,10 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent, #else if (err & DMA_MEMORY_NOMAP) { #endif - dev_info(parent, - "%s :dma coherent mem declare %pa,%zu\n", + pr_info("%s :dma coherent mem declare %pa,%zu\n", co->name, &base, len); } else { - dev_err(parent, - "%s: dma coherent declare fail %pa,%zu\n", + pr_err("%s: dma coherent declare fail %pa,%zu\n", co->name, &base, len); 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 && nvmap_cache_maint_phys_range(NVMAP_CACHE_OP_WB_INV, base, base + len, true, true)) { - dev_err(parent, "cache flush failed\n"); + pr_err("cache flush failed\n"); goto fail; } } @@ -533,7 +531,7 @@ struct nvmap_heap *nvmap_heap_create(struct device *parent, if (co->no_cpu_access) 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); return h; fail: diff --git a/drivers/video/tegra/nvmap/nvmap_init.c b/drivers/video/tegra/nvmap/nvmap_init.c index fe96818e..14bb3ce7 100644 --- a/drivers/video/tegra/nvmap/nvmap_init.c +++ b/drivers/video/tegra/nvmap/nvmap_init.c @@ -683,14 +683,12 @@ static int __init nvmap_co_device_init(struct reserved_mem *rmem, #else if (err & DMA_MEMORY_NOMAP) { #endif - dev_info(dev, - "%s :dma coherent mem declare %pa,%zu\n", + pr_info("%s :dma coherent mem declare %pa,%zu\n", co->name, &co->base, co->size); co->init_done = true; err = 0; } else - dev_err(dev, - "%s :dma coherent mem declare fail %pa,%zu,err:%d\n", + pr_err("%s :dma coherent mem declare fail %pa,%zu,err:%d\n", co->name, &co->base, co->size, err); } else { #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( co->dma_dev, co->dma_info); if (err) - dev_err(dev, "%s coherent memory declaration failed\n", + pr_err("%s coherent memory declaration failed\n", co->name); else #endif