@@ -828,22 +828,22 @@ static inline unsigned long dir_pages(struct inode *inode)
* @page: the page to check
* @inode: the inode to check the page against
*
- * Returns the number of bytes in the page up to EOF,
+ * Return: The number of bytes in the page up to EOF,
* or -EFAULT if the page was truncated.
*/
-static inline int page_mkwrite_check_truncate(struct page *page,
+static inline ssize_t page_mkwrite_check_truncate(struct page *page,
struct inode *inode)
{
loff_t size = i_size_read(inode);
pgoff_t index = size >> PAGE_SHIFT;
- int offset = offset_in_page(size);
+ unsigned long offset = offset_in_thp(page, size);
if (page->mapping != inode->i_mapping)
return -EFAULT;
/* page is wholly inside EOF */
- if (page->index < index)
- return PAGE_SIZE;
+ if (page->index + hpage_nr_pages(page) - 1 < index)
+ return thp_size(page);
/* page is wholly past EOF */
if (page->index > index || !offset)
return -EFAULT;