Skip to content

Commit ca16d14

Browse files
kosakitorvalds
authored andcommitted
mm: don't access vm_flags as 'int'
The type of vma->vm_flags is 'unsigned long'. Neither 'int' nor 'unsigned int'. This patch fixes such misuse. Signed-off-by: KOSAKI Motohiro <[email protected]> [ Changed to use a typedef - we'll extend it to cover more cases later, since there has been discussion about making it a 64-bit type.. - Linus ] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4db70f7 commit ca16d14

File tree

12 files changed

+26
-23
lines changed

12 files changed

+26
-23
lines changed

fs/hugetlbfs/inode.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ static int can_do_hugetlb_shm(void)
921921
return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
922922
}
923923

924-
struct file *hugetlb_file_setup(const char *name, size_t size, int acctflag,
924+
struct file *hugetlb_file_setup(const char *name, size_t size,
925+
vm_flags_t acctflag,
925926
struct user_struct **user, int creat_flags)
926927
{
927928
int error = -ENOMEM;

fs/proc/task_mmu.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
211211
{
212212
struct mm_struct *mm = vma->vm_mm;
213213
struct file *file = vma->vm_file;
214-
int flags = vma->vm_flags;
214+
vm_flags_t flags = vma->vm_flags;
215215
unsigned long ino = 0;
216216
unsigned long long pgoff = 0;
217217
unsigned long start, end;

include/linux/hugetlb.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
4141
unsigned long address, unsigned int flags);
4242
int hugetlb_reserve_pages(struct inode *inode, long from, long to,
4343
struct vm_area_struct *vma,
44-
int acctflags);
44+
vm_flags_t vm_flags);
4545
void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed);
4646
int dequeue_hwpoisoned_huge_page(struct page *page);
4747
void copy_huge_page(struct page *dst, struct page *src);
@@ -168,7 +168,7 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb)
168168

169169
extern const struct file_operations hugetlbfs_file_operations;
170170
extern const struct vm_operations_struct hugetlb_vm_ops;
171-
struct file *hugetlb_file_setup(const char *name, size_t size, int acct,
171+
struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct,
172172
struct user_struct **user, int creat_flags);
173173
int hugetlb_get_quota(struct address_space *mapping, long delta);
174174
void hugetlb_put_quota(struct address_space *mapping, long delta);
@@ -192,7 +192,7 @@ static inline void set_file_hugepages(struct file *file)
192192
#define is_file_hugepages(file) 0
193193
#define set_file_hugepages(file) BUG()
194194
static inline struct file *hugetlb_file_setup(const char *name, size_t size,
195-
int acctflag, struct user_struct **user, int creat_flags)
195+
vm_flags_t acctflag, struct user_struct **user, int creat_flags)
196196
{
197197
return ERR_PTR(-ENOSYS);
198198
}

include/linux/hugetlb_inline.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
99
{
10-
return vma->vm_flags & VM_HUGETLB;
10+
return !!(vma->vm_flags & VM_HUGETLB);
1111
}
1212

1313
#else

include/linux/mm.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ extern pgprot_t protection_map[16];
165165
*/
166166
static inline int is_linear_pfn_mapping(struct vm_area_struct *vma)
167167
{
168-
return (vma->vm_flags & VM_PFN_AT_MMAP);
168+
return !!(vma->vm_flags & VM_PFN_AT_MMAP);
169169
}
170170

171171
static inline int is_pfn_mapping(struct vm_area_struct *vma)
172172
{
173-
return (vma->vm_flags & VM_PFNMAP);
173+
return !!(vma->vm_flags & VM_PFNMAP);
174174
}
175175

176176
/*
@@ -1432,7 +1432,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
14321432
unsigned long flag, unsigned long pgoff);
14331433
extern unsigned long mmap_region(struct file *file, unsigned long addr,
14341434
unsigned long len, unsigned long flags,
1435-
unsigned int vm_flags, unsigned long pgoff);
1435+
vm_flags_t vm_flags, unsigned long pgoff);
14361436

14371437
static inline unsigned long do_mmap(struct file *file, unsigned long addr,
14381438
unsigned long len, unsigned long prot,

include/linux/mm_types.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ struct page {
102102
#endif
103103
};
104104

105+
typedef unsigned long __nocast vm_flags_t;
106+
105107
/*
106108
* A region containing a mapping of a non-memory backed file under NOMMU
107109
* conditions. These are held in a global tree and are pinned by the VMAs that
108110
* map parts of them.
109111
*/
110112
struct vm_region {
111113
struct rb_node vm_rb; /* link in global region tree */
112-
unsigned long vm_flags; /* VMA vm_flags */
114+
vm_flags_t vm_flags; /* VMA vm_flags */
113115
unsigned long vm_start; /* start address of region */
114116
unsigned long vm_end; /* region initialised to here */
115117
unsigned long vm_top; /* region allocated to here */

ipc/shm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
347347
struct file * file;
348348
char name[13];
349349
int id;
350-
int acctflag = 0;
350+
vm_flags_t acctflag = 0;
351351

352352
if (size < SHMMIN || size > ns->shm_ctlmax)
353353
return -EINVAL;

mm/fremap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
224224
/*
225225
* drop PG_Mlocked flag for over-mapped range
226226
*/
227-
unsigned int saved_flags = vma->vm_flags;
227+
vm_flags_t saved_flags = vma->vm_flags;
228228
munlock_vma_pages_range(vma, start, start + size);
229229
vma->vm_flags = saved_flags;
230230
}

