]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
libfs: simple_transaction_get(): replace get_zeroed_page() with kzalloc()
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Sat, 23 May 2026 17:54:20 +0000 (20:54 +0300)
committerChristian Brauner <brauner@kernel.org>
Wed, 27 May 2026 13:12:23 +0000 (15:12 +0200)
simple_transaction_get() allocates memory with get_zeroed_page(). That
memory is used as a file local buffer that is accessed using
copy_from_user() and simple_read_from_buffer().

kmalloc() is a better API for such use and it also provides better
scalability and more debugging possibilities.

Replace use of get_zeroed_page() with kzalloc().

Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Link: https://patch.msgid.link/20260523-b4-fs-v1-8-275e36a83f0e@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
fs/libfs.c

index 1bbea5e7bae379256d0b6a26f15be022ae6da394..80a330c8296f11502d0a3734c744be9528415730 100644 (file)
@@ -1258,7 +1258,7 @@ char *simple_transaction_get(struct file *file, const char __user *buf, size_t s
        if (size > SIMPLE_TRANSACTION_LIMIT - 1)
                return ERR_PTR(-EFBIG);
 
-       ar = (struct simple_transaction_argresp *)get_zeroed_page(GFP_KERNEL);
+       ar = kzalloc(PAGE_SIZE, GFP_KERNEL);
        if (!ar)
                return ERR_PTR(-ENOMEM);
 
@@ -1267,7 +1267,7 @@ char *simple_transaction_get(struct file *file, const char __user *buf, size_t s
        /* only one write allowed per open */
        if (file->private_data) {
                spin_unlock(&simple_transaction_lock);
-               free_page((unsigned long)ar);
+               kfree(ar);
                return ERR_PTR(-EBUSY);
        }
 
@@ -1294,7 +1294,7 @@ EXPORT_SYMBOL(simple_transaction_read);
 
 int simple_transaction_release(struct inode *inode, struct file *file)
 {
-       free_page((unsigned long)file->private_data);
+       kfree(file->private_data);
        return 0;
 }
 EXPORT_SYMBOL(simple_transaction_release);