drm/rockchip: Convert psr_list_mutex to spinlock and use it
authorSean Paul <seanpaul@chromium.org>
Tue, 16 Aug 2016 23:11:28 +0000 (16:11 -0700)
committerSean Paul <seanpaul@chromium.org>
Tue, 23 Aug 2016 15:44:34 +0000 (11:44 -0400)
This patch converts the psr_list_mutex to a spinlock and locks
all access to psr_list to avoid races (however unlikely they
were).

Reviewed-by: Yakir Yang <ykk@rock-chips.com>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
drivers/gpu/drm/rockchip/rockchip_drm_drv.c
drivers/gpu/drm/rockchip/rockchip_drm_drv.h
drivers/gpu/drm/rockchip/rockchip_drm_psr.c

index b43fe5d938282776011f0d0b0e6bafb752eff437..76eaf1de52e41e7253df80c9b5aaa927f64acc83 100644 (file)
@@ -157,7 +157,7 @@ static int rockchip_drm_bind(struct device *dev)
        drm_dev->dev_private = private;
 
        INIT_LIST_HEAD(&private->psr_list);
-       mutex_init(&private->psr_list_mutex);
+       spin_lock_init(&private->psr_list_lock);
 
        drm_mode_config_init(drm_dev);
 
index 9c34c9e181d065db71d1f42ee1b92cd2be740812..5c698456aa1cd84da5666d9f121954d231e9ad78 100644 (file)
@@ -63,7 +63,7 @@ struct rockchip_drm_private {
        struct drm_atomic_state *state;
 
        struct list_head psr_list;
-       struct mutex psr_list_mutex;
+       spinlock_t psr_list_lock;
 };
 
 int rockchip_register_crtc_funcs(struct drm_crtc *crtc,
index a6d3bd25b905052bd6318b5e46f68e16d9b23c39..bd25273a89bb18e03481564b0d0be848d430cac0 100644 (file)
@@ -45,12 +45,18 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc)
 {
        struct rockchip_drm_private *drm_drv = crtc->dev->dev_private;
        struct psr_drv *psr;
+       unsigned long flags;
 
-       list_for_each_entry(psr, &drm_drv->psr_list, list)
+       spin_lock_irqsave(&drm_drv->psr_list_lock, flags);
+       list_for_each_entry(psr, &drm_drv->psr_list, list) {
                if (psr->encoder->crtc == crtc)
-                       return psr;
+                       goto out;
+       }
+       psr = ERR_PTR(-ENODEV);
 
-       return ERR_PTR(-ENODEV);
+out:
+       spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags);
+       return psr;
 }
 
 static void psr_state_work(struct work_struct *work)
@@ -173,7 +179,9 @@ void rockchip_drm_psr_flush(struct drm_device *dev)
 {
        struct rockchip_drm_private *drm_drv = dev->dev_private;
        struct psr_drv *psr;
+       unsigned long flags;
 
+       spin_lock_irqsave(&drm_drv->psr_list_lock, flags);
        list_for_each_entry(psr, &drm_drv->psr_list, list) {
                if (psr->request_state == PSR_DISABLE)
                        continue;
@@ -183,6 +191,7 @@ void rockchip_drm_psr_flush(struct drm_device *dev)
 
                psr_set_state(psr, PSR_FLUSH);
        }
+       spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags);
 }
 EXPORT_SYMBOL(rockchip_drm_psr_flush);
 
@@ -199,6 +208,7 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder,
 {
        struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
        struct psr_drv *psr;
+       unsigned long flags;
 
        if (!encoder || !psr_set)
                return -EINVAL;
@@ -215,9 +225,9 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder,
        psr->encoder = encoder;
        psr->set = psr_set;
 
-       mutex_lock(&drm_drv->psr_list_mutex);
+       spin_lock_irqsave(&drm_drv->psr_list_lock, flags);
        list_add_tail(&psr->list, &drm_drv->psr_list);
-       mutex_unlock(&drm_drv->psr_list_mutex);
+       spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags);
 
        return 0;
 }
@@ -235,8 +245,9 @@ void rockchip_drm_psr_unregister(struct drm_encoder *encoder)
 {
        struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
        struct psr_drv *psr, *n;
+       unsigned long flags;
 
-       mutex_lock(&drm_drv->psr_list_mutex);
+       spin_lock_irqsave(&drm_drv->psr_list_lock, flags);
        list_for_each_entry_safe(psr, n, &drm_drv->psr_list, list) {
                if (psr->encoder == encoder) {
                        del_timer(&psr->flush_timer);
@@ -244,6 +255,6 @@ void rockchip_drm_psr_unregister(struct drm_encoder *encoder)
                        kfree(psr);
                }
        }
-       mutex_unlock(&drm_drv->psr_list_mutex);
+       spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags);
 }
 EXPORT_SYMBOL(rockchip_drm_psr_unregister);