From e0d5fa9ae40bedfce4a7b7b2f6ec22096650ffdf Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 19 Oct 2026 19:24:03 -1000 Subject: [PATCH] ubi: use put_user() when filling the erase counter array ubi_get_ec_info() checks the user's erase_counters array with access_ok() and then fills it one entry at a time with __put_user(), taking the wear-leveling lock for each entry in between. Each of those accesses enables and disables user access on its own, so the up-front check saves nothing. Use put_user(). The access_ok() stays, so a bad array still fails before anything is written. This is part of getting rid of __get_user() and __put_user() entirely. Signed-off-by: Linus Torvalds --- drivers/mtd/ubi/cdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 54acd8394d67..8dd005ef376b 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c @@ -861,7 +861,7 @@ static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user int ec; if (ubi_io_is_bad(ubi, peb)) { - if (__put_user(UBI_UNKNOWN, ureq->erase_counters+read_cnt)) + if (put_user(UBI_UNKNOWN, ureq->erase_counters+read_cnt)) return -EFAULT; continue; @@ -877,7 +877,7 @@ static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user spin_unlock(&ubi->wl_lock); - if (__put_user(ec, ureq->erase_counters+read_cnt)) + if (put_user(ec, ureq->erase_counters+read_cnt)) return -EFAULT; }