77#include <linux/page-flags.h>
88#include <linux/swap.h>
99
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-
2410/*
2511 * Need to map shmem indices to handle since a handle value
2612 * 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)
4026 * @backup: The struct backup pointer used to obtain the handle
4127 * @handle: The handle obtained from the @backup_page function.
4228 */
43- void ttm_backup_drop (struct ttm_backup * backup , pgoff_t handle )
29+ void ttm_backup_drop (struct file * backup , pgoff_t handle )
4430{
4531 loff_t start = ttm_backup_handle_to_shmem_idx (handle );
4632
4733 start <<= PAGE_SHIFT ;
48- shmem_truncate_range (file_inode (ttm_backup_to_file ( backup ) ), start ,
34+ shmem_truncate_range (file_inode (backup ), start ,
4935 start + PAGE_SIZE - 1 );
5036}
5137
@@ -55,16 +41,15 @@ void ttm_backup_drop(struct ttm_backup *backup, pgoff_t handle)
5541 * @backup: The struct backup pointer used to back up the page.
5642 * @dst: The struct page to copy into.
5743 * @handle: The handle returned when the page was backed up.
58- * @intr: Try to perform waits interruptable or at least killable.
44+ * @intr: Try to perform waits interruptible or at least killable.
5945 *
6046 * Return: 0 on success, Negative error code on failure, notably
6147 * -EINTR if @intr was set to true and a signal is pending.
6248 */
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 ,
6450 pgoff_t handle , bool intr )
6551{
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 ;
6853 struct folio * from_folio ;
6954 pgoff_t idx = ttm_backup_handle_to_shmem_idx (handle );
7055
@@ -106,12 +91,11 @@ int ttm_backup_copy_page(struct ttm_backup *backup, struct page *dst,
10691 * the folio size- and usage.
10792 */
10893s64
109- ttm_backup_backup_page (struct ttm_backup * backup , struct page * page ,
94+ ttm_backup_backup_page (struct file * backup , struct page * page ,
11095 bool writeback , pgoff_t idx , gfp_t page_gfp ,
11196 gfp_t alloc_gfp )
11297{
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 ;
11599 unsigned long handle = 0 ;
116100 struct folio * to_folio ;
117101 int ret ;
@@ -161,9 +145,9 @@ ttm_backup_backup_page(struct ttm_backup *backup, struct page *page,
161145 *
162146 * After a call to this function, it's illegal to use the @backup pointer.
163147 */
164- void ttm_backup_fini (struct ttm_backup * backup )
148+ void ttm_backup_fini (struct file * backup )
165149{
166- fput (ttm_backup_to_file ( backup ) );
150+ fput (backup );
167151}
168152
169153/**
@@ -194,14 +178,10 @@ EXPORT_SYMBOL_GPL(ttm_backup_bytes_avail);
194178 *
195179 * Create a backup utilizing shmem objects.
196180 *
197- * Return: A pointer to a struct ttm_backup on success,
181+ * Return: A pointer to a struct file on success,
198182 * an error pointer on error.
199183 */
200- struct ttm_backup * ttm_backup_shmem_create (loff_t size )
184+ struct file * ttm_backup_shmem_create (loff_t size )
201185{
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 );
207187}
0 commit comments