Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions arch/arm64/kernel/patching.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ static void *__text_poke(text_poke_f func, void *addr, void *src, size_t len)

while (patched < len) {
ptr = addr + patched;
size = min_t(size_t, PAGE_SIZE - offset_in_page(ptr),
len - patched);

size = min_t(size_t, rest_of_page(ptr), len - patched);
waddr = patch_map(ptr, FIX_TEXT_POKE0);
func(waddr, src, patched, size);
patch_unmap(FIX_TEXT_POKE0);
Expand Down
6 changes: 3 additions & 3 deletions arch/powerpc/lib/code-patching.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static int __patch_instructions(u32 *patch_addr, u32 *code, size_t len, bool rep

/*
* A page is mapped and instructions that fit the page are patched.
* Assumes 'len' to be (PAGE_SIZE - offset_in_page(addr)) or below.
* Assumes 'len' to be rest_of_page(addr) or below.
*/
static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool repeat_instr)
{
Expand Down Expand Up @@ -514,7 +514,7 @@ static int __do_patch_instructions_mm(u32 *addr, u32 *code, size_t len, bool rep

/*
* A page is mapped and instructions that fit the page are patched.
* Assumes 'len' to be (PAGE_SIZE - offset_in_page(addr)) or below.
* Assumes 'len' to be rest_of_page(addr) or below.
*/
static int __do_patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
{
Expand Down Expand Up @@ -554,7 +554,7 @@ int patch_instructions(u32 *addr, u32 *code, size_t len, bool repeat_instr)
size_t plen;
int err;

plen = min_t(size_t, PAGE_SIZE - offset_in_page(addr), len);
plen = min_t(size_t, rest_of_page(addr), len);

local_irq_save(flags);
if (mm_patch_enabled())
Expand Down
4 changes: 2 additions & 2 deletions arch/riscv/kernel/sbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ int sbi_debug_console_write(const char *bytes, unsigned int num_bytes)
else
base_addr = __pa(bytes);
if (PAGE_SIZE < (offset_in_page(bytes) + num_bytes))
num_bytes = PAGE_SIZE - offset_in_page(bytes);
num_bytes = rest_of_page(bytes);

if (IS_ENABLED(CONFIG_32BIT))
ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE,
Expand Down Expand Up @@ -631,7 +631,7 @@ int sbi_debug_console_read(char *bytes, unsigned int num_bytes)
else
base_addr = __pa(bytes);
if (PAGE_SIZE < (offset_in_page(bytes) + num_bytes))
num_bytes = PAGE_SIZE - offset_in_page(bytes);
num_bytes = rest_of_page(bytes);

if (IS_ENABLED(CONFIG_32BIT))
ret = sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_READ,
Expand Down
6 changes: 3 additions & 3 deletions arch/s390/kvm/gaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ int access_guest_with_key(struct kvm_vcpu *vcpu, unsigned long ga, u8 ar,
if (rc)
goto out_unlock;
for (idx = 0; idx < nr_pages; idx++) {
fragment_len = min(PAGE_SIZE - offset_in_page(gpas[idx]), len);
fragment_len = min(rest_of_page(gpas[idx]), len);
if (try_fetch_prot_override && fetch_prot_override_applies(ga, fragment_len)) {
rc = access_guest_page_gpa(vcpu->kvm, mode, gpas[idx], data, fragment_len);
} else {
Expand Down Expand Up @@ -1015,7 +1015,7 @@ int access_guest_real(struct kvm_vcpu *vcpu, unsigned long gra,

while (len && !rc) {
gpa = kvm_s390_real_to_abs(vcpu, gra);
fragment_len = min(PAGE_SIZE - offset_in_page(gpa), len);
fragment_len = min(rest_of_page(gpa), len);
rc = access_guest_page_gpa(vcpu->kvm, mode, gpa, data, fragment_len);
len -= fragment_len;
gra += fragment_len;
Expand Down Expand Up @@ -1237,7 +1237,7 @@ int check_gpa_range(struct kvm *kvm, unsigned long gpa, unsigned long length,
int rc = 0;

while (length && !rc) {
fragment_len = min(PAGE_SIZE - offset_in_page(gpa), length);
fragment_len = min(rest_of_page(gpa), length);
rc = vm_check_access_key_gpa(kvm, access_key, mode, gpa);
length -= fragment_len;
gpa += fragment_len;
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/kvm/emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ static int __do_insn_fetch_bytes(struct x86_emulate_ctxt *ctxt, int op_size)
return rc;

size = min_t(unsigned, 15UL ^ cur_size, max_size);
size = min_t(unsigned, size, PAGE_SIZE - offset_in_page(linear));
size = min_t(unsigned int, size, rest_of_page(linear));

/*
* One instruction can only straddle two pages,
Expand Down Expand Up @@ -1372,7 +1372,7 @@ static int pio_in_emulated(struct x86_emulate_ctxt *ctxt,
address_mask(ctxt, reg_read(ctxt, VCPU_REGS_RCX)) : 1;
in_page = (ctxt->eflags & X86_EFLAGS_DF) ?
offset_in_page(reg_read(ctxt, VCPU_REGS_RDI)) :
PAGE_SIZE - offset_in_page(reg_read(ctxt, VCPU_REGS_RDI));
rest_of_page(reg_read(ctxt, VCPU_REGS_RDI));
n = min3(in_page, (unsigned int)sizeof(rc->data) / size, count);
if (n == 0)
n = 1;
Expand Down
6 changes: 2 additions & 4 deletions drivers/block/null_blk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,8 +1147,7 @@ static blk_status_t copy_to_nullb(struct nullb *nullb, void *source,
sector_t sector;

while (count < n) {
temp = min3(nullb->dev->blocksize, n - count,
PAGE_SIZE - offset_in_page(pos));
temp = min3(nullb->dev->blocksize, n - count, rest_of_page(pos));
sector = pos >> SECTOR_SHIFT;

if (null_cache_active(nullb) && !is_fua)
Expand Down Expand Up @@ -1181,8 +1180,7 @@ static void copy_from_nullb(struct nullb *nullb, void *dest, loff_t pos,
sector_t sector;

while (count < n) {
temp = min3(nullb->dev->blocksize, n - count,
PAGE_SIZE - offset_in_page(pos));
temp = min3(nullb->dev->blocksize, n - count, rest_of_page(pos));
sector = pos >> SECTOR_SHIFT;

t_page = null_lookup_page(nullb, sector, false,
Expand Down
5 changes: 2 additions & 3 deletions drivers/gpu/drm/i915/gt/shmem_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ static int __shmem_rw(struct file *file, loff_t off,
unsigned long pfn;

for (pfn = off >> PAGE_SHIFT; len; pfn++) {
unsigned int this =
min_t(size_t, PAGE_SIZE - offset_in_page(off), len);
unsigned int this = min_t(size_t, rest_of_page(off), len);
struct page *page;
void *vaddr;

Expand Down Expand Up @@ -135,7 +134,7 @@ int shmem_read_to_iosys_map(struct file *file, loff_t off,

for (pfn = off >> PAGE_SHIFT; len; pfn++) {
unsigned int this =
min_t(size_t, PAGE_SIZE - offset_in_page(off), len);
min_t(size_t, rest_of_page(off), len);
struct page *page;
void *vaddr;

Expand Down
2 changes: 1 addition & 1 deletion drivers/md/dm-pcache/backing_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static inline u32 backing_dev_req_coalesced_max_len(const void *data, u32 len)

first_page = vmalloc_to_page(p);
advance:
in_page = PAGE_SIZE - offset_in_page(p);
in_page = rest_of_page(p);
to_advance = min_t(u32, in_page, len - done);

done += to_advance;
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct fbnic_tlv_msg *fbnic_tlv_msg_alloc(u16 msg_id)
**/
int fbnic_tlv_attr_put_flag(struct fbnic_tlv_msg *msg, const u16 attr_id)
{
int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg);
int attr_max_len = rest_of_page(msg) - sizeof(*msg);
struct fbnic_tlv_hdr hdr = { 0 };
struct fbnic_tlv_msg *attr;

Expand Down Expand Up @@ -94,7 +94,7 @@ int fbnic_tlv_attr_put_flag(struct fbnic_tlv_msg *msg, const u16 attr_id)
int fbnic_tlv_attr_put_value(struct fbnic_tlv_msg *msg, const u16 attr_id,
const void *value, const int len)
{
int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg);
int attr_max_len = rest_of_page(msg) - sizeof(*msg);
struct fbnic_tlv_hdr hdr = { 0 };
struct fbnic_tlv_msg *attr;

Expand Down Expand Up @@ -292,7 +292,7 @@ ssize_t fbnic_tlv_attr_get_string(struct fbnic_tlv_msg *attr, char *dst,
struct fbnic_tlv_msg *fbnic_tlv_attr_nest_start(struct fbnic_tlv_msg *msg,
u16 attr_id)
{
int attr_max_len = PAGE_SIZE - offset_in_page(msg) - sizeof(*msg);
int attr_max_len = rest_of_page(msg) - sizeof(*msg);
struct fbnic_tlv_msg *attr = &msg[le16_to_cpu(msg->hdr.len)];
struct fbnic_tlv_hdr hdr = { 0 };

Expand Down
6 changes: 2 additions & 4 deletions drivers/s390/net/qeth_core_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4087,8 +4087,7 @@ static unsigned int qeth_fill_buffer(struct qeth_qdio_out_buffer *buf,

/* map linear part into buffer element(s) */
while (length > 0) {
elem_length = min_t(unsigned int, length,
PAGE_SIZE - offset_in_page(data));
elem_length = min_t(unsigned int, length, rest_of_page(data));

buffer->element[element].addr = virt_to_dma64(data);
buffer->element[element].length = elem_length;
Expand Down Expand Up @@ -4117,8 +4116,7 @@ static unsigned int qeth_fill_buffer(struct qeth_qdio_out_buffer *buf,
data = skb_frag_address(frag);
length = skb_frag_size(frag);
while (length > 0) {
elem_length = min_t(unsigned int, length,
PAGE_SIZE - offset_in_page(data));
elem_length = min_t(unsigned int, length, rest_of_page(data));

buffer->element[element].addr = virt_to_dma64(data);
buffer->element[element].length = elem_length;
Expand Down
3 changes: 1 addition & 2 deletions drivers/spi/spi-pl022.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ static void setup_dma_scatter(struct pl022 *pl022,
* we just feed in this, else we stuff in as much
* as we can.
*/
mapbytes = min_t(int, bytesleft,
PAGE_SIZE - offset_in_page(bufp));
mapbytes = min_t(int, bytesleft, rest_of_page(bufp));

sg_set_page(sg, virt_to_page(bufp),
mapbytes, offset_in_page(bufp));
Expand Down
4 changes: 1 addition & 3 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,7 @@ static int spi_map_buf_attrs(struct spi_controller *ctlr, struct device *dev,
* the desc_len and the remaining buffer length that
* fits in a page.
*/
min = min_t(size_t, desc_len,
min_t(size_t, len,
PAGE_SIZE - offset_in_page(buf)));
min = min_t(size_t, desc_len, min_t(size_t, len, rest_of_page(buf)));
if (vmalloced_buf)
vm_page = vmalloc_to_page(buf);
else
Expand Down
3 changes: 1 addition & 2 deletions fs/ext4/verity.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
return -EFBIG;

while (count) {
size_t n = min_t(size_t, count,
PAGE_SIZE - offset_in_page(pos));
size_t n = min_t(size_t, count, rest_of_page(pos));
struct folio *folio;
void *fsdata = NULL;
int res;
Expand Down
6 changes: 2 additions & 4 deletions fs/f2fs/verity.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ static int pagecache_read(struct inode *inode, void *buf, size_t count,
loff_t pos)
{
while (count) {
size_t n = min_t(size_t, count,
PAGE_SIZE - offset_in_page(pos));
size_t n = min_t(size_t, count, rest_of_page(pos));
struct page *page;

page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT,
Expand Down Expand Up @@ -78,8 +77,7 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
return -EFBIG;

while (count) {
size_t n = min_t(size_t, count,
PAGE_SIZE - offset_in_page(pos));
size_t n = min_t(size_t, count, rest_of_page(pos));
struct folio *folio;
void *fsdata = NULL;
int res;
Expand Down
4 changes: 2 additions & 2 deletions fs/fuse/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,8 @@ static int fuse_copy_folio(struct fuse_copy_state *cs, struct folio **foliop,
unsigned int copy = count;
unsigned int bytes_copied;

if (folio_test_highmem(folio) && count > PAGE_SIZE - offset_in_page(offset))
copy = PAGE_SIZE - offset_in_page(offset);
if (folio_test_highmem(folio) && count > rest_of_page(offset))
copy = rest_of_page(offset);

bytes_copied = fuse_copy_do(cs, &buf, &copy);
kunmap_local(mapaddr);
Expand Down
2 changes: 1 addition & 1 deletion fs/iomap/buffered-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ static struct folio *__iomap_get_folio(struct iomap_iter *iter,
loff_t pos = iter->pos;

if (!mapping_large_folio_support(iter->inode->i_mapping))
len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos));
len = min_t(size_t, len, rest_of_page(pos));

if (iter->iomap.flags & IOMAP_F_FOLIO_BATCH) {
struct folio *folio = folio_batch_next(iter->fbatch);
Expand Down
2 changes: 1 addition & 1 deletion fs/nfs/pagelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static struct page *nfs_page_iter_page_get(struct nfs_page_iter_page *i)

if (i->count != req->wb_bytes) {
size_t base = i->count + req->wb_pgbase;
size_t len = PAGE_SIZE - offset_in_page(base);
size_t len = rest_of_page(base);

page = nfs_page_to_page(req, base);
nfs_page_iter_page_advance(i, len);
Expand Down
3 changes: 1 addition & 2 deletions fs/remap_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ static int vfs_dedupe_file_range_compare(struct file *src, loff_t srcoff,
while (len) {
struct folio *src_folio, *dst_folio;
void *src_addr, *dst_addr;
loff_t cmp_len = min(PAGE_SIZE - offset_in_page(srcoff),
PAGE_SIZE - offset_in_page(dstoff));
loff_t cmp_len = min(rest_of_page(srcoff), rest_of_page(dstoff));

cmp_len = min(cmp_len, len);
if (cmp_len <= 0)
Expand Down
3 changes: 1 addition & 2 deletions fs/xfs/scrub/xfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ xfile_load(
* No data stored at this offset, just zero the output
* buffer until the next page boundary.
*/
len = min_t(ssize_t, count,
PAGE_SIZE - offset_in_page(pos));
len = min_t(ssize_t, count, rest_of_page(pos));
memset(buf, 0, len);
} else {
if (filemap_check_wb_err(inode->i_mapping, 0)) {
Expand Down
2 changes: 1 addition & 1 deletion include/crypto/scatterwalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk,
* page due to the data not being aligned to the algorithm's alignmask.
*/
if (IS_ENABLED(CONFIG_HIGHMEM))
limit = PAGE_SIZE - offset_in_page(walk->offset);
limit = rest_of_page(walk->offset);
else
limit = PAGE_SIZE;

Expand Down
24 changes: 10 additions & 14 deletions include/linux/highmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,10 @@ static inline void memcpy_folio(struct folio *dst_folio, size_t dst_off,
const char *src = kmap_local_folio(src_folio, src_off);
size_t chunk = len;

if (folio_test_highmem(dst_folio) &&
chunk > PAGE_SIZE - offset_in_page(dst_off))
chunk = PAGE_SIZE - offset_in_page(dst_off);
if (folio_test_highmem(src_folio) &&
chunk > PAGE_SIZE - offset_in_page(src_off))
chunk = PAGE_SIZE - offset_in_page(src_off);
if (folio_test_highmem(dst_folio) && chunk > rest_of_page(dst_off))
chunk = rest_of_page(dst_off);
if (folio_test_highmem(src_folio) && chunk > rest_of_page(src_off))
chunk = rest_of_page(src_off);
memcpy(dst, src, chunk);
kunmap_local(src);
kunmap_local(dst);
Expand Down Expand Up @@ -580,9 +578,8 @@ static inline void memcpy_from_folio(char *to, struct folio *folio,
const char *from = kmap_local_folio(folio, offset);
size_t chunk = len;

if (folio_test_partial_kmap(folio) &&
chunk > PAGE_SIZE - offset_in_page(offset))
chunk = PAGE_SIZE - offset_in_page(offset);
if (folio_test_partial_kmap(folio) && chunk > rest_of_page(offset))
chunk = rest_of_page(offset);
memcpy(to, from, chunk);
kunmap_local(from);

Expand All @@ -608,9 +605,8 @@ static inline void memcpy_to_folio(struct folio *folio, size_t offset,
char *to = kmap_local_folio(folio, offset);
size_t chunk = len;

if (folio_test_partial_kmap(folio) &&
chunk > PAGE_SIZE - offset_in_page(offset))
chunk = PAGE_SIZE - offset_in_page(offset);
if (folio_test_partial_kmap(folio) && chunk > rest_of_page(offset))
chunk = rest_of_page(offset);
memcpy(to, from, chunk);
kunmap_local(to);

Expand Down Expand Up @@ -642,7 +638,7 @@ static inline __must_check void *folio_zero_tail(struct folio *folio,
size_t len = folio_size(folio) - offset;

if (folio_test_partial_kmap(folio)) {
size_t max = PAGE_SIZE - offset_in_page(offset);
size_t max = rest_of_page(offset);

while (len > max) {
memset(kaddr, 0, max);
Expand Down Expand Up @@ -680,7 +676,7 @@ static inline void folio_fill_tail(struct folio *folio, size_t offset,
VM_BUG_ON(offset + len > folio_size(folio));

if (folio_test_partial_kmap(folio)) {
size_t max = PAGE_SIZE - offset_in_page(offset);
size_t max = rest_of_page(offset);

while (len > max) {
memcpy(to, from, max);
Expand Down
2 changes: 1 addition & 1 deletion include/linux/iomap.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static inline void *iomap_inline_data(const struct iomap *iomap, loff_t pos)
*/
static inline bool iomap_inline_data_valid(const struct iomap *iomap)
{
return iomap->length <= PAGE_SIZE - offset_in_page(iomap->inline_data);
return iomap->length <= rest_of_page(iomap->inline_data);
}

/*
Expand Down
3 changes: 1 addition & 2 deletions include/linux/iov_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ size_t iterate_xarray(struct iov_iter *iter, size_t len, void *priv, void *priv2
while (flen) {
void *base = kmap_local_folio(folio, offset);

part = min_t(size_t, flen,
PAGE_SIZE - offset_in_page(offset));
part = min_t(size_t, flen, rest_of_page(offset));
remain = step(base, progress, part, priv, priv2);
kunmap_local(base);

Expand Down
2 changes: 2 additions & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2793,6 +2793,8 @@ extern void pagefault_out_of_memory(void);
#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
#define offset_in_folio(folio, p) ((unsigned long)(p) & (folio_size(folio) - 1))

#define rest_of_page(p) (PAGE_SIZE - offset_in_page(p))

/*
* Parameter block passed down to zap_pte_range in exceptional cases.
*/
Expand Down
Loading