Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'ubifs-for-linus-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs

Pull UBI and UBIFS updates from Richard Weinberger:
"UBI:
- New interface to dump detailed erase counters
- Fixes around wear-leveling

UBIFS:
- Minor cleanups
- Fix for TNC dumping code"

* tag 'ubifs-for-linus-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs:
ubi: ubi_get_ec_info: Fix compiling error 'cast specifies array type'
ubi: Implement ioctl for detailed erase counters
ubi: Expose interface for detailed erase counters
ubifs: skip dumping tnc tree when zroot is null
ubi: Revert "ubi: wl: Close down wear-leveling before nand is suspended"
ubifs: ubifs_dump_leb: remove return from end of void function
ubifs: dump_lpt_leb: remove return at end of void function
ubi: Add a check for ubi_num

+117 -35
+1 -1
drivers/mtd/ubi/build.c
··· 1537 1537 if (token) { 1538 1538 int err = kstrtoint(token, 10, &p->ubi_num); 1539 1539 1540 - if (err) { 1540 + if (err || p->ubi_num < UBI_DEV_NUM_AUTO) { 1541 1541 pr_err("UBI error: bad value for ubi_num parameter: %s\n", 1542 1542 token); 1543 1543 return -EINVAL;
+70
drivers/mtd/ubi/cdev.c
··· 828 828 return err; 829 829 } 830 830 831 + static int ubi_get_ec_info(struct ubi_device *ubi, struct ubi_ecinfo_req __user *ureq) 832 + { 833 + struct ubi_ecinfo_req req; 834 + struct ubi_wl_entry *wl; 835 + int read_cnt; 836 + int peb; 837 + int end_peb; 838 + 839 + /* Copy the input arguments */ 840 + if (copy_from_user(&req, ureq, sizeof(struct ubi_ecinfo_req))) 841 + return -EFAULT; 842 + 843 + /* Check input arguments */ 844 + if (req.length <= 0 || req.start < 0 || req.start >= ubi->peb_count) 845 + return -EINVAL; 846 + 847 + if (check_add_overflow(req.start, req.length, &end_peb)) 848 + return -EINVAL; 849 + 850 + if (end_peb > ubi->peb_count) 851 + end_peb = ubi->peb_count; 852 + 853 + /* Check access rights before filling erase_counters array */ 854 + if (!access_ok((void __user *)ureq->erase_counters, 855 + (end_peb-req.start) * sizeof(int32_t))) 856 + return -EFAULT; 857 + 858 + /* Fill erase counter array */ 859 + read_cnt = 0; 860 + for (peb = req.start; peb < end_peb; read_cnt++, peb++) { 861 + int ec; 862 + 863 + if (ubi_io_is_bad(ubi, peb)) { 864 + if (__put_user(UBI_UNKNOWN, ureq->erase_counters+read_cnt)) 865 + return -EFAULT; 866 + 867 + continue; 868 + } 869 + 870 + spin_lock(&ubi->wl_lock); 871 + 872 + wl = ubi->lookuptbl[peb]; 873 + if (wl) 874 + ec = wl->ec; 875 + else 876 + ec = UBI_UNKNOWN; 877 + 878 + spin_unlock(&ubi->wl_lock); 879 + 880 + if (__put_user(ec, ureq->erase_counters+read_cnt)) 881 + return -EFAULT; 882 + 883 + } 884 + 885 + /* Return actual read length */ 886 + req.read_length = read_cnt; 887 + 888 + /* Copy everything except erase counter array */ 889 + if (copy_to_user(ureq, &req, sizeof(struct ubi_ecinfo_req))) 890 + return -EFAULT; 891 + 892 + return 0; 893 + } 894 + 831 895 static long ubi_cdev_ioctl(struct file *file, unsigned int cmd, 832 896 unsigned long arg) 833 897 { ··· 1052 988 } 1053 989 1054 990 err = ubi_bitflip_check(ubi, pnum, 1); 991 + break; 992 + } 993 + 994 + case UBI_IOCECNFO: 995 + { 996 + err = ubi_get_ec_info(ubi, argp); 1055 997 break; 1056 998 } 1057 999
-2
drivers/mtd/ubi/ubi.h
··· 549 549 * @peb_buf: a buffer of PEB size used for different purposes 550 550 * @buf_mutex: protects @peb_buf 551 551 * @ckvol_mutex: serializes static volume checking when opening 552 - * @wl_reboot_notifier: close all wear-leveling work before reboot 553 552 * 554 553 * @dbg: debugging information for this UBI device 555 554 */ ··· 651 652 void *peb_buf; 652 653 struct mutex buf_mutex; 653 654 struct mutex ckvol_mutex; 654 - struct notifier_block wl_reboot_notifier; 655 655 656 656 struct ubi_debug_info dbg; 657 657 };
-21
drivers/mtd/ubi/wl.c
··· 89 89 #include <linux/crc32.h> 90 90 #include <linux/freezer.h> 91 91 #include <linux/kthread.h> 92 - #include <linux/reboot.h> 93 92 #include "ubi.h" 94 93 #include "wl.h" 95 94 ··· 127 128 struct ubi_wl_entry *e, struct rb_root *root); 128 129 static int self_check_in_pq(const struct ubi_device *ubi, 129 130 struct ubi_wl_entry *e); 130 - static int ubi_wl_reboot_notifier(struct notifier_block *n, 131 - unsigned long state, void *cmd); 132 131 133 132 /** 134 133 * wl_tree_add - add a wear-leveling entry to a WL RB-tree. ··· 1950 1953 if (!ubi->ro_mode && !ubi->fm_disabled) 1951 1954 ubi_ensure_anchor_pebs(ubi); 1952 1955 #endif 1953 - 1954 - if (!ubi->wl_reboot_notifier.notifier_call) { 1955 - ubi->wl_reboot_notifier.notifier_call = ubi_wl_reboot_notifier; 1956 - ubi->wl_reboot_notifier.priority = 1; /* Higher than MTD */ 1957 - register_reboot_notifier(&ubi->wl_reboot_notifier); 1958 - } 1959 - 1960 1956 return 0; 1961 1957 1962 1958 out_free: ··· 1993 2003 tree_destroy(ubi, &ubi->free); 1994 2004 tree_destroy(ubi, &ubi->scrub); 1995 2005 kfree(ubi->lookuptbl); 1996 - } 1997 - 1998 - static int ubi_wl_reboot_notifier(struct notifier_block *n, 1999 - unsigned long state, void *cmd) 2000 - { 2001 - struct ubi_device *ubi; 2002 - 2003 - ubi = container_of(n, struct ubi_device, wl_reboot_notifier); 2004 - ubi_wl_close(ubi); 2005 - 2006 - return NOTIFY_DONE; 2007 2006 } 2008 2007 2009 2008 /**
+13 -10
fs/ubifs/debug.c
··· 863 863 864 864 out: 865 865 vfree(buf); 866 - return; 867 866 } 868 867 869 868 void ubifs_dump_znode(const struct ubifs_info *c, ··· 945 946 946 947 pr_err("\n"); 947 948 pr_err("(pid %d) start dumping TNC tree\n", current->pid); 948 - znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, NULL); 949 - level = znode->level; 950 - pr_err("== Level %d ==\n", level); 951 - while (znode) { 952 - if (level != znode->level) { 953 - level = znode->level; 954 - pr_err("== Level %d ==\n", level); 949 + if (c->zroot.znode) { 950 + znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, NULL); 951 + level = znode->level; 952 + pr_err("== Level %d ==\n", level); 953 + while (znode) { 954 + if (level != znode->level) { 955 + level = znode->level; 956 + pr_err("== Level %d ==\n", level); 957 + } 958 + ubifs_dump_znode(c, znode); 959 + znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, znode); 955 960 } 956 - ubifs_dump_znode(c, znode); 957 - znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, znode); 961 + } else { 962 + pr_err("empty TNC tree in memory\n"); 958 963 } 959 964 pr_err("(pid %d) finish dumping TNC tree\n", current->pid); 960 965 }
-1
fs/ubifs/lpt_commit.c
··· 1932 1932 pr_err("(pid %d) finish dumping LEB %d\n", current->pid, lnum); 1933 1933 out: 1934 1934 vfree(buf); 1935 - return; 1936 1935 } 1937 1936 1938 1937 /**
+33
include/uapi/mtd/ubi-user.h
··· 175 175 #define UBI_IOCRPEB _IOW(UBI_IOC_MAGIC, 4, __s32) 176 176 /* Force scrubbing on the specified PEB */ 177 177 #define UBI_IOCSPEB _IOW(UBI_IOC_MAGIC, 5, __s32) 178 + /* Read detailed device erase counter information */ 179 + #define UBI_IOCECNFO _IOWR(UBI_IOC_MAGIC, 6, struct ubi_ecinfo_req) 178 180 179 181 /* ioctl commands of the UBI control character device */ 180 182 ··· 413 411 char name[UBI_MAX_VOLUME_NAME + 1]; 414 412 } ents[UBI_MAX_RNVOL]; 415 413 } __packed; 414 + 415 + /** 416 + * struct ubi_ecinfo_req - a data structure used for requesting and receiving 417 + * erase block counter information from a UBI device. 418 + * 419 + * @start: index of first physical erase block to read (in) 420 + * @length: number of erase counters to read (in) 421 + * @read_length: number of erase counters that was actually read (out) 422 + * @padding: reserved for future, not used, has to be zeroed 423 + * @erase_counters: array of erase counter values (out) 424 + * 425 + * This structure is used to retrieve erase counter information for a specified 426 + * range of PEBs on a UBI device. 427 + * Erase counters are read from @start and attempts to read @length number of 428 + * erase counters. 429 + * The retrieved values are stored in the @erase_counters array. It is the 430 + * responsibility of the caller to allocate enough memory for storing @length 431 + * elements in the @erase_counters array. 432 + * If a block is bad or if the erase counter is unknown the corresponding value 433 + * in the array will be set to -1. 434 + * The @read_length field will indicate the number of erase counters actually 435 + * read. Typically @read_length will be limited due to memory or the number of 436 + * PEBs on the UBI device. 437 + */ 438 + struct ubi_ecinfo_req { 439 + __s32 start; 440 + __s32 length; 441 + __s32 read_length; 442 + __s8 padding[16]; 443 + __s32 erase_counters[]; 444 + } __packed; 416 445 417 446 /** 418 447 * struct ubi_leb_change_req - a data structure used in atomic LEB change