| 1 |
/* Reduced and adapted from Linux: fs/proc/inode.c: proc_reg_open |
| 2 |
(GPL v2.0). */ |
| 3 |
|
| 4 |
/* { dg-additional-options "-Wno-analyzer-too-complex -Wno-analyzer-symbol-too-complex" } */ |
| 5 |
|
| 6 |
/* Types. */ |
| 7 |
|
| 8 |
typedef unsigned char u8; |
| 9 |
typedef unsigned int gfp_t; |
| 10 |
|
| 11 |
struct file; |
| 12 |
struct kmem_cache; |
| 13 |
struct proc_dir_entry; |
| 14 |
|
| 15 |
struct inode { /* [...snip...] */ }; |
| 16 |
|
| 17 |
enum { |
| 18 |
PROC_ENTRY_PERMANENT = 1U << 0, |
| 19 |
}; |
| 20 |
|
| 21 |
struct proc_ops { |
| 22 |
/* [...snip...] */ |
| 23 |
int (*proc_open)(struct inode *, struct file *); |
| 24 |
/* [...snip...] */ |
| 25 |
int (*proc_release)(struct inode *, struct file *); |
| 26 |
/* [...snip...] */ |
| 27 |
}; |
| 28 |
|
| 29 |
struct proc_dir_entry { |
| 30 |
/* [...snip...] */ |
| 31 |
struct completion *pde_unload_completion; |
| 32 |
/* [...snip...] */ |
| 33 |
union { |
| 34 |
const struct proc_ops *proc_ops; |
| 35 |
const struct file_operations *proc_dir_ops; |
| 36 |
}; |
| 37 |
/* [...snip...] */ |
| 38 |
u8 flags; |
| 39 |
/* [...snip...] */ |
| 40 |
}; |
| 41 |
|
| 42 |
struct pde_opener { |
| 43 |
/* [...snip...] */ |
| 44 |
struct file *file; |
| 45 |
/* [...snip...] */ |
| 46 |
}; |
| 47 |
|
| 48 |
struct proc_inode { |
| 49 |
/* [...snip...] */ |
| 50 |
struct proc_dir_entry *pde; |
| 51 |
/* [...snip...] */ |
| 52 |
struct inode vfs_inode; |
| 53 |
}; |
| 54 |
|
| 55 |
/* Data. */ |
| 56 |
|
| 57 |
static struct kmem_cache *pde_opener_cache __attribute__((__section__(".data..ro_after_init"))); |
| 58 |
|
| 59 |
/* Functions. */ |
| 60 |
|
| 61 |
void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags) __attribute__((__malloc__)); |
| 62 |
void kmem_cache_free(struct kmem_cache *, void *); |
| 63 |
|
| 64 |
static inline bool pde_is_permanent(const struct proc_dir_entry *pde) |
| 65 |
{ |
| 66 |
return pde->flags & PROC_ENTRY_PERMANENT; |
| 67 |
} |
| 68 |
|
| 69 |
static inline struct proc_inode *PROC_I(const struct inode *inode) |
| 70 |
{ |
| 71 |
char *__mptr = (char *)(inode); |
| 72 |
return ((struct proc_inode *)(__mptr - __builtin_offsetof(struct proc_inode, vfs_inode))); |
| 73 |
} |
| 74 |
|
| 75 |
static inline struct proc_dir_entry *PDE(const struct inode *inode) |
| 76 |
{ |
| 77 |
return PROC_I(inode)->pde; |
| 78 |
} |
| 79 |
|
| 80 |
/* We don't want to emit bogus use of uninitialized value 'pdeo' |
| 81 |
warnings from -Wanalyzer-use-of-uninitialized-value in this function; |
| 82 |
these would require following infeasible paths in which "release" is |
| 83 |
first NULL (to avoid the initialization of "pdeo") and then is non-NULL |
| 84 |
(to access "pdeo"). |
| 85 |
|
| 86 |
"release" is sufficiently complicated in this function to hit the |
| 87 |
complexity limit for symbolic values during enode exploration. */ |
| 88 |
|
| 89 |
static int proc_reg_open(struct inode *inode, struct file *file) |
| 90 |
{ |
| 91 |
struct proc_dir_entry *pde = PDE(inode); |
| 92 |
int rv = 0; |
| 93 |
|
| 94 |
|
| 95 |
int (*open)(struct inode *, struct file *); |
| 96 |
int (*release)(struct inode *, struct file *); |
| 97 |
|
| 98 |
struct pde_opener *pdeo; |
| 99 |
|
| 100 |
if (pde_is_permanent(pde)) { |
| 101 |
open = pde->proc_ops->proc_open; |
| 102 |
if (open) |
| 103 |
rv = open(inode, file); |
| 104 |
return rv; |
| 105 |
} |
| 106 |
|
| 107 |
/* [...snip...] */ |
| 108 |
|
| 109 |
release = pde->proc_ops->proc_release; |
| 110 |
if (release) { |
| 111 |
pdeo = (struct pde_opener *) kmem_cache_alloc(pde_opener_cache, |
| 112 |
((( gfp_t)(0x400u|0x800u)) |
| 113 |
| (( gfp_t)0x40u) |
| 114 |
| (( gfp_t)0x80u))); |
| 115 |
if (!pdeo) { |
| 116 |
rv = -12; |
| 117 |
goto out_unuse; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
open = pde->proc_ops->proc_open; |
| 122 |
if (open) |
| 123 |
rv = open(inode, file); |
| 124 |
|
| 125 |
if (release) { |
| 126 |
if (rv == 0) { |
| 127 |
|
| 128 |
pdeo->file = file; /* { dg-bogus "uninit" } */ |
| 129 |
/* [...snip...] */ |
| 130 |
} else |
| 131 |
kmem_cache_free(pde_opener_cache, pdeo); /* { dg-bogus "uninit" } */ |
| 132 |
} |
| 133 |
|
| 134 |
out_unuse: |
| 135 |
/* [...snip...] */ |
| 136 |
return rv; |
| 137 |
} |