drm: Make the per-driver file_operations struct const
Subsystems (7)
PATCH 1/1 drm: Make the per-driver file_operations struct const
Quoted 2 lines
From
fdf1fdebaa00f81de18c227f32f8074c8b352d50Mon Sep 17 00:00:00 2001
From: Arjan van de Ven <[email protected]>
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.
--- drivers/gpu/drm/drm_fops.c | 2 +- drivers/gpu/drm/i810/i810_drv.c | 23 ++++++------ drivers/gpu/drm/i915/i915_drv.c | 31 +++++++++-------- drivers/gpu/drm/mga/mga_drv.c | 29 ++++++++-------- drivers/gpu/drm/nouveau/nouveau_drv.c | 31 +++++++++-------- drivers/gpu/drm/r128/r128_drv.c | 30 ++++++++-------- drivers/gpu/drm/radeon/radeon_drv.c | 60 +++++++++++++++++---------------- drivers/gpu/drm/savage/savage_drv.c | 23 ++++++------ drivers/gpu/drm/sis/sis_drv.c | 23 ++++++------ drivers/gpu/drm/tdfx/tdfx_drv.c | 23 ++++++------ drivers/gpu/drm/via/via_drv.c | 23 ++++++------ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 28 ++++++++------- drivers/staging/gma500/psb_drv.c | 23 ++++++------ include/drm/drmP.h | 2 +- 14 files changed, 182 insertions(+), 169 deletions(-)
drivers/gpu/drm/drm_fops.c +1 -1
@@ -181,7 +181,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;
drivers/gpu/drm/i810/i810_drv.c +12 -11
@@ -41,6 +41,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 |
@@ -53,17 +64,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,
drivers/gpu/drm/i915/i915_drv.c +16 -15
@@ -784,6 +784,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.
@@ -817,21 +832,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,
drivers/gpu/drm/mga/mga_drv.c +15 -14
@@ -42,6 +42,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 |
@@ -62,20 +76,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,
drivers/gpu/drm/nouveau/nouveau_drv.c +16 -15
@@ -387,6 +387,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 |
@@ -412,21 +427,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,
drivers/gpu/drm/r128/r128_drv.c +15 -15
@@ -40,6 +40,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 |
@@ -58,21 +72,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,
drivers/gpu/drm/radeon/radeon_drv.c +31 -29
84 lines not on this page · raw message
drivers/gpu/drm/savage/savage_drv.c +12 -11
@@ -33,6 +33,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 ,
@@ -44,17 +55,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,
drivers/gpu/drm/sis/sis_drv.c +12 -11
@@ -63,6 +63,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,
@@ -72,17 +83,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,
drivers/gpu/drm/tdfx/tdfx_drv.c +12 -11
@@ -39,20 +39,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 ,
drivers/gpu/drm/via/via_drv.c +12 -11
@@ -32,6 +32,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 |
@@ -52,17 +63,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,
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +15 -13
@@ -874,6 +874,20 @@ 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 = drm_poll, + .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 ,
@@ -896,19 +910,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 = drm_poll, - .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,
drivers/staging/gma500/psb_drv.c +12 -11
@@ -1150,6 +1150,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 ,
@@ -1178,17 +1189,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,
include/drm/drmP.h +1 -1
@@ -917,7 +917,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;
Signature · 7 lines
1.7.6 -- Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org