Skip to content

Commit e08e96d

Browse files
Arjan van de Venairlied
authored andcommitted
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>
1 parent d68752c commit e08e96d

14 files changed

Lines changed: 183 additions & 170 deletions

File tree

‎drivers/gpu/drm/drm_fops.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ int drm_stub_open(struct inode *inode, struct file *filp)
182182
goto out;
183183

184184
old_fops = filp->f_op;
185-
filp->f_op = fops_get(&dev->driver->fops);
185+
filp->f_op = fops_get(dev->driver->fops);
186186
if (filp->f_op == NULL) {
187187
filp->f_op = old_fops;
188188
goto out;

‎drivers/gpu/drm/i810/i810_drv.c‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ static struct pci_device_id pciidlist[] = {
4343
i810_PCI_IDS
4444
};
4545

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+
4657
static struct drm_driver driver = {
4758
.driver_features =
4859
DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | DRIVER_USE_MTRR |
@@ -55,17 +66,7 @@ static struct drm_driver driver = {
5566
.reclaim_buffers_locked = i810_driver_reclaim_buffers_locked,
5667
.dma_quiescent = i810_driver_dma_quiescent,
5768
.ioctls = i810_ioctls,
58-
.fops = {
59-
.owner = THIS_MODULE,
60-
.open = drm_open,
61-
.release = drm_release,
62-
.unlocked_ioctl = drm_ioctl,
63-
.mmap = drm_mmap,
64-
.poll = drm_poll,
65-
.fasync = drm_fasync,
66-
.llseek = noop_llseek,
67-
},
68-
69+
.fops = &i810_driver_fops,
6970
.name = DRIVER_NAME,
7071
.desc = DRIVER_DESC,
7172
.date = DRIVER_DATE,

‎drivers/gpu/drm/i915/i915_drv.c‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,21 @@ static struct vm_operations_struct i915_gem_vm_ops = {
788788
.close = drm_gem_vm_close,
789789
};
790790

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+
791806
static struct drm_driver driver = {
792807
/* don't use mtrr's here, the Xserver or user space app should
793808
* deal with them for intel hardware.
@@ -821,21 +836,7 @@ static struct drm_driver driver = {
821836
.dumb_map_offset = i915_gem_mmap_gtt,
822837
.dumb_destroy = i915_gem_dumb_destroy,
823838
.ioctls = i915_ioctls,
824-
.fops = {
825-
.owner = THIS_MODULE,
826-
.open = drm_open,
827-
.release = drm_release,
828-
.unlocked_ioctl = drm_ioctl,
829-
.mmap = drm_gem_mmap,
830-
.poll = drm_poll,
831-
.fasync = drm_fasync,
832-
.read = drm_read,
833-
#ifdef CONFIG_COMPAT
834-
.compat_ioctl = i915_compat_ioctl,
835-
#endif
836-
.llseek = noop_llseek,
837-
},
838-
839+
.fops = &i915_driver_fops,
839840
.name = DRIVER_NAME,
840841
.desc = DRIVER_DESC,
841842
.date = DRIVER_DATE,

‎drivers/gpu/drm/mga/mga_drv.c‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ static struct pci_device_id pciidlist[] = {
4444
mga_PCI_IDS
4545
};
4646

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+
4761
static struct drm_driver driver = {
4862
.driver_features =
4963
DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
@@ -64,20 +78,7 @@ static struct drm_driver driver = {
6478
.reclaim_buffers = drm_core_reclaim_buffers,
6579
.ioctls = mga_ioctls,
6680
.dma_ioctl = mga_dma_buffers,
67-
.fops = {
68-
.owner = THIS_MODULE,
69-
.open = drm_open,
70-
.release = drm_release,
71-
.unlocked_ioctl = drm_ioctl,
72-
.mmap = drm_mmap,
73-
.poll = drm_poll,
74-
.fasync = drm_fasync,
75-
#ifdef CONFIG_COMPAT
76-
.compat_ioctl = mga_compat_ioctl,
77-
#endif
78-
.llseek = noop_llseek,
79-
},
80-
81+
.fops = &mga_driver_fops,
8182
.name = DRIVER_NAME,
8283
.desc = DRIVER_DESC,
8384
.date = DRIVER_DATE,

‎drivers/gpu/drm/nouveau/nouveau_drv.c‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,21 @@ nouveau_pci_resume(struct pci_dev *pdev)
388388
return 0;
389389
}
390390

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+
391406
static struct drm_driver driver = {
392407
.driver_features =
393408
DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
@@ -413,21 +428,7 @@ static struct drm_driver driver = {
413428
.disable_vblank = nouveau_vblank_disable,
414429
.reclaim_buffers = drm_core_reclaim_buffers,
415430
.ioctls = nouveau_ioctls,
416-
.fops = {
417-
.owner = THIS_MODULE,
418-
.open = drm_open,
419-
.release = drm_release,
420-
.unlocked_ioctl = drm_ioctl,
421-
.mmap = nouveau_ttm_mmap,
422-
.poll = drm_poll,
423-
.fasync = drm_fasync,
424-
.read = drm_read,
425-
#if defined(CONFIG_COMPAT)
426-
.compat_ioctl = nouveau_compat_ioctl,
427-
#endif
428-
.llseek = noop_llseek,
429-
},
430-
431+
.fops = &nouveau_driver_fops,
431432
.gem_init_object = nouveau_gem_object_new,
432433
.gem_free_object = nouveau_gem_object_del,
433434
.gem_open_object = nouveau_gem_object_open,

‎drivers/gpu/drm/r128/r128_drv.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ static struct pci_device_id pciidlist[] = {
4242
r128_PCI_IDS
4343
};
4444

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+
4559
static struct drm_driver driver = {
4660
.driver_features =
4761
DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
@@ -60,21 +74,7 @@ static struct drm_driver driver = {
6074
.reclaim_buffers = drm_core_reclaim_buffers,
6175
.ioctls = r128_ioctls,
6276
.dma_ioctl = r128_cce_buffers,
63-
.fops = {
64-
.owner = THIS_MODULE,
65-
.open = drm_open,
66-
.release = drm_release,
67-
.unlocked_ioctl = drm_ioctl,
68-
.mmap = drm_mmap,
69-
.poll = drm_poll,
70-
.fasync = drm_fasync,
71-
#ifdef CONFIG_COMPAT
72-
.compat_ioctl = r128_compat_ioctl,
73-
#endif
74-
.llseek = noop_llseek,
75-
},
76-
77-
77+
.fops = &r128_driver_fops,
7878
.name = DRIVER_NAME,
7979
.desc = DRIVER_DESC,
8080
.date = DRIVER_DATE,

‎drivers/gpu/drm/radeon/radeon_drv.c‎

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ static struct pci_device_id pciidlist[] = {
205205
MODULE_DEVICE_TABLE(pci, pciidlist);
206206
#endif
207207

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+
208223
static struct drm_driver driver_old = {
209224
.driver_features =
210225
DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
@@ -231,21 +246,7 @@ static struct drm_driver driver_old = {
231246
.reclaim_buffers = drm_core_reclaim_buffers,
232247
.ioctls = radeon_ioctls,
233248
.dma_ioctl = radeon_cp_buffers,
234-
.fops = {
235-
.owner = THIS_MODULE,
236-
.open = drm_open,
237-
.release = drm_release,
238-
.unlocked_ioctl = drm_ioctl,
239-
.mmap = drm_mmap,
240-
.poll = drm_poll,
241-
.fasync = drm_fasync,
242-
.read = drm_read,
243-
#ifdef CONFIG_COMPAT
244-
.compat_ioctl = radeon_compat_ioctl,
245-
#endif
246-
.llseek = noop_llseek,
247-
},
248-
249+
.fops = &radeon_driver_old_fops,
249250
.name = DRIVER_NAME,
250251
.desc = DRIVER_DESC,
251252
.date = DRIVER_DATE,
@@ -303,6 +304,20 @@ radeon_pci_resume(struct pci_dev *pdev)
303304
return radeon_resume_kms(dev);
304305
}
305306

307+
static const struct file_operations radeon_driver_kms_fops = {
308+
.owner = THIS_MODULE,
309+
.open = drm_open,
310+
.release = drm_release,
311+
.unlocked_ioctl = drm_ioctl,
312+
.mmap = radeon_mmap,
313+
.poll = drm_poll,
314+
.fasync = drm_fasync,
315+
.read = drm_read,
316+
#ifdef CONFIG_COMPAT
317+
.compat_ioctl = radeon_kms_compat_ioctl,
318+
#endif
319+
};
320+
306321
static struct drm_driver kms_driver = {
307322
.driver_features =
308323
DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | DRIVER_SG |
@@ -338,20 +353,7 @@ static struct drm_driver kms_driver = {
338353
.dumb_create = radeon_mode_dumb_create,
339354
.dumb_map_offset = radeon_mode_dumb_mmap,
340355
.dumb_destroy = radeon_mode_dumb_destroy,
341-
.fops = {
342-
.owner = THIS_MODULE,
343-
.open = drm_open,
344-
.release = drm_release,
345-
.unlocked_ioctl = drm_ioctl,
346-
.mmap = radeon_mmap,
347-
.poll = drm_poll,
348-
.fasync = drm_fasync,
349-
.read = drm_read,
350-
#ifdef CONFIG_COMPAT
351-
.compat_ioctl = radeon_kms_compat_ioctl,
352-
#endif
353-
},
354-
356+
.fops = &radeon_driver_kms_fops,
355357
.name = DRIVER_NAME,
356358
.desc = DRIVER_DESC,
357359
.date = DRIVER_DATE,

‎drivers/gpu/drm/savage/savage_drv.c‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ static struct pci_device_id pciidlist[] = {
3535
savage_PCI_IDS
3636
};
3737

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+
3849
static struct drm_driver driver = {
3950
.driver_features =
4051
DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_DMA | DRIVER_PCI_DMA,
@@ -46,17 +57,7 @@ static struct drm_driver driver = {
4657
.reclaim_buffers = savage_reclaim_buffers,
4758
.ioctls = savage_ioctls,
4859
.dma_ioctl = savage_bci_buffers,
49-
.fops = {
50-
.owner = THIS_MODULE,
51-
.open = drm_open,
52-
.release = drm_release,
53-
.unlocked_ioctl = drm_ioctl,
54-
.mmap = drm_mmap,
55-
.poll = drm_poll,
56-
.fasync = drm_fasync,
57-
.llseek = noop_llseek,
58-
},
59-
60+
.fops = &savage_driver_fops,
6061
.name = DRIVER_NAME,
6162
.desc = DRIVER_DESC,
6263
.date = DRIVER_DATE,

‎drivers/gpu/drm/sis/sis_drv.c‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ static int sis_driver_unload(struct drm_device *dev)
6565
return 0;
6666
}
6767

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+
6879
static struct drm_driver driver = {
6980
.driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR,
7081
.load = sis_driver_load,
@@ -74,17 +85,7 @@ static struct drm_driver driver = {
7485
.reclaim_buffers_idlelocked = sis_reclaim_buffers_locked,
7586
.lastclose = sis_lastclose,
7687
.ioctls = sis_ioctls,
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-
.llseek = noop_llseek,
86-
},
87-
88+
.fops = &sis_driver_fops,
8889
.name = DRIVER_NAME,
8990
.desc = DRIVER_DESC,
9091
.date = DRIVER_DATE,

0 commit comments

Comments
 (0)