Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Make the per-driver file_operations struct const

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>

authored by

Arjan van de Ven and committed by
Dave Airlie
e08e96de d68752cf

+183 -170
+1 -1
drivers/gpu/drm/drm_fops.c
··· 182 182 goto out; 183 183 184 184 old_fops = filp->f_op; 185 - filp->f_op = fops_get(&dev->driver->fops); 185 + filp->f_op = fops_get(dev->driver->fops); 186 186 if (filp->f_op == NULL) { 187 187 filp->f_op = old_fops; 188 188 goto out;
+12 -11
drivers/gpu/drm/i810/i810_drv.c
··· 43 43 i810_PCI_IDS 44 44 }; 45 45 46 + static const struct file_operations i810_driver_fops = { 47 + .owner = THIS_MODULE, 48 + .open = drm_open, 49 + .release = drm_release, 50 + .unlocked_ioctl = drm_ioctl, 51 + .mmap = drm_mmap, 52 + .poll = drm_poll, 53 + .fasync = drm_fasync, 54 + .llseek = noop_llseek, 55 + }; 56 + 46 57 static struct drm_driver driver = { 47 58 .driver_features = 48 59 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR | ··· 66 55 .reclaim_buffers_locked = i810_driver_reclaim_buffers_locked, 67 56 .dma_quiescent = i810_driver_dma_quiescent, 68 57 .ioctls = i810_ioctls, 69 - .fops = { 70 - .owner = THIS_MODULE, 71 - .open = drm_open, 72 - .release = drm_release, 73 - .unlocked_ioctl = drm_ioctl, 74 - .mmap = drm_mmap, 75 - .poll = drm_poll, 76 - .fasync = drm_fasync, 77 - .llseek = noop_llseek, 78 - }, 79 - 58 + .fops = &i810_driver_fops, 80 59 .name = DRIVER_NAME, 81 60 .desc = DRIVER_DESC, 82 61 .date = DRIVER_DATE,
+16 -15
drivers/gpu/drm/i915/i915_drv.c
··· 788 788 .close = drm_gem_vm_close, 789 789 }; 790 790 791 + static const struct file_operations i915_driver_fops = { 792 + .owner = THIS_MODULE, 793 + .open = drm_open, 794 + .release = drm_release, 795 + .unlocked_ioctl = drm_ioctl, 796 + .mmap = drm_gem_mmap, 797 + .poll = drm_poll, 798 + .fasync = drm_fasync, 799 + .read = drm_read, 800 + #ifdef CONFIG_COMPAT 801 + .compat_ioctl = i915_compat_ioctl, 802 + #endif 803 + .llseek = noop_llseek, 804 + }; 805 + 791 806 static struct drm_driver driver = { 792 807 /* don't use mtrr's here, the Xserver or user space app should 793 808 * deal with them for intel hardware. ··· 836 821 .dumb_map_offset = i915_gem_mmap_gtt, 837 822 .dumb_destroy = i915_gem_dumb_destroy, 838 823 .ioctls = i915_ioctls, 839 - .fops = { 840 - .owner = THIS_MODULE, 841 - .open = drm_open, 842 - .release = drm_release, 843 - .unlocked_ioctl = drm_ioctl, 844 - .mmap = drm_gem_mmap, 845 - .poll = drm_poll, 846 - .fasync = drm_fasync, 847 - .read = drm_read, 848 - #ifdef CONFIG_COMPAT 849 - .compat_ioctl = i915_compat_ioctl, 850 - #endif 851 - .llseek = noop_llseek, 852 - }, 853 - 824 + .fops = &i915_driver_fops, 854 825 .name = DRIVER_NAME, 855 826 .desc = DRIVER_DESC, 856 827 .date = DRIVER_DATE,
+15 -14
drivers/gpu/drm/mga/mga_drv.c
··· 44 44 mga_PCI_IDS 45 45 }; 46 46 47 + static const struct file_operations mga_driver_fops = { 48 + .owner = THIS_MODULE, 49 + .open = drm_open, 50 + .release = drm_release, 51 + .unlocked_ioctl = drm_ioctl, 52 + .mmap = drm_mmap, 53 + .poll = drm_poll, 54 + .fasync = drm_fasync, 55 + #ifdef CONFIG_COMPAT 56 + .compat_ioctl = mga_compat_ioctl, 57 + #endif 58 + .llseek = noop_llseek, 59 + }; 60 + 47 61 static struct drm_driver driver = { 48 62 .driver_features = 49 63 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | ··· 78 64 .reclaim_buffers = drm_core_reclaim_buffers, 79 65 .ioctls = mga_ioctls, 80 66 .dma_ioctl = mga_dma_buffers, 81 - .fops = { 82 - .owner = THIS_MODULE, 83 - .open = drm_open, 84 - .release = drm_release, 85 - .unlocked_ioctl = drm_ioctl, 86 - .mmap = drm_mmap, 87 - .poll = drm_poll, 88 - .fasync = drm_fasync, 89 - #ifdef CONFIG_COMPAT 90 - .compat_ioctl = mga_compat_ioctl, 91 - #endif 92 - .llseek = noop_llseek, 93 - }, 94 - 67 + .fops = &mga_driver_fops, 95 68 .name = DRIVER_NAME, 96 69 .desc = DRIVER_DESC, 97 70 .date = DRIVER_DATE,
+16 -15
drivers/gpu/drm/nouveau/nouveau_drv.c
··· 388 388 return 0; 389 389 } 390 390 391 + static const struct file_operations nouveau_driver_fops = { 392 + .owner = THIS_MODULE, 393 + .open = drm_open, 394 + .release = drm_release, 395 + .unlocked_ioctl = drm_ioctl, 396 + .mmap = nouveau_ttm_mmap, 397 + .poll = drm_poll, 398 + .fasync = drm_fasync, 399 + .read = drm_read, 400 + #if defined(CONFIG_COMPAT) 401 + .compat_ioctl = nouveau_compat_ioctl, 402 + #endif 403 + .llseek = noop_llseek, 404 + }; 405 + 391 406 static struct drm_driver driver = { 392 407 .driver_features = 393 408 DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG | ··· 428 413 .disable_vblank = nouveau_vblank_disable, 429 414 .reclaim_buffers = drm_core_reclaim_buffers, 430 415 .ioctls = nouveau_ioctls, 431 - .fops = { 432 - .owner = THIS_MODULE, 433 - .open = drm_open, 434 - .release = drm_release, 435 - .unlocked_ioctl = drm_ioctl, 436 - .mmap = nouveau_ttm_mmap, 437 - .poll = drm_poll, 438 - .fasync = drm_fasync, 439 - .read = drm_read, 440 - #if defined(CONFIG_COMPAT) 441 - .compat_ioctl = nouveau_compat_ioctl, 442 - #endif 443 - .llseek = noop_llseek, 444 - }, 445 - 416 + .fops = &nouveau_driver_fops, 446 417 .gem_init_object = nouveau_gem_object_new, 447 418 .gem_free_object = nouveau_gem_object_del, 448 419 .gem_open_object = nouveau_gem_object_open,
+15 -15
drivers/gpu/drm/r128/r128_drv.c
··· 42 42 r128_PCI_IDS 43 43 }; 44 44 45 + static const struct file_operations r128_driver_fops = { 46 + .owner = THIS_MODULE, 47 + .open = drm_open, 48 + .release = drm_release, 49 + .unlocked_ioctl = drm_ioctl, 50 + .mmap = drm_mmap, 51 + .poll = drm_poll, 52 + .fasync = drm_fasync, 53 + #ifdef CONFIG_COMPAT 54 + .compat_ioctl = r128_compat_ioctl, 55 + #endif 56 + .llseek = noop_llseek, 57 + }; 58 + 45 59 static struct drm_driver driver = { 46 60 .driver_features = 47 61 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG | ··· 74 60 .reclaim_buffers = drm_core_reclaim_buffers, 75 61 .ioctls = r128_ioctls, 76 62 .dma_ioctl = r128_cce_buffers, 77 - .fops = { 78 - .owner = THIS_MODULE, 79 - .open = drm_open, 80 - .release = drm_release, 81 - .unlocked_ioctl = drm_ioctl, 82 - .mmap = drm_mmap, 83 - .poll = drm_poll, 84 - .fasync = drm_fasync, 85 - #ifdef CONFIG_COMPAT 86 - .compat_ioctl = r128_compat_ioctl, 87 - #endif 88 - .llseek = noop_llseek, 89 - }, 90 - 91 - 63 + .fops = &r128_driver_fops, 92 64 .name = DRIVER_NAME, 93 65 .desc = DRIVER_DESC, 94 66 .date = DRIVER_DATE,
+31 -29
drivers/gpu/drm/radeon/radeon_drv.c
··· 205 205 MODULE_DEVICE_TABLE(pci, pciidlist); 206 206 #endif 207 207 208 + static const struct file_operations radeon_driver_old_fops = { 209 + .owner = THIS_MODULE, 210 + .open = drm_open, 211 + .release = drm_release, 212 + .unlocked_ioctl = drm_ioctl, 213 + .mmap = drm_mmap, 214 + .poll = drm_poll, 215 + .fasync = drm_fasync, 216 + .read = drm_read, 217 + #ifdef CONFIG_COMPAT 218 + .compat_ioctl = radeon_compat_ioctl, 219 + #endif 220 + .llseek = noop_llseek, 221 + }; 222 + 208 223 static struct drm_driver driver_old = { 209 224 .driver_features = 210 225 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG | ··· 246 231 .reclaim_buffers = drm_core_reclaim_buffers, 247 232 .ioctls = radeon_ioctls, 248 233 .dma_ioctl = radeon_cp_buffers, 249 - .fops = { 250 - .owner = THIS_MODULE, 251 - .open = drm_open, 252 - .release = drm_release, 253 - .unlocked_ioctl = drm_ioctl, 254 - .mmap = drm_mmap, 255 - .poll = drm_poll, 256 - .fasync = drm_fasync, 257 - .read = drm_read, 258 - #ifdef CONFIG_COMPAT 259 - .compat_ioctl = radeon_compat_ioctl, 260 - #endif 261 - .llseek = noop_llseek, 262 - }, 263 - 234 + .fops = &radeon_driver_old_fops, 264 235 .name = DRIVER_NAME, 265 236 .desc = DRIVER_DESC, 266 237 .date = DRIVER_DATE, ··· 304 303 return radeon_resume_kms(dev); 305 304 } 306 305 306 + static const struct file_operations radeon_driver_kms_fops = { 307 + .owner = THIS_MODULE, 308 + .open = drm_open, 309 + .release = drm_release, 310 + .unlocked_ioctl = drm_ioctl, 311 + .mmap = radeon_mmap, 312 + .poll = drm_poll, 313 + .fasync = drm_fasync, 314 + .read = drm_read, 315 + #ifdef CONFIG_COMPAT 316 + .compat_ioctl = radeon_kms_compat_ioctl, 317 + #endif 318 + }; 319 + 307 320 static struct drm_driver kms_driver = { 308 321 .driver_features = 309 322 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG | ··· 353 338 .dumb_create = radeon_mode_dumb_create, 354 339 .dumb_map_offset = radeon_mode_dumb_mmap, 355 340 .dumb_destroy = radeon_mode_dumb_destroy, 356 - .fops = { 357 - .owner = THIS_MODULE, 358 - .open = drm_open, 359 - .release = drm_release, 360 - .unlocked_ioctl = drm_ioctl, 361 - .mmap = radeon_mmap, 362 - .poll = drm_poll, 363 - .fasync = drm_fasync, 364 - .read = drm_read, 365 - #ifdef CONFIG_COMPAT 366 - .compat_ioctl = radeon_kms_compat_ioctl, 367 - #endif 368 - }, 369 - 341 + .fops = &radeon_driver_kms_fops, 370 342 .name = DRIVER_NAME, 371 343 .desc = DRIVER_DESC, 372 344 .date = DRIVER_DATE,
+12 -11
drivers/gpu/drm/savage/savage_drv.c
··· 35 35 savage_PCI_IDS 36 36 }; 37 37 38 + static const struct file_operations savage_driver_fops = { 39 + .owner = THIS_MODULE, 40 + .open = drm_open, 41 + .release = drm_release, 42 + .unlocked_ioctl = drm_ioctl, 43 + .mmap = drm_mmap, 44 + .poll = drm_poll, 45 + .fasync = drm_fasync, 46 + .llseek = noop_llseek, 47 + }; 48 + 38 49 static struct drm_driver driver = { 39 50 .driver_features = 40 51 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_PCI_DMA, ··· 57 46 .reclaim_buffers = savage_reclaim_buffers, 58 47 .ioctls = savage_ioctls, 59 48 .dma_ioctl = savage_bci_buffers, 60 - .fops = { 61 - .owner = THIS_MODULE, 62 - .open = drm_open, 63 - .release = drm_release, 64 - .unlocked_ioctl = drm_ioctl, 65 - .mmap = drm_mmap, 66 - .poll = drm_poll, 67 - .fasync = drm_fasync, 68 - .llseek = noop_llseek, 69 - }, 70 - 49 + .fops = &savage_driver_fops, 71 50 .name = DRIVER_NAME, 72 51 .desc = DRIVER_DESC, 73 52 .date = DRIVER_DATE,
+12 -11
drivers/gpu/drm/sis/sis_drv.c
··· 65 65 return 0; 66 66 } 67 67 68 + static const struct file_operations sis_driver_fops = { 69 + .owner = THIS_MODULE, 70 + .open = drm_open, 71 + .release = drm_release, 72 + .unlocked_ioctl = drm_ioctl, 73 + .mmap = drm_mmap, 74 + .poll = drm_poll, 75 + .fasync = drm_fasync, 76 + .llseek = noop_llseek, 77 + }; 78 + 68 79 static struct drm_driver driver = { 69 80 .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR, 70 81 .load = sis_driver_load, ··· 85 74 .reclaim_buffers_idlelocked = sis_reclaim_buffers_locked, 86 75 .lastclose = sis_lastclose, 87 76 .ioctls = sis_ioctls, 88 - .fops = { 89 - .owner = THIS_MODULE, 90 - .open = drm_open, 91 - .release = drm_release, 92 - .unlocked_ioctl = drm_ioctl, 93 - .mmap = drm_mmap, 94 - .poll = drm_poll, 95 - .fasync = drm_fasync, 96 - .llseek = noop_llseek, 97 - }, 98 - 77 + .fops = &sis_driver_fops, 99 78 .name = DRIVER_NAME, 100 79 .desc = DRIVER_DESC, 101 80 .date = DRIVER_DATE,
+12 -11
drivers/gpu/drm/tdfx/tdfx_drv.c
··· 41 41 tdfx_PCI_IDS 42 42 }; 43 43 44 + static const struct file_operations tdfx_driver_fops = { 45 + .owner = THIS_MODULE, 46 + .open = drm_open, 47 + .release = drm_release, 48 + .unlocked_ioctl = drm_ioctl, 49 + .mmap = drm_mmap, 50 + .poll = drm_poll, 51 + .fasync = drm_fasync, 52 + .llseek = noop_llseek, 53 + }; 54 + 44 55 static struct drm_driver driver = { 45 56 .driver_features = DRIVER_USE_MTRR, 46 57 .reclaim_buffers = drm_core_reclaim_buffers, 47 - .fops = { 48 - .owner = THIS_MODULE, 49 - .open = drm_open, 50 - .release = drm_release, 51 - .unlocked_ioctl = drm_ioctl, 52 - .mmap = drm_mmap, 53 - .poll = drm_poll, 54 - .fasync = drm_fasync, 55 - .llseek = noop_llseek, 56 - }, 57 - 58 + .fops = &tdfx_driver_fops, 58 59 .name = DRIVER_NAME, 59 60 .desc = DRIVER_DESC, 60 61 .date = DRIVER_DATE,
+12 -11
drivers/gpu/drm/via/via_drv.c
··· 34 34 viadrv_PCI_IDS 35 35 }; 36 36 37 + static const struct file_operations via_driver_fops = { 38 + .owner = THIS_MODULE, 39 + .open = drm_open, 40 + .release = drm_release, 41 + .unlocked_ioctl = drm_ioctl, 42 + .mmap = drm_mmap, 43 + .poll = drm_poll, 44 + .fasync = drm_fasync, 45 + .llseek = noop_llseek, 46 + }; 47 + 37 48 static struct drm_driver driver = { 38 49 .driver_features = 39 50 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ | ··· 65 54 .reclaim_buffers_idlelocked = via_reclaim_buffers_locked, 66 55 .lastclose = via_lastclose, 67 56 .ioctls = via_ioctls, 68 - .fops = { 69 - .owner = THIS_MODULE, 70 - .open = drm_open, 71 - .release = drm_release, 72 - .unlocked_ioctl = drm_ioctl, 73 - .mmap = drm_mmap, 74 - .poll = drm_poll, 75 - .fasync = drm_fasync, 76 - .llseek = noop_llseek, 77 - }, 78 - 57 + .fops = &via_driver_fops, 79 58 .name = DRIVER_NAME, 80 59 .desc = DRIVER_DESC, 81 60 .date = DRIVER_DATE,
+16 -14
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
··· 1064 1064 .resume = vmw_pm_resume, 1065 1065 }; 1066 1066 1067 + static const struct file_operations vmwgfx_driver_fops = { 1068 + .owner = THIS_MODULE, 1069 + .open = drm_open, 1070 + .release = drm_release, 1071 + .unlocked_ioctl = vmw_unlocked_ioctl, 1072 + .mmap = vmw_mmap, 1073 + .poll = vmw_fops_poll, 1074 + .read = vmw_fops_read, 1075 + .fasync = drm_fasync, 1076 + #if defined(CONFIG_COMPAT) 1077 + .compat_ioctl = drm_compat_ioctl, 1078 + #endif 1079 + .llseek = noop_llseek, 1080 + }; 1081 + 1067 1082 static struct drm_driver driver = { 1068 1083 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | 1069 1084 DRIVER_MODESET, ··· 1103 1088 .master_drop = vmw_master_drop, 1104 1089 .open = vmw_driver_open, 1105 1090 .postclose = vmw_postclose, 1106 - .fops = { 1107 - .owner = THIS_MODULE, 1108 - .open = drm_open, 1109 - .release = drm_release, 1110 - .unlocked_ioctl = vmw_unlocked_ioctl, 1111 - .mmap = vmw_mmap, 1112 - .poll = vmw_fops_poll, 1113 - .read = vmw_fops_read, 1114 - .fasync = drm_fasync, 1115 - #if defined(CONFIG_COMPAT) 1116 - .compat_ioctl = drm_compat_ioctl, 1117 - #endif 1118 - .llseek = noop_llseek, 1119 - }, 1091 + .fops = &vmwgfx_driver_fops, 1120 1092 .name = VMWGFX_DRIVER_NAME, 1121 1093 .desc = VMWGFX_DRIVER_DESC, 1122 1094 .date = VMWGFX_DRIVER_DATE,
+12 -11
drivers/staging/gma500/psb_drv.c
··· 1151 1151 .close = drm_gem_vm_close, 1152 1152 }; 1153 1153 1154 + static const struct file_operations gma500_driver_fops = { 1155 + .owner = THIS_MODULE, 1156 + .open = drm_open, 1157 + .release = drm_release, 1158 + .unlocked_ioctl = psb_unlocked_ioctl, 1159 + .mmap = drm_gem_mmap, 1160 + .poll = drm_poll, 1161 + .fasync = drm_fasync, 1162 + .read = drm_read, 1163 + }; 1164 + 1154 1165 static struct drm_driver driver = { 1155 1166 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | \ 1156 1167 DRIVER_IRQ_VBL | DRIVER_MODESET | DRIVER_GEM , ··· 1190 1179 .dumb_create = psb_gem_dumb_create, 1191 1180 .dumb_map_offset = psb_gem_dumb_map_gtt, 1192 1181 .dumb_destroy = psb_gem_dumb_destroy, 1193 - 1194 - .fops = { 1195 - .owner = THIS_MODULE, 1196 - .open = drm_open, 1197 - .release = drm_release, 1198 - .unlocked_ioctl = psb_unlocked_ioctl, 1199 - .mmap = drm_gem_mmap, 1200 - .poll = drm_poll, 1201 - .fasync = drm_fasync, 1202 - .read = drm_read, 1203 - }, 1182 + .fops = &gma500_driver_fops, 1204 1183 .name = DRIVER_NAME, 1205 1184 .desc = DRIVER_DESC, 1206 1185 .date = PSB_DRM_DRIVER_DATE,
+1 -1
include/drm/drmP.h
··· 918 918 int dev_priv_size; 919 919 struct drm_ioctl_desc *ioctls; 920 920 int num_ioctls; 921 - struct file_operations fops; 921 + const struct file_operations *fops; 922 922 union { 923 923 struct pci_driver *pci; 924 924 struct platform_device *platform_device;