From 29e88ed17e757c0129a54a3fb44990cec4a33983 Mon Sep 17 00:00:00 2001 From: Ankur Pawar Date: Thu, 15 Feb 2024 10:48:41 +0000 Subject: [PATCH] camera: fix the kernel freeze after driver unbind Kernel freeze is occurring due to incorrect cleanup in vi5.c. Fix for kernel freeze: 1 Don't call vi_channel_drv_unregister() and tegra_vi_media_controller_cleanup() in vi5_remove. 2 capture_vi_probe() is calling vi_channel_drv_register() and tegra_capture_vi_media_controller_init(), so capture_vi_remove() should call vi_channel_drv_unregister() and tegra_vi_media_controller_cleanup() 3 Use correct dev pointer in vi_channel_drv_unregister(). Code cleanup: 1 Remove use_legacy_path variable that was used for T186. 2 Removed unused t194_vi5_file_private struct. Bug 4415340 Change-Id: I6153f65d62a9f7f4fc5d04c2ace948a29396e404 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3077660 Reviewed-by: Shubham Chandra Reviewed-by: Ankur Pawar Reviewed-by: Laxman Dewangan GVS: Gerrit_Virtual_Submit Tested-by: Ankur Pawar --- .../camera/fusa-capture/capture-vi-channel.c | 50 +++++++------------ .../tegra/camera/fusa-capture/capture-vi.c | 23 ++++----- drivers/video/tegra/host/vi/vi5.c | 13 ----- .../media/fusa-capture/capture-vi-channel.h | 9 +--- 4 files changed, 30 insertions(+), 65 deletions(-) diff --git a/drivers/media/platform/tegra/camera/fusa-capture/capture-vi-channel.c b/drivers/media/platform/tegra/camera/fusa-capture/capture-vi-channel.c index 3e9a26f5..0e6b74ac 100644 --- a/drivers/media/platform/tegra/camera/fusa-capture/capture-vi-channel.c +++ b/drivers/media/platform/tegra/camera/fusa-capture/capture-vi-channel.c @@ -1,10 +1,10 @@ -// SPDX-License-Identifier: GPL-2.0 -// Copyright (c) 2017-2023 NVIDIA Corporation. All rights reserved. +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. /** * @file drivers/media/platform/tegra/camera/fusa-capture/capture-vi-channel.c * - * @brief VI channel character device driver for the T186/T194 Camera RTCPU + * @brief VI channel character device driver for the T234 Camera RTCPU * platform. */ @@ -204,11 +204,7 @@ struct tegra_vi_channel *vi_channel_open_ex( return ERR_PTR(-ENOMEM); chan->drv = chan_drv; - if (chan_drv->use_legacy_path) { - chan->dev = chan_drv->dev; - chan->ndev = chan_drv->ndev; - } else - chan->vi_capture_pdev = chan_drv->vi_capture_pdev; + chan->vi_capture_pdev = chan_drv->vi_capture_pdev; chan->ops = chan_drv->ops; @@ -390,17 +386,14 @@ static long vi_channel_ioctl( if (copy_from_user(&setup, ptr, sizeof(setup))) break; - if (chan->drv->use_legacy_path == false) { - vi_get_nvhost_device(chan, &setup); - if (chan->dev == NULL) { - dev_err(&chan->vi_capture_pdev->dev, - "%s: channel device is NULL", - __func__); - return -EINVAL; - } + vi_get_nvhost_device(chan, &setup); + if (chan->dev == NULL) { + dev_err(&chan->vi_capture_pdev->dev, + "%s: channel device is NULL", + __func__); + return -EINVAL; } - if (setup.request_size < sizeof(struct capture_descriptor)) { dev_err(chan->dev, "request size is too small to fit capture descriptor\n"); @@ -650,16 +643,10 @@ int vi_channel_drv_register( if (unlikely(chan_drv == NULL)) return -ENOMEM; - if (strstr(ndev->name, "tegra-capture-vi") == NULL) { - chan_drv->use_legacy_path = true; - chan_drv->dev = &ndev->dev; - chan_drv->ndev = ndev; - } else { - chan_drv->use_legacy_path = false; - chan_drv->dev = NULL; - chan_drv->ndev = NULL; - chan_drv->vi_capture_pdev = ndev; - } + chan_drv->dev = NULL; + chan_drv->ndev = NULL; + chan_drv->vi_capture_pdev = ndev; + chan_drv->num_channels = max_vi_channels; mutex_init(&chan_drv->lock); @@ -676,9 +663,7 @@ int vi_channel_drv_register( for (i = 0; i < chan_drv->num_channels; i++) { dev_t devt = MKDEV(vi_channel_major, i); - struct device *dev = - (chan_drv->use_legacy_path)?chan_drv->dev : - &chan_drv->vi_capture_pdev->dev; + struct device *dev = &chan_drv->vi_capture_pdev->dev; device_create(vi_channel_class, dev, devt, NULL, "capture-vi-channel%u", i); } @@ -725,7 +710,8 @@ void vi_channel_drv_unregister( mutex_lock(&chdrv_lock); chan_drv = chdrv_; chdrv_ = NULL; - WARN_ON(chan_drv->dev != dev); + + WARN_ON(&chan_drv->vi_capture_pdev->dev != dev); mutex_unlock(&chdrv_lock); for (i = 0; i < chan_drv->num_channels; i++) { @@ -734,7 +720,7 @@ void vi_channel_drv_unregister( device_destroy(vi_channel_class, devt); } - devm_kfree(chan_drv->dev, chan_drv); + devm_kfree(&chan_drv->vi_capture_pdev->dev, chan_drv); } EXPORT_SYMBOL(vi_channel_drv_unregister); diff --git a/drivers/media/platform/tegra/camera/fusa-capture/capture-vi.c b/drivers/media/platform/tegra/camera/fusa-capture/capture-vi.c index 5d6e6c71..f1a3e19c 100644 --- a/drivers/media/platform/tegra/camera/fusa-capture/capture-vi.c +++ b/drivers/media/platform/tegra/camera/fusa-capture/capture-vi.c @@ -1,10 +1,10 @@ -// SPDX-License-Identifier: GPL-2.0 -// Copyright (c) 2017-2023 NVIDIA Corporation. All rights reserved. +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. /** * @file drivers/media/platform/tegra/camera/fusa-capture/capture-vi.c * - * @brief VI channel operations for the T186/T194 Camera RTCPU platform. + * @brief VI channel operations for the T234 Camera RTCPU platform. */ #include @@ -448,10 +448,7 @@ int vi_capture_init( struct platform_device *rtc_pdev; struct device *dev; - if (chan->drv->use_legacy_path) - dev = chan->dev; - else - dev = &chan->vi_capture_pdev->dev; + dev = &chan->vi_capture_pdev->dev; dev_dbg(dev, "%s++\n", __func__); dn = of_find_node_by_path("tegra-camera-rtcpu"); @@ -595,10 +592,7 @@ int vi_capture_setup( uint32_t vi_inst = 0; struct device *dev; - if (chan->drv->use_legacy_path) - dev = chan->dev; - else - dev = &chan->vi_capture_pdev->dev; + dev = &chan->vi_capture_pdev->dev; if (setup->csi_stream_id >= MAX_NVCSI_STREAM_IDS || setup->virtual_channel_id >= MAX_VIRTUAL_CHANNEL_PER_STREAM) { @@ -1664,7 +1658,7 @@ static int capture_vi_probe(struct platform_device *pdev) err = vi_channel_drv_register(pdev, info->max_vi_channels); if (err) { - vi_channel_drv_exit(); + vi_channel_drv_exit(); goto cleanup; } @@ -1702,7 +1696,10 @@ static int capture_vi_remove(struct platform_device *pdev) for (ii = 0; ii < info->num_vi_devices; ii++) put_device(&info->vi_pdevices[ii]->dev); - vi_channel_drv_exit(); + vi_channel_drv_unregister(&pdev->dev); + tegra_vi_media_controller_cleanup(&info->vi_common.mc_vi); + vi_channel_drv_exit(); + return 0; } diff --git a/drivers/video/tegra/host/vi/vi5.c b/drivers/video/tegra/host/vi/vi5.c index 95fecd1b..e7f6e51d 100644 --- a/drivers/video/tegra/host/vi/vi5.c +++ b/drivers/video/tegra/host/vi/vi5.c @@ -1,11 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only // SPDX-FileCopyrightText: Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. /* -<<<<<<< HEAD (246e62 video: tegra: remove icc request in system resume) - * SPDX-FileCopyrightText: Copyright (C) 2017-2023 NVIDIA CORPORATION. All rights reserved. -======= * VI5 driver ->>>>>>> CHANGE (73a498 video: tegra: Don't use nvhost_get_private_data) */ #include @@ -309,24 +305,15 @@ error: return err; } -struct t194_vi5_file_private { - struct platform_device *pdev; - struct tegra_mc_vi mc_vi; - unsigned int vi_bypass_bw; -}; - static int vi5_remove(struct platform_device *pdev) { struct nvhost_device_data *pdata = platform_get_drvdata(pdev); struct host_vi5 *vi5 = pdata->private_data; tegra_camera_device_unregister(vi5); - vi_channel_drv_unregister(&pdev->dev); - tegra_vi_media_controller_cleanup(&vi5->vi_common.mc_vi); vi5_remove_debugfs(vi5); platform_device_put(vi5->vi_thi); - return 0; } diff --git a/include/media/fusa-capture/capture-vi-channel.h b/include/media/fusa-capture/capture-vi-channel.h index 5d91420a..719dc72d 100644 --- a/include/media/fusa-capture/capture-vi-channel.h +++ b/include/media/fusa-capture/capture-vi-channel.h @@ -1,12 +1,9 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (c) 2017-2022, NVIDIA Corporation. All rights reserved. - */ - +/* SPDX-FileCopyrightText: Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ /** * @file include/media/fusa-capture/capture-vi-channel.h * - * @brief VI channel character device driver header for the T186/T194 Camera + * @brief VI channel character device driver header for the T234 Camera * RTCPU platform. */ @@ -84,8 +81,6 @@ struct vi_channel_drv_ops { struct vi_channel_drv { struct platform_device *vi_capture_pdev; /**< Capture VI driver platform device */ - bool use_legacy_path; - /**< Flag to maintain backward-compatibility for T186 */ struct device *dev; /**< VI kernel @em device */ struct platform_device *ndev; /**< VI kernel @em platform_device */ struct mutex lock; /**< VI channel driver context lock */