]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm: Make the per-driver file_operations struct const
authorArjan van de Ven <arjan@infradead.org>
Mon, 31 Oct 2011 14:28:57 +0000 (07:28 -0700)
committerDave Airlie <airlied@redhat.com>
Fri, 11 Nov 2011 11:14:47 +0000 (11:14 +0000)
From fdf1fdebaa00f81de18c227f32f8074c8b352d50 Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <arjan@linux.intel.com>
Date: Sun, 30 Oct 2011 19:06:07 -0700
Subject: [PATCH] drm: Make the per-driver file_operations struct const

The DRM layer keeps a copy of struct file_operations inside its
big driver struct... which prevents it from being consistent and static.
For consistency (and the general security objective of having such things
static), it's desirable to get this fixed.

This patch splits out the file_operations field to its own struct,
which is then "static const", and just stick a pointer to this into
the driver struct, making it more consistent with how the rest of the
kernel does this.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
14 files changed:
drivers/gpu/drm/drm_fops.c
drivers/gpu/drm/i810/i810_drv.c
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/mga/mga_drv.c
drivers/gpu/drm/nouveau/nouveau_drv.c
drivers/gpu/drm/r128/r128_drv.c
drivers/gpu/drm/radeon/radeon_drv.c
drivers/gpu/drm/savage/savage_drv.c
drivers/gpu/drm/sis/sis_drv.c
drivers/gpu/drm/tdfx/tdfx_drv.c
drivers/gpu/drm/via/via_drv.c
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
drivers/staging/gma500/psb_drv.c
include/drm/drmP.h

index 4911e1d1dcf2a60d527235c35da7a33edc864be4..c00cf154cc0bbd81ce3c807fde6bffb2a5ff777f 100644 (file)
@@ -182,7 +182,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
                goto out;
 
        old_fops = filp->f_op;
