@@ -126,7 +126,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
126
126
ret = - ENOMEM ;
127
127
goto out ;
128
128
}
129
- cpage_out = page_address (out_page );
129
+ cpage_out = kmap (out_page );
130
130
pages [0 ] = out_page ;
131
131
nr_pages = 1 ;
132
132
@@ -148,22 +148,26 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
148
148
int i ;
149
149
150
150
for (i = 0 ; i < in_buf_pages ; i ++ ) {
151
- if (in_page )
151
+ if (in_page ) {
152
+ kunmap (in_page );
152
153
put_page (in_page );
154
+ }
153
155
in_page = find_get_page (mapping ,
154
156
start >> PAGE_SHIFT );
155
- data_in = page_address (in_page );
157
+ data_in = kmap (in_page );
156
158
memcpy (workspace -> buf + i * PAGE_SIZE ,
157
159
data_in , PAGE_SIZE );
158
160
start += PAGE_SIZE ;
159
161
}
160
162
workspace -> strm .next_in = workspace -> buf ;
161
163
} else {
162
- if (in_page )
164
+ if (in_page ) {
165
+ kunmap (in_page );
163
166
put_page (in_page );
167
+ }
164
168
in_page = find_get_page (mapping ,
165
169
start >> PAGE_SHIFT );
166
- data_in = page_address (in_page );
170
+ data_in = kmap (in_page );
167
171
start += PAGE_SIZE ;
168
172
workspace -> strm .next_in = data_in ;
169
173
}
@@ -192,6 +196,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
192
196
* the stream end if required
193
197
*/
194
198
if (workspace -> strm .avail_out == 0 ) {
199
+ kunmap (out_page );
195
200
if (nr_pages == nr_dest_pages ) {
196
201
out_page = NULL ;
197
202
ret = - E2BIG ;
@@ -202,7 +207,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
202
207
ret = - ENOMEM ;
203
208
goto out ;
204
209
}
205
- cpage_out = page_address (out_page );
210
+ cpage_out = kmap (out_page );
206
211
pages [nr_pages ] = out_page ;
207
212
nr_pages ++ ;
208
213
workspace -> strm .avail_out = PAGE_SIZE ;
@@ -229,6 +234,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
229
234
goto out ;
230
235
} else if (workspace -> strm .avail_out == 0 ) {
231
236
/* get another page for the stream end */
237
+ kunmap (out_page );
232
238
if (nr_pages == nr_dest_pages ) {
233
239
out_page = NULL ;
234
240
ret = - E2BIG ;
@@ -239,7 +245,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
239
245
ret = - ENOMEM ;
240
246
goto out ;
241
247
}
242
- cpage_out = page_address (out_page );
248
+ cpage_out = kmap (out_page );
243
249
pages [nr_pages ] = out_page ;
244
250
nr_pages ++ ;
245
251
workspace -> strm .avail_out = PAGE_SIZE ;
@@ -258,8 +264,13 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
258
264
* total_in = workspace -> strm .total_in ;
259
265
out :
260
266
* out_pages = nr_pages ;
261
- if (in_page )
267
+ if (out_page )
268
+ kunmap (out_page );
269
+
270
+ if (in_page ) {
271
+ kunmap (in_page );
262
272
put_page (in_page );
273
+ }
263
274
return ret ;
264
275
}
265
276
@@ -276,7 +287,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
276
287
unsigned long buf_start ;
277
288
struct page * * pages_in = cb -> compressed_pages ;
278
289
279
- data_in = page_address (pages_in [page_in_index ]);
290
+ data_in = kmap (pages_in [page_in_index ]);
280
291
workspace -> strm .next_in = data_in ;
281
292
workspace -> strm .avail_in = min_t (size_t , srclen , PAGE_SIZE );
282
293
workspace -> strm .total_in = 0 ;
@@ -298,6 +309,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
298
309
299
310
if (Z_OK != zlib_inflateInit2 (& workspace -> strm , wbits )) {
300
311
pr_warn ("BTRFS: inflateInit failed\n" );
312
+ kunmap (pages_in [page_in_index ]);
301
313
return - EIO ;
302
314
}
303
315
while (workspace -> strm .total_in < srclen ) {
@@ -324,13 +336,13 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
324
336
325
337
if (workspace -> strm .avail_in == 0 ) {
326
338
unsigned long tmp ;
327
-
339
+ kunmap ( pages_in [ page_in_index ]);
328
340
page_in_index ++ ;
329
341
if (page_in_index >= total_pages_in ) {
330
342
data_in = NULL ;
331
343
break ;
332
344
}
333
- data_in = page_address (pages_in [page_in_index ]);
345
+ data_in = kmap (pages_in [page_in_index ]);
334
346
workspace -> strm .next_in = data_in ;
335
347
tmp = srclen - workspace -> strm .total_in ;
336
348
workspace -> strm .avail_in = min (tmp , PAGE_SIZE );
@@ -342,6 +354,8 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
342
354
ret = 0 ;
343
355
done :
344
356
zlib_inflateEnd (& workspace -> strm );
357
+ if (data_in )
358
+ kunmap (pages_in [page_in_index ]);
345
359
if (!ret )
346
360
zero_fill_bio (cb -> orig_bio );
347
361
return ret ;
0 commit comments