7
7
#include <linux/page-flags.h>
8
8
#include <linux/swap.h>
9
9
10
- /*
11
- * Casting from randomized struct file * to struct ttm_backup * is fine since
12
- * struct ttm_backup is never defined nor dereferenced.
13
- */
14
- static struct file * ttm_backup_to_file (struct ttm_backup * backup )
15
- {
16
- return (void * )backup ;
17
- }
18
-
19
- static struct ttm_backup * ttm_file_to_backup (struct file * file )
20
- {
21
- return (void * )file ;
22
- }
23
-
24
10
/*
25
11
* Need to map shmem indices to handle since a handle value
26
12
* of 0 means error, following the swp_entry_t convention.
@@ -40,12 +26,12 @@ static pgoff_t ttm_backup_handle_to_shmem_idx(pgoff_t handle)
40
26
* @backup: The struct backup pointer used to obtain the handle
41
27
* @handle: The handle obtained from the @backup_page function.
42
28
*/
43
- void ttm_backup_drop (struct ttm_backup * backup , pgoff_t handle )
29
+ void ttm_backup_drop (struct file * backup , pgoff_t handle )
44
30
{
45
31
loff_t start = ttm_backup_handle_to_shmem_idx (handle );
46
32
47
33
start <<= PAGE_SHIFT ;
48
- shmem_truncate_range (file_inode (ttm_backup_to_file ( backup ) ), start ,
34
+ shmem_truncate_range (file_inode (backup ), start ,
49
35
start + PAGE_SIZE - 1 );
50
36
}
51
37
@@ -60,11 +46,10 @@ void ttm_backup_drop(struct ttm_backup *backup, pgoff_t handle)
60
46
* Return: 0 on success, Negative error code on failure, notably
61
47
* -EINTR if @intr was set to true and a signal is pending.
62
48
*/
63
- int ttm_backup_copy_page (struct ttm_backup * backup , struct page * dst ,
49
+ int ttm_backup_copy_page (struct file * backup , struct page * dst ,
64
50
pgoff_t handle , bool intr )
65
51
{
66
- struct file * filp = ttm_backup_to_file (backup );
67
- struct address_space * mapping = filp -> f_mapping ;
52
+ struct address_space * mapping = backup -> f_mapping ;
68
53
struct folio * from_folio ;
69
54
pgoff_t idx = ttm_backup_handle_to_shmem_idx (handle );
70
55
@@ -106,12 +91,11 @@ int ttm_backup_copy_page(struct ttm_backup *backup, struct page *dst,
106
91
* the folio size- and usage.
107
92
*/
108
93
s64
109
- ttm_backup_backup_page (struct ttm_backup * backup , struct page * page ,
94
+ ttm_backup_backup_page (struct file * backup , struct page * page ,
110
95
bool writeback , pgoff_t idx , gfp_t page_gfp ,
111
96
gfp_t alloc_gfp )
112
97
{
113
- struct file * filp = ttm_backup_to_file (backup );
114
- struct address_space * mapping = filp -> f_mapping ;
98
+ struct address_space * mapping = backup -> f_mapping ;
115
99
unsigned long handle = 0 ;
116
100
struct folio * to_folio ;
117
101
int ret ;
@@ -161,9 +145,9 @@ ttm_backup_backup_page(struct ttm_backup *backup, struct page *page,
161
145
*
162
146
* After a call to this function, it's illegal to use the @backup pointer.
163
147
*/
164
- void ttm_backup_fini (struct ttm_backup * backup )
148
+ void ttm_backup_fini (struct file * backup )
165
149
{
166
- fput (ttm_backup_to_file ( backup ) );
150
+ fput (backup );
167
151
}
168
152
169
153
/**
@@ -194,14 +178,10 @@ EXPORT_SYMBOL_GPL(ttm_backup_bytes_avail);
194
178
*
195
179
* Create a backup utilizing shmem objects.
196
180
*
197
- * Return: A pointer to a struct ttm_backup on success,
181
+ * Return: A pointer to a struct file on success,
198
182
* an error pointer on error.
199
183
*/
200
- struct ttm_backup * ttm_backup_shmem_create (loff_t size )
184
+ struct file * ttm_backup_shmem_create (loff_t size )
201
185
{
202
- struct file * filp ;
203
-
204
- filp = shmem_file_setup ("ttm shmem backup" , size , 0 );
205
-
206
- return ttm_file_to_backup (filp );
186
+ return shmem_file_setup ("ttm shmem backup" , size , 0 );
207
187
}
0 commit comments