mm/hugetlb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,7 @@ void hugetlb_change_protection(struct vm_area_struct *vma,
28332833
int hugetlb_reserve_pages(struct inode *inode,
28342834
long from, long to,
28352835
struct vm_area_struct *vma,
2836-
int acctflag)
2836+
vm_flags_t vm_flags)
28372837
{
28382838
long ret, chg;
28392839
struct hstate *h = hstate_inode(inode);
@@ -2843,7 +2843,7 @@ int hugetlb_reserve_pages(struct inode *inode,
28432843
* attempt will be made for VM_NORESERVE to allocate a page
28442844
* and filesystem quota without using reserves
28452845
*/
2846-
if (acctflag & VM_NORESERVE)
2846+
if (vm_flags & VM_NORESERVE)
28472847
return 0;
28482848

28492849
/*

mm/memory.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
730730
add_taint(TAINT_BAD_PAGE);
731731
}
732732

733-
static inline int is_cow_mapping(unsigned int flags)
733+
static inline int is_cow_mapping(vm_flags_t flags)
734734
{
735735
return (flags & (VM_SHARED | VM_MAYWRITE)) == VM_MAYWRITE;
736736
}

mm/mlock.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,13 @@ void munlock_vma_pages_range(struct vm_area_struct *vma,
307307
* For vmas that pass the filters, merge/split as appropriate.
308308
*/
309309
static int mlock_fixup(struct vm_area_struct *vma, struct vm_area_struct **prev,
310-
unsigned long start, unsigned long end, unsigned int newflags)
310+
unsigned long start, unsigned long end, vm_flags_t newflags)
311311
{
312312
struct mm_struct *mm = vma->vm_mm;
313313
pgoff_t pgoff;
314314
int nr_pages;
315315
int ret = 0;
316-
int lock = newflags & VM_LOCKED;
316+
int lock = !!(newflags & VM_LOCKED);
317317

318318
if (newflags == vma->vm_flags || (vma->vm_flags & VM_SPECIAL) ||
319319
is_vm_hugetlb_page(vma) || vma == get_gate_vma(current->mm))
@@ -385,7 +385,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
385385
prev = vma;
386386

387387
for (nstart = start ; ; ) {
388-
unsigned int newflags;
388+
vm_flags_t newflags;
389389

390390
/* Here we know that vma->vm_start <= nstart < vma->vm_end. */
391391

@@ -524,7 +524,7 @@ static int do_mlockall(int flags)
524524
goto out;
525525

526526
for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
527-
unsigned int newflags;
527+
vm_flags_t newflags;
528528

529529
newflags = vma->vm_flags | VM_LOCKED;
530530
if (!(flags & MCL_CURRENT))

mm/mmap.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
960960
{
961961
struct mm_struct * mm = current->mm;
962962
struct inode *inode;
963-
unsigned int vm_flags;
963+
vm_flags_t vm_flags;
964964
int error;
965965
unsigned long reqprot = prot;
966966

@@ -1165,7 +1165,7 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg)
11651165
*/
11661166
int vma_wants_writenotify(struct vm_area_struct *vma)
11671167
{
1168-
unsigned int vm_flags = vma->vm_flags;
1168+
vm_flags_t vm_flags = vma->vm_flags;
11691169

11701170
/* If it was private or non-writable, the write bit is already clear */
11711171
if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
@@ -1193,7 +1193,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
11931193
* We account for memory if it's a private writeable mapping,
11941194
* not hugepages and VM_NORESERVE wasn't set.
11951195
*/
1196-
static inline int accountable_mapping(struct file *file, unsigned int vm_flags)
1196+
static inline int accountable_mapping(struct file *file, vm_flags_t vm_flags)
11971197
{
11981198
/*
11991199
* hugetlb has its own accounting separate from the core VM
@@ -1207,7 +1207,7 @@ static inline int accountable_mapping(struct file *file, unsigned int vm_flags)
12071207

12081208
unsigned long mmap_region(struct file *file, unsigned long addr,
12091209
unsigned long len, unsigned long flags,
1210-
unsigned int vm_flags, unsigned long pgoff)
1210+
vm_flags_t vm_flags, unsigned long pgoff)
12111211
{
12121212
struct mm_struct *mm = current->mm;
12131213
struct vm_area_struct *vma, *prev;

0 commit comments

Comments
 (0)