![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-or-later */ 0002 /* 0003 * malloc.h - NTFS kernel memory handling. Part of the Linux-NTFS project. 0004 * 0005 * Copyright (c) 2001-2005 Anton Altaparmakov 0006 */ 0007 0008 #ifndef _LINUX_NTFS_MALLOC_H 0009 #define _LINUX_NTFS_MALLOC_H 0010 0011 #include <linux/vmalloc.h> 0012 #include <linux/slab.h> 0013 #include <linux/highmem.h> 0014 0015 /** 0016 * __ntfs_malloc - allocate memory in multiples of pages 0017 * @size: number of bytes to allocate 0018 * @gfp_mask: extra flags for the allocator 0019 * 0020 * Internal function. You probably want ntfs_malloc_nofs()... 0021 * 0022 * Allocates @size bytes of memory, rounded up to multiples of PAGE_SIZE and 0023 * returns a pointer to the allocated memory. 0024 * 0025 * If there was insufficient memory to complete the request, return NULL. 0026 * Depending on @gfp_mask the allocation may be guaranteed to succeed. 0027 */ 0028 static inline void *__ntfs_malloc(unsigned long size, gfp_t gfp_mask) 0029 { 0030 if (likely(size <= PAGE_SIZE)) { 0031 BUG_ON(!size); 0032 /* kmalloc() has per-CPU caches so is faster for now. */ 0033 return kmalloc(PAGE_SIZE, gfp_mask & ~__GFP_HIGHMEM); 0034 /* return (void *)__get_free_page(gfp_mask); */ 0035 } 0036 if (likely((size >> PAGE_SHIFT) < totalram_pages())) 0037 return __vmalloc(size, gfp_mask); 0038 return NULL; 0039 } 0040 0041 /** 0042 * ntfs_malloc_nofs - allocate memory in multiples of pages 0043 * @size: number of bytes to allocate 0044 * 0045 * Allocates @size bytes of memory, rounded up to multiples of PAGE_SIZE and 0046 * returns a pointer to the allocated memory. 0047 * 0048 * If there was insufficient memory to complete the request, return NULL. 0049 */ 0050 static inline void *ntfs_malloc_nofs(unsigned long size) 0051 { 0052 return __ntfs_malloc(size, GFP_NOFS | __GFP_HIGHMEM); 0053 } 0054 0055 /** 0056 * ntfs_malloc_nofs_nofail - allocate memory in multiples of pages 0057 * @size: number of bytes to allocate 0058 * 0059 * Allocates @size bytes of memory, rounded up to multiples of PAGE_SIZE and 0060 * returns a pointer to the allocated memory. 0061 * 0062 * This function guarantees that the allocation will succeed. It will sleep 0063 * for as long as it takes to complete the allocation. 0064 * 0065 * If there was insufficient memory to complete the request, return NULL. 0066 */ 0067 static inline void *ntfs_malloc_nofs_nofail(unsigned long size) 0068 { 0069 return __ntfs_malloc(size, GFP_NOFS | __GFP_HIGHMEM | __GFP_NOFAIL); 0070 } 0071 0072 static inline void ntfs_free(void *addr) 0073 { 0074 kvfree(addr); 0075 } 0076 0077 #endif /* _LINUX_NTFS_MALLOC_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |