Skip to content

Commit 5b93f24

Browse files
committed
btrfs: lzo: inline read/write length helpers
The LZO_LEN read/write helpers are supposed to be trivial and we're duplicating the put/get unaligned helpers so use them directly. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 463626a commit 5b93f24

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

fs/btrfs/lzo.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,22 +106,6 @@ struct list_head *lzo_alloc_workspace(struct btrfs_fs_info *fs_info)
106106
return ERR_PTR(-ENOMEM);
107107
}
108108

109-
static inline void write_compress_length(char *buf, size_t len)
110-
{
111-
__le32 dlen;
112-
113-
dlen = cpu_to_le32(len);
114-
memcpy(buf, &dlen, LZO_LEN);
115-
}
116-
117-
static inline size_t read_compress_length(const char *buf)
118-
{
119-
__le32 dlen;
120-
121-
memcpy(&dlen, buf, LZO_LEN);
122-
return le32_to_cpu(dlen);
123-
}
124-
125109
/*
126110
* Write data into @out_folio and queue it into @out_bio.
127111
*
@@ -225,7 +209,7 @@ static int copy_compressed_data_to_bio(struct btrfs_fs_info *fs_info,
225209

226210
/* Write the segment header first. */
227211
kaddr = kmap_local_folio(*out_folio, offset_in_folio(*out_folio, *total_out));
228-
write_compress_length(kaddr, compressed_size);
212+
put_unaligned_le32(compressed_size, kaddr);
229213
kunmap_local(kaddr);
230214
ret = write_and_queue_folio(out_bio, out_folio, total_out, LZO_LEN);
231215
if (ret < 0)
@@ -362,7 +346,7 @@ int lzo_compress_bio(struct list_head *ws, struct compressed_bio *cb)
362346

363347
/* Store the size of all chunks of compressed data */
364348
sizes_ptr = kmap_local_folio(bio_first_folio_all(bio), 0);
365-
write_compress_length(sizes_ptr, total_out);
349+
put_unaligned_le32(total_out, sizes_ptr);
366350
kunmap_local(sizes_ptr);
367351
out:
368352
/*
@@ -450,7 +434,7 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
450434
return -EINVAL;
451435
ASSERT(folio_size(fi.folio) == btrfs_min_folio_size(fs_info));
452436
kaddr = kmap_local_folio(fi.folio, 0);
453-
len_in = read_compress_length(kaddr);
437+
len_in = get_unaligned_le32(kaddr);
454438
kunmap_local(kaddr);
455439
cur_in += LZO_LEN;
456440

@@ -489,7 +473,7 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
489473
cur_folio = get_current_folio(cb, &fi, &cur_folio_index, cur_in);
490474
ASSERT(cur_folio);
491475
kaddr = kmap_local_folio(cur_folio, 0);
492-
seg_len = read_compress_length(kaddr + offset_in_folio(cur_folio, cur_in));
476+
seg_len = get_unaligned_le32(kaddr + offset_in_folio(cur_folio, cur_in));
493477
kunmap_local(kaddr);
494478
cur_in += LZO_LEN;
495479

@@ -560,12 +544,12 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,
560544
if (unlikely(srclen < LZO_LEN || srclen > max_segment_len + LZO_LEN * 2))
561545
return -EUCLEAN;
562546

563-
in_len = read_compress_length(data_in);
547+
in_len = get_unaligned_le32(data_in);
564548
if (unlikely(in_len != srclen))
565549
return -EUCLEAN;
566550
data_in += LZO_LEN;
567551

568-
in_len = read_compress_length(data_in);
552+
in_len = get_unaligned_le32(data_in);
569553
if (unlikely(in_len != srclen - LZO_LEN * 2))
570554
return -EUCLEAN;
571555
data_in += LZO_LEN;

0 commit comments

Comments
 (0)