usb: gadget: f_mtp: Avoid race between mtp_read and mtp_function_disable
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / fs / squashfs / page_actor.h
1 #ifndef PAGE_ACTOR_H
2 #define PAGE_ACTOR_H
3 /*
4 * Copyright (c) 2013
5 * Phillip Lougher <phillip@squashfs.org.uk>
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2. See
8 * the COPYING file in the top-level squashfsory.
9 */
10
11 struct squashfs_page_actor {
12 struct page **page;
13 void *pageaddr;
14 int pages;
15 int length;
16 int next_page;
17 void (*release_pages)(struct page **, int, int);
18 };
19
20 extern struct squashfs_page_actor *squashfs_page_actor_init(struct page **,
21 int, int, void (*)(struct page **, int, int));
22 extern void squashfs_page_actor_free(struct squashfs_page_actor *, int);
23
24 extern void squashfs_actor_to_buf(struct squashfs_page_actor *, void *, int);
25 extern void squashfs_buf_to_actor(void *, struct squashfs_page_actor *, int);
26 extern void squashfs_bh_to_actor(struct buffer_head **, int,
27 struct squashfs_page_actor *, int, int, int);
28 extern void squashfs_bh_to_buf(struct buffer_head **, int, void *, int, int,
29 int);
30
31 /*
32 * Calling code should avoid sleeping between calls to squashfs_first_page()
33 * and squashfs_finish_page().
34 */
35 static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
36 {
37 actor->next_page = 1;
38 return actor->pageaddr = actor->page[0] ? kmap_atomic(actor->page[0])
39 : NULL;
40 }
41
42 static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
43 {
44 if (!IS_ERR_OR_NULL(actor->pageaddr))
45 kunmap_atomic(actor->pageaddr);
46
47 if (actor->next_page == actor->pages)
48 return actor->pageaddr = ERR_PTR(-ENODATA);
49
50 actor->pageaddr = actor->page[actor->next_page] ?
51 kmap_atomic(actor->page[actor->next_page]) : NULL;
52 ++actor->next_page;
53 return actor->pageaddr;
54 }
55
56 static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
57 {
58 if (!IS_ERR_OR_NULL(actor->pageaddr))
59 kunmap_atomic(actor->pageaddr);
60 }
61
62 extern struct page **alloc_page_array(int, int);
63 extern void free_page_array(struct page **, int);
64
65 #endif