media: marvell-ccic: mmp: get rid of mmpcam_devices list
authorLubomir Rintel <lkundrak@v3.sk>
Mon, 17 Aug 2020 22:08:48 +0000 (00:08 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sat, 29 Aug 2020 06:09:16 +0000 (08:09 +0200)
The sole reason for this was so that it would be possible to get a
mmp_camera from a platform_device in suspend/resume/remove hooks, because
drvdata used to be used by the v4l core.

Since commit 95db3a60e065 ("[media] v4l: Add a media_device pointer to the
v4l2_device structure") it is no longer case and thus we can make things
a great deal simpler.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/marvell-ccic/mmp-driver.c

index 92b92255dac66766398e10168b2026532ecf0e4d..f04c01bced2f060d31631ba6df6fc6584dc6fb69 100644 (file)
@@ -46,49 +46,6 @@ static inline struct mmp_camera *mcam_to_cam(struct mcam_camera *mcam)
        return container_of(mcam, struct mmp_camera, mcam);
 }
 
-/*
- * A silly little infrastructure so we can keep track of our devices.
- * Chances are that we will never have more than one of them, but
- * the Armada 610 *does* have two controllers...
- */
-
-static LIST_HEAD(mmpcam_devices);
-static struct mutex mmpcam_devices_lock;
-
-static void mmpcam_add_device(struct mmp_camera *cam)
-{
-       mutex_lock(&mmpcam_devices_lock);
-       list_add(&cam->devlist, &mmpcam_devices);
-       mutex_unlock(&mmpcam_devices_lock);
-}
-
-static void mmpcam_remove_device(struct mmp_camera *cam)
-{
-       mutex_lock(&mmpcam_devices_lock);
-       list_del(&cam->devlist);
-       mutex_unlock(&mmpcam_devices_lock);
-}
-
-/*
- * Platform dev remove passes us a platform_device, and there's
- * no handy unused drvdata to stash a backpointer in.  So just
- * dig it out of our list.
- */
-static struct mmp_camera *mmpcam_find_device(struct platform_device *pdev)
-{
-       struct mmp_camera *cam;
-
-       mutex_lock(&mmpcam_devices_lock);
-       list_for_each_entry(cam, &mmpcam_devices, devlist) {
-               if (cam->pdev == pdev) {
-                       mutex_unlock(&mmpcam_devices_lock);
-                       return cam;
-               }
-       }
-       mutex_unlock(&mmpcam_devices_lock);
-       return NULL;
-}
-
 /*
  * calc the dphy register values
  * There are three dphy registers being used.
@@ -227,6 +184,7 @@ static int mmpcam_probe(struct platform_device *pdev)
        cam = devm_kzalloc(&pdev->dev, sizeof(*cam), GFP_KERNEL);
        if (cam == NULL)
                return -ENOMEM;
+       platform_set_drvdata(pdev, cam);
        cam->pdev = pdev;
        INIT_LIST_HEAD(&cam->devlist);
 
@@ -313,11 +271,10 @@ static int mmpcam_probe(struct platform_device *pdev)
        cam->irq = res->start;
        ret = devm_request_irq(&pdev->dev, cam->irq, mmpcam_irq, IRQF_SHARED,
                                        "mmp-camera", mcam);
-       if (ret == 0) {
-               mmpcam_add_device(cam);
-               return 0;
-       }
+       if (ret)
+               goto out;
 
+       return 0;
 out:
        fwnode_handle_put(mcam->asd.match.fwnode);
        mccic_shutdown(mcam);
@@ -330,14 +287,13 @@ static int mmpcam_remove(struct mmp_camera *cam)
 {
        struct mcam_camera *mcam = &cam->mcam;
 
-       mmpcam_remove_device(cam);
        mccic_shutdown(mcam);
        return 0;
 }
 
 static int mmpcam_platform_remove(struct platform_device *pdev)
 {
-       struct mmp_camera *cam = mmpcam_find_device(pdev);
+       struct mmp_camera *cam = platform_get_drvdata(pdev);
 
        if (cam == NULL)
                return -ENODEV;
@@ -351,7 +307,7 @@ static int mmpcam_platform_remove(struct platform_device *pdev)
 
 static int mmpcam_suspend(struct platform_device *pdev, pm_message_t state)
 {
-       struct mmp_camera *cam = mmpcam_find_device(pdev);
+       struct mmp_camera *cam = platform_get_drvdata(pdev);
 
        if (state.event != PM_EVENT_SUSPEND)
                return 0;
@@ -361,7 +317,7 @@ static int mmpcam_suspend(struct platform_device *pdev, pm_message_t state)
 
 static int mmpcam_resume(struct platform_device *pdev)
 {
-       struct mmp_camera *cam = mmpcam_find_device(pdev);
+       struct mmp_camera *cam = platform_get_drvdata(pdev);
 
        return mccic_resume(&cam->mcam);
 }
@@ -387,22 +343,4 @@ static struct platform_driver mmpcam_driver = {
        }
 };
 
-
-static int __init mmpcam_init_module(void)
-{
-       mutex_init(&mmpcam_devices_lock);
-       return platform_driver_register(&mmpcam_driver);
-}
-
-static void __exit mmpcam_exit_module(void)
-{
-       platform_driver_unregister(&mmpcam_driver);
-       /*
-        * platform_driver_unregister() should have emptied the list
-        */
-       if (!list_empty(&mmpcam_devices))
-               printk(KERN_ERR "mmp_camera leaving devices behind\n");
-}
-
-module_init(mmpcam_init_module);
-module_exit(mmpcam_exit_module);
+module_platform_driver(mmpcam_driver);