-       filp->f_op = fops_get(&dev->driver->fops);
+       filp->f_op = fops_get(dev->driver->fops);
        if (filp->f_op == NULL) {
                filp->f_op = old_fops;
                goto out;
index d4266bdf6fb4eb3d3cb6ac6ea991b0de8a8cd7c9..ec12f7dc717a863ed7fcd17911aec55a1c486fce 100644 (file)
@@ -43,6 +43,17 @@ static struct pci_device_id pciidlist[] = {
        i810_PCI_IDS
 };
 
+static const struct file_operations i810_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features =
            DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
@@ -55,17 +66,7 @@ static struct drm_driver driver = {
        .reclaim_buffers_locked = i810_driver_reclaim_buffers_locked,
        .dma_quiescent = i810_driver_dma_quiescent,
        .ioctls = i810_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .llseek = noop_llseek,
-       },
-
+       .fops = &i810_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index cc531bb59c26f7ccc8b7de8721f1b94bce576be6..9f592703c3696842d8a858de06bec880cd832a65 100644 (file)
@@ -788,6 +788,21 @@ static struct vm_operations_struct i915_gem_vm_ops = {
        .close = drm_gem_vm_close,
 };
 
+static const struct file_operations i915_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_gem_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .read = drm_read,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = i915_compat_ioctl,
+#endif
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        /* don't use mtrr's here, the Xserver or user space app should
         * deal with them for intel hardware.
@@ -821,21 +836,7 @@ static struct drm_driver driver = {
        .dumb_map_offset = i915_gem_mmap_gtt,
        .dumb_destroy = i915_gem_dumb_destroy,
        .ioctls = i915_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = drm_ioctl,
-                .mmap = drm_gem_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .read = drm_read,
-#ifdef CONFIG_COMPAT
-                .compat_ioctl = i915_compat_ioctl,
-#endif
-                .llseek = noop_llseek,
-       },
-
+       .fops = &i915_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index 33daa29eea6652e0afa9888cecb840f2eda1e9bd..f9a925d5881966d7f88acd66f065be29976f3659 100644 (file)
@@ -44,6 +44,20 @@ static struct pci_device_id pciidlist[] = {
        mga_PCI_IDS
 };
 
+static const struct file_operations mga_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = mga_compat_ioctl,
+#endif
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features =
            DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
@@ -64,20 +78,7 @@ static struct drm_driver driver = {
        .reclaim_buffers = drm_core_reclaim_buffers,
        .ioctls = mga_ioctls,
        .dma_ioctl = mga_dma_buffers,
-       .fops = {
-               .owner = THIS_MODULE,
-               .open = drm_open,
-               .release = drm_release,
-               .unlocked_ioctl = drm_ioctl,
-               .mmap = drm_mmap,
-               .poll = drm_poll,
-               .fasync = drm_fasync,
-#ifdef CONFIG_COMPAT
-               .compat_ioctl = mga_compat_ioctl,
-#endif
-               .llseek = noop_llseek,
-       },
-
+       .fops = &mga_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index 9f7bb12952623b51bed52e21148ec04dcca902af..d661bc5e3945b7b7a73b7b34a536743185a5dff4 100644 (file)
@@ -388,6 +388,21 @@ nouveau_pci_resume(struct pci_dev *pdev)
        return 0;
 }
 
+static const struct file_operations nouveau_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = nouveau_ttm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .read = drm_read,
+#if defined(CONFIG_COMPAT)
+       .compat_ioctl = nouveau_compat_ioctl,
+#endif
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features =
                DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
@@ -413,21 +428,7 @@ static struct drm_driver driver = {
        .disable_vblank = nouveau_vblank_disable,
        .reclaim_buffers = drm_core_reclaim_buffers,
        .ioctls = nouveau_ioctls,
-       .fops = {
-               .owner = THIS_MODULE,
-               .open = drm_open,
-               .release = drm_release,
-               .unlocked_ioctl = drm_ioctl,
-               .mmap = nouveau_ttm_mmap,
-               .poll = drm_poll,
-               .fasync = drm_fasync,
-               .read = drm_read,
-#if defined(CONFIG_COMPAT)
-               .compat_ioctl = nouveau_compat_ioctl,
-#endif
-               .llseek = noop_llseek,
-       },
-
+       .fops = &nouveau_driver_fops,
        .gem_init_object = nouveau_gem_object_new,
        .gem_free_object = nouveau_gem_object_del,
        .gem_open_object = nouveau_gem_object_open,
index 4c8796ba6dd8d3adf07f0760c436b6b55dfba7f9..6a5f4395838f712bc03bc0c70e9c34777ba37051 100644 (file)
@@ -42,6 +42,20 @@ static struct pci_device_id pciidlist[] = {
        r128_PCI_IDS
 };
 
+static const struct file_operations r128_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = r128_compat_ioctl,
+#endif
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features =
            DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
@@ -60,21 +74,7 @@ static struct drm_driver driver = {
        .reclaim_buffers = drm_core_reclaim_buffers,
        .ioctls = r128_ioctls,
        .dma_ioctl = r128_cce_buffers,
-       .fops = {
-               .owner = THIS_MODULE,
-               .open = drm_open,
-               .release = drm_release,
-               .unlocked_ioctl = drm_ioctl,
-               .mmap = drm_mmap,
-               .poll = drm_poll,
-               .fasync = drm_fasync,
-#ifdef CONFIG_COMPAT
-               .compat_ioctl = r128_compat_ioctl,
-#endif
-               .llseek = noop_llseek,
-       },
-
-
+       .fops = &r128_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index a0b35e9094896cf90202d8f54effd942b0398054..e42c34b98c7b7efe776b75e944a971942064de53 100644 (file)
@@ -205,6 +205,21 @@ static struct pci_device_id pciidlist[] = {
 MODULE_DEVICE_TABLE(pci, pciidlist);
 #endif
 
+static const struct file_operations radeon_driver_old_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .read = drm_read,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = radeon_compat_ioctl,
+#endif
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver_old = {
        .driver_features =
            DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
@@ -231,21 +246,7 @@ static struct drm_driver driver_old = {
        .reclaim_buffers = drm_core_reclaim_buffers,
        .ioctls = radeon_ioctls,
        .dma_ioctl = radeon_cp_buffers,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .read = drm_read,
-#ifdef CONFIG_COMPAT
-                .compat_ioctl = radeon_compat_ioctl,
-#endif
-                .llseek = noop_llseek,
-       },
-
+       .fops = &radeon_driver_old_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
@@ -303,6 +304,20 @@ radeon_pci_resume(struct pci_dev *pdev)
        return radeon_resume_kms(dev);
 }
 
+static const struct file_operations radeon_driver_kms_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = radeon_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .read = drm_read,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = radeon_kms_compat_ioctl,
+#endif
+};
+
 static struct drm_driver kms_driver = {
        .driver_features =
            DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
@@ -338,20 +353,7 @@ static struct drm_driver kms_driver = {
        .dumb_create = radeon_mode_dumb_create,
        .dumb_map_offset = radeon_mode_dumb_mmap,
        .dumb_destroy = radeon_mode_dumb_destroy,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = drm_ioctl,
-                .mmap = radeon_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .read = drm_read,
-#ifdef CONFIG_COMPAT
-                .compat_ioctl = radeon_kms_compat_ioctl,
-#endif
-       },
-
+       .fops = &radeon_driver_kms_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index 5468d1cd3296102560aa1653173233c637494bad..89afe0b83643282ced1abf4ed62660c510008423 100644 (file)
@@ -35,6 +35,17 @@ static struct pci_device_id pciidlist[] = {
        savage_PCI_IDS
 };
 
+static const struct file_operations savage_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features =
            DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
@@ -46,17 +57,7 @@ static struct drm_driver driver = {
        .reclaim_buffers = savage_reclaim_buffers,
        .ioctls = savage_ioctls,
        .dma_ioctl = savage_bci_buffers,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .llseek = noop_llseek,
-       },
-
+       .fops = &savage_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index a9c5716bea4eb1f3a155c2d1d15cda3480c0f51d..bda96a8cd939c02f46e00968ae7cb273a0bc44ce 100644 (file)
@@ -65,6 +65,17 @@ static int sis_driver_unload(struct drm_device *dev)
        return 0;
 }
 
+static const struct file_operations sis_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
        .load = sis_driver_load,
@@ -74,17 +85,7 @@ static struct drm_driver driver = {
        .reclaim_buffers_idlelocked = sis_reclaim_buffers_locked,
        .lastclose = sis_lastclose,
        .ioctls = sis_ioctls,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .llseek = noop_llseek,
-       },
-
+       .fops = &sis_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index cda29911e332edb7d4dc5ed1d024c597fb6cb2bc..1613c78544c0e8b9bf4aa63501f0dece2d69d003 100644 (file)
@@ -41,20 +41,21 @@ static struct pci_device_id pciidlist[] = {
        tdfx_PCI_IDS
 };
 
+static const struct file_operations tdfx_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features = DRIVER_USE_MTRR,
        .reclaim_buffers = drm_core_reclaim_buffers,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = drm_ioctl,
-                .mmap = drm_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .llseek = noop_llseek,
-       },
-
+       .fops = &tdfx_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index a83e86d3956cb284a04945b988e7844a248d4e01..fb43fd368ce139cb1e74a76b07e578efbce822b7 100644 (file)
@@ -34,6 +34,17 @@ static struct pci_device_id pciidlist[] = {
        viadrv_PCI_IDS
 };
 
+static const struct file_operations via_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .mmap = drm_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features =
            DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ |
@@ -54,17 +65,7 @@ static struct drm_driver driver = {
        .reclaim_buffers_idlelocked = via_reclaim_buffers_locked,
        .lastclose = via_lastclose,
        .ioctls = via_ioctls,
-       .fops = {
-               .owner = THIS_MODULE,
-               .open = drm_open,
-               .release = drm_release,
-               .unlocked_ioctl = drm_ioctl,
-               .mmap = drm_mmap,
-               .poll = drm_poll,
-               .fasync = drm_fasync,
-               .llseek = noop_llseek,
-               },
-
+       .fops = &via_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = DRIVER_DATE,
index dff8fc7671525d347382261402d60d002a21dbb5..f390f5f9cb684f64fc2e0dbb390a713841f296f2 100644 (file)
@@ -1064,6 +1064,21 @@ static const struct dev_pm_ops vmw_pm_ops = {
        .resume = vmw_pm_resume,
 };
 
+static const struct file_operations vmwgfx_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = vmw_unlocked_ioctl,
+       .mmap = vmw_mmap,
+       .poll = vmw_fops_poll,
+       .read = vmw_fops_read,
+       .fasync = drm_fasync,
+#if defined(CONFIG_COMPAT)
+       .compat_ioctl = drm_compat_ioctl,
+#endif
+       .llseek = noop_llseek,
+};
+
 static struct drm_driver driver = {
        .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
        DRIVER_MODESET,
@@ -1088,20 +1103,7 @@ static struct drm_driver driver = {
        .master_drop = vmw_master_drop,
        .open = vmw_driver_open,
        .postclose = vmw_postclose,
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = vmw_unlocked_ioctl,
-                .mmap = vmw_mmap,
-                .poll = vmw_fops_poll,
-                .read = vmw_fops_read,
-                .fasync = drm_fasync,
-#if defined(CONFIG_COMPAT)
-                .compat_ioctl = drm_compat_ioctl,
-#endif
-                .llseek = noop_llseek,
-       },
+       .fops = &vmwgfx_driver_fops,
        .name = VMWGFX_DRIVER_NAME,
        .desc = VMWGFX_DRIVER_DESC,
        .date = VMWGFX_DRIVER_DATE,
index 986a04d16ba8641f2aaf4c265e3bb54087206186..95816808f86761c85ba9fb5ac05b0e123866f195 100644 (file)
@@ -1151,6 +1151,17 @@ static struct vm_operations_struct psb_gem_vm_ops = {
        .close = drm_gem_vm_close,
 };
 
+static const struct file_operations gma500_driver_fops = {
+       .owner = THIS_MODULE,
+       .open = drm_open,
+       .release = drm_release,
+       .unlocked_ioctl = psb_unlocked_ioctl,
+       .mmap = drm_gem_mmap,
+       .poll = drm_poll,
+       .fasync = drm_fasync,
+       .read = drm_read,
+};
+
 static struct drm_driver driver = {
        .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \
                           DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM ,
@@ -1179,17 +1190,7 @@ static struct drm_driver driver = {
        .dumb_create = psb_gem_dumb_create,
        .dumb_map_offset = psb_gem_dumb_map_gtt,
        .dumb_destroy = psb_gem_dumb_destroy,
-
-       .fops = {
-                .owner = THIS_MODULE,
-                .open = drm_open,
-                .release = drm_release,
-                .unlocked_ioctl = psb_unlocked_ioctl,
-                .mmap = drm_gem_mmap,
-                .poll = drm_poll,
-                .fasync = drm_fasync,
-                .read = drm_read,
-        },
+       .fops = &gma500_driver_fops,
        .name = DRIVER_NAME,
        .desc = DRIVER_DESC,
        .date = PSB_DRM_DRIVER_DATE,
index cf399495d38ff7418947471e164faa79c0a094ec..1f630a5d75b46056023727b4901904737f10e3f1 100644 (file)
@@ -918,7 +918,7 @@ struct drm_driver {
        int dev_priv_size;
        struct drm_ioctl_desc *ioctls;
        int num_ioctls;
-       struct file_operations fops;
+       const struct file_operations *fops;
        union {
                struct pci_driver *pci;
                struct platform_device *platform_device;