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

Pull UBI and UBIFS updates from Richard Weinberger:
"UBI:
- Use bitmap API to allocate bitmaps
- New attach mode, disable_fm, to attach without fastmap
- Fixes for various typos in comments

UBIFS:
- Fix for a deadlock when setting xattrs for encrypted file
- Fix for an assertion failures when truncating encrypted files
- Fixes for various typos in comments"

* tag 'for-linus-6.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs:
ubi: fastmap: Add fastmap control support for 'UBI_IOCATT' ioctl
ubi: fastmap: Use the bitmap API to allocate bitmaps
ubifs: Fix AA deadlock when setting xattr for encrypted file
ubifs: Fix UBIFS ro fail due to truncate in the encrypted directory
mtd: ubi: drop unexpected word 'a' in comments
ubi: block: Fix typos in comments
ubi: fastmap: Fix typo in comments
ubi: Fix repeated words in comments
ubi: ubi-media.h: Fix comment typo
ubi: block: Remove in vain semicolon
ubifs: Fix ubifs_check_dir_empty() kernel-doc comment

+84 -53
+2 -2
drivers/mtd/ubi/block.c
··· 409 409 ret = blk_mq_alloc_tag_set(&dev->tag_set); 410 410 if (ret) { 411 411 dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed"); 412 - goto out_free_dev;; 412 + goto out_free_dev; 413 413 } 414 414 415 415 ··· 441 441 442 442 /* 443 443 * Create one workqueue per volume (per registered block device). 444 - * Rembember workqueues are cheap, they're not threads. 444 + * Remember workqueues are cheap, they're not threads. 445 445 */ 446 446 dev->wq = alloc_workqueue("%s", 0, 0, gd->disk_name); 447 447 if (!dev->wq) {
+10 -4
drivers/mtd/ubi/build.c
··· 807 807 * @ubi_num: number to assign to the new UBI device 808 808 * @vid_hdr_offset: VID header offset 809 809 * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs 810 + * @disable_fm: whether disable fastmap 810 811 * 811 812 * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number 812 813 * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in ··· 815 814 * automatically. Returns the new UBI device number in case of success and a 816 815 * negative error code in case of failure. 817 816 * 817 + * If @disable_fm is true, ubi doesn't create new fastmap even the module param 818 + * 'fm_autoconvert' is set, and existed old fastmap will be destroyed after 819 + * doing full scanning. 820 + * 818 821 * Note, the invocations of this function has to be serialized by the 819 822 * @ubi_devices_mutex. 820 823 */ 821 824 int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, 822 - int vid_hdr_offset, int max_beb_per1024) 825 + int vid_hdr_offset, int max_beb_per1024, bool disable_fm) 823 826 { 824 827 struct ubi_device *ubi; 825 828 int i, err; ··· 926 921 UBI_FM_MIN_POOL_SIZE); 927 922 928 923 ubi->fm_wl_pool.max_size = ubi->fm_pool.max_size / 2; 929 - ubi->fm_disabled = !fm_autoconvert; 924 + ubi->fm_disabled = (!fm_autoconvert || disable_fm) ? 1 : 0; 930 925 if (fm_debug) 931 926 ubi_enable_dbg_chk_fastmap(ubi); 932 927 ··· 967 962 if (!ubi->fm_buf) 968 963 goto out_free; 969 964 #endif 970 - err = ubi_attach(ubi, 0); 965 + err = ubi_attach(ubi, disable_fm ? 1 : 0); 971 966 if (err) { 972 967 ubi_err(ubi, "failed to attach mtd%d, error %d", 973 968 mtd->index, err); ··· 1247 1242 1248 1243 mutex_lock(&ubi_devices_mutex); 1249 1244 err = ubi_attach_mtd_dev(mtd, p->ubi_num, 1250 - p->vid_hdr_offs, p->max_beb_per1024); 1245 + p->vid_hdr_offs, p->max_beb_per1024, 1246 + false); 1251 1247 mutex_unlock(&ubi_devices_mutex); 1252 1248 if (err < 0) { 1253 1249 pr_err("UBI error: cannot attach mtd%d\n",
+2 -2
drivers/mtd/ubi/cdev.c
··· 672 672 * @req: volumes re-name request 673 673 * 674 674 * This is a helper function for the volume re-name IOCTL which validates the 675 - * the request, opens the volume and calls corresponding volumes management 675 + * request, opens the volume and calls corresponding volumes management 676 676 * function. Returns zero in case of success and a negative error code in case 677 677 * of failure. 678 678 */ ··· 1041 1041 */ 1042 1042 mutex_lock(&ubi_devices_mutex); 1043 1043 err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset, 1044 - req.max_beb_per1024); 1044 + req.max_beb_per1024, !!req.disable_fm); 1045 1045 mutex_unlock(&ubi_devices_mutex); 1046 1046 if (err < 0) 1047 1047 put_mtd_device(mtd);
+1 -1
drivers/mtd/ubi/eba.c
··· 377 377 * 378 378 * This function locks a logical eraseblock for writing if there is no 379 379 * contention and does nothing if there is contention. Returns %0 in case of 380 - * success, %1 in case of contention, and and a negative error code in case of 380 + * success, %1 in case of contention, and a negative error code in case of 381 381 * failure. 382 382 */ 383 383 static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
+4 -6
drivers/mtd/ubi/fastmap.c
··· 20 20 if (!ubi_dbg_chk_fastmap(ubi)) 21 21 return NULL; 22 22 23 - ret = kcalloc(BITS_TO_LONGS(ubi->peb_count), sizeof(unsigned long), 24 - GFP_KERNEL); 23 + ret = bitmap_zalloc(ubi->peb_count, GFP_KERNEL); 25 24 if (!ret) 26 25 return ERR_PTR(-ENOMEM); 27 26 ··· 33 34 */ 34 35 static inline void free_seen(unsigned long *seen) 35 36 { 36 - kfree(seen); 37 + bitmap_free(seen); 37 38 } 38 39 39 40 /** ··· 1107 1108 if (!ubi->fast_attach) 1108 1109 return 0; 1109 1110 1110 - vol->checkmap = kcalloc(BITS_TO_LONGS(leb_count), sizeof(unsigned long), 1111 - GFP_KERNEL); 1111 + vol->checkmap = bitmap_zalloc(leb_count, GFP_KERNEL); 1112 1112 if (!vol->checkmap) 1113 1113 return -ENOMEM; 1114 1114 ··· 1116 1118 1117 1119 void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol) 1118 1120 { 1119 - kfree(vol->checkmap); 1121 + bitmap_free(vol->checkmap); 1120 1122 } 1121 1123 1122 1124 /**
+1 -1
drivers/mtd/ubi/io.c
··· 1147 1147 * @ubi: UBI device description object 1148 1148 * @pnum: the physical eraseblock number to check 1149 1149 * 1150 - * This function returns zero if the erase counter header is all right and and 1150 + * This function returns zero if the erase counter header is all right and 1151 1151 * a negative error code if not or if an error occurred. 1152 1152 */ 1153 1153 static int self_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
+1 -1
drivers/mtd/ubi/ubi-media.h
··· 131 131 * is changed radically. This field is duplicated in the volume identifier 132 132 * header. 133 133 * 134 - * The @vid_hdr_offset and @data_offset fields contain the offset of the the 134 + * The @vid_hdr_offset and @data_offset fields contain the offset of the 135 135 * volume identifier header and user data, relative to the beginning of the 136 136 * physical eraseblock. These values have to be the same for all physical 137 137 * eraseblocks.
+5 -4
drivers/mtd/ubi/ubi.h
··· 86 86 * Error codes returned by the I/O sub-system. 87 87 * 88 88 * UBI_IO_FF: the read region of flash contains only 0xFFs 89 - * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also also there was a data 89 + * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also there was a data 90 90 * integrity error reported by the MTD driver 91 91 * (uncorrectable ECC error in case of NAND) 92 92 * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC) ··· 281 281 282 282 /** 283 283 * struct ubi_volume - UBI volume description data structure. 284 - * @dev: device object to make use of the the Linux device model 284 + * @dev: device object to make use of the Linux device model 285 285 * @cdev: character device object to create character device 286 286 * @ubi: reference to the UBI device description object 287 287 * @vol_id: volume ID ··· 439 439 440 440 /** 441 441 * struct ubi_device - UBI device description structure 442 - * @dev: UBI device object to use the the Linux device model 442 + * @dev: UBI device object to use the Linux device model 443 443 * @cdev: character device object to create character device 444 444 * @ubi_num: UBI device number 445 445 * @ubi_name: UBI device name ··· 937 937 938 938 /* build.c */ 939 939 int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, 940 - int vid_hdr_offset, int max_beb_per1024); 940 + int vid_hdr_offset, int max_beb_per1024, 941 + bool disable_fm); 941 942 int ubi_detach_mtd_dev(int ubi_num, int anyway); 942 943 struct ubi_device *ubi_get_device(int ubi_num); 943 944 void ubi_put_device(struct ubi_device *ubi);
+2 -2
drivers/mtd/ubi/vmt.c
··· 623 623 * @ubi: UBI device description object 624 624 * @vol_id: volume ID 625 625 * 626 - * Returns zero if volume is all right and a a negative error code if not. 626 + * Returns zero if volume is all right and a negative error code if not. 627 627 */ 628 628 static int self_check_volume(struct ubi_device *ubi, int vol_id) 629 629 { ··· 776 776 * self_check_volumes - check information about all volumes. 777 777 * @ubi: UBI device description object 778 778 * 779 - * Returns zero if volumes are all right and a a negative error code if not. 779 + * Returns zero if volumes are all right and a negative error code if not. 780 780 */ 781 781 static int self_check_volumes(struct ubi_device *ubi) 782 782 {
+4 -4
drivers/mtd/ubi/wl.c
··· 376 376 * refill_wl_user_pool(). 377 377 * @ubi: UBI device description object 378 378 * 379 - * This function returns a a wear leveling entry in case of success and 379 + * This function returns a wear leveling entry in case of success and 380 380 * NULL in case of failure. 381 381 */ 382 382 static struct ubi_wl_entry *wl_get_wle(struct ubi_device *ubi) ··· 429 429 /** 430 430 * sync_erase - synchronously erase a physical eraseblock. 431 431 * @ubi: UBI device description object 432 - * @e: the the physical eraseblock to erase 432 + * @e: the physical eraseblock to erase 433 433 * @torture: if the physical eraseblock has to be tortured 434 434 * 435 435 * This function returns zero in case of success and a negative error code in ··· 1016 1016 1017 1017 /* 1018 1018 * If the ubi->scrub tree is not empty, scrubbing is needed, and the 1019 - * the WL worker has to be scheduled anyway. 1019 + * WL worker has to be scheduled anyway. 1020 1020 */ 1021 1021 if (!ubi->scrub.rb_node) { 1022 1022 #ifdef CONFIG_MTD_UBI_FASTMAP ··· 1464 1464 * ubi_bitflip_check - Check an eraseblock for bitflips and scrub it if needed. 1465 1465 * @ubi: UBI device description object 1466 1466 * @pnum: the physical eraseblock to schedule 1467 - * @force: dont't read the block, assume bitflips happened and take action. 1467 + * @force: don't read the block, assume bitflips happened and take action. 1468 1468 * 1469 1469 * This function reads the given eraseblock and checks if bitflips occured. 1470 1470 * In case of bitflips, the eraseblock is scheduled for scrubbing.
+11
fs/ubifs/crypto.c
··· 24 24 return ubifs_check_dir_empty(inode) == 0; 25 25 } 26 26 27 + /** 28 + * ubifs_encrypt - Encrypt data. 29 + * @inode: inode which refers to the data node 30 + * @dn: data node to encrypt 31 + * @in_len: length of data to be compressed 32 + * @out_len: allocated memory size for the data area of @dn 33 + * @block: logical block number of the block 34 + * 35 + * This function encrypt a possibly-compressed data in the data node. 36 + * The encrypted data length will store in @out_len. 37 + */ 27 38 int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn, 28 39 unsigned int in_len, unsigned int *out_len, int block) 29 40 {
+15 -12
fs/ubifs/dir.c
··· 68 68 * @c: UBIFS file-system description object 69 69 * @dir: parent directory inode 70 70 * @mode: inode mode flags 71 + * @is_xattr: whether the inode is xattr inode 71 72 * 72 73 * This function finds an unused inode number, allocates new inode and 73 74 * initializes it. Returns new inode in case of success and an error code in 74 75 * case of failure. 75 76 */ 76 77 struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, 77 - umode_t mode) 78 + umode_t mode, bool is_xattr) 78 79 { 79 80 int err; 80 81 struct inode *inode; ··· 100 99 current_time(inode); 101 100 inode->i_mapping->nrpages = 0; 102 101 103 - err = fscrypt_prepare_new_inode(dir, inode, &encrypted); 104 - if (err) { 105 - ubifs_err(c, "fscrypt_prepare_new_inode failed: %i", err); 106 - goto out_iput; 102 + if (!is_xattr) { 103 + err = fscrypt_prepare_new_inode(dir, inode, &encrypted); 104 + if (err) { 105 + ubifs_err(c, "fscrypt_prepare_new_inode failed: %i", err); 106 + goto out_iput; 107 + } 107 108 } 108 109 109 110 switch (mode & S_IFMT) { ··· 312 309 313 310 sz_change = CALC_DENT_SIZE(fname_len(&nm)); 314 311 315 - inode = ubifs_new_inode(c, dir, mode); 312 + inode = ubifs_new_inode(c, dir, mode, false); 316 313 if (IS_ERR(inode)) { 317 314 err = PTR_ERR(inode); 318 315 goto out_fname; ··· 373 370 if (err) 374 371 return ERR_PTR(err); 375 372 376 - inode = ubifs_new_inode(c, dir, mode); 373 + inode = ubifs_new_inode(c, dir, mode, false); 377 374 if (IS_ERR(inode)) { 378 375 err = PTR_ERR(inode); 379 376 goto out_free; ··· 466 463 return err; 467 464 } 468 465 469 - inode = ubifs_new_inode(c, dir, mode); 466 + inode = ubifs_new_inode(c, dir, mode, false); 470 467 if (IS_ERR(inode)) { 471 468 err = PTR_ERR(inode); 472 469 goto out_budg; ··· 876 873 } 877 874 878 875 /** 879 - * check_dir_empty - check if a directory is empty or not. 876 + * ubifs_check_dir_empty - check if a directory is empty or not. 880 877 * @dir: VFS inode object of the directory to check 881 878 * 882 879 * This function checks if directory @dir is empty. Returns zero if the ··· 1008 1005 1009 1006 sz_change = CALC_DENT_SIZE(fname_len(&nm)); 1010 1007 1011 - inode = ubifs_new_inode(c, dir, S_IFDIR | mode); 1008 + inode = ubifs_new_inode(c, dir, S_IFDIR | mode, false); 1012 1009 if (IS_ERR(inode)) { 1013 1010 err = PTR_ERR(inode); 1014 1011 goto out_fname; ··· 1095 1092 1096 1093 sz_change = CALC_DENT_SIZE(fname_len(&nm)); 1097 1094 1098 - inode = ubifs_new_inode(c, dir, mode); 1095 + inode = ubifs_new_inode(c, dir, mode, false); 1099 1096 if (IS_ERR(inode)) { 1100 1097 kfree(dev); 1101 1098 err = PTR_ERR(inode); ··· 1177 1174 1178 1175 sz_change = CALC_DENT_SIZE(fname_len(&nm)); 1179 1176 1180 - inode = ubifs_new_inode(c, dir, S_IFLNK | S_IRWXUGO); 1177 + inode = ubifs_new_inode(c, dir, S_IFLNK | S_IRWXUGO, false); 1181 1178 if (IS_ERR(inode)) { 1182 1179 err = PTR_ERR(inode); 1183 1180 goto out_fname;
+17 -11
fs/ubifs/journal.c
··· 1472 1472 * @block: data block number 1473 1473 * @dn: data node to re-compress 1474 1474 * @new_len: new length 1475 + * @dn_size: size of the data node @dn in memory 1475 1476 * 1476 1477 * This function is used when an inode is truncated and the last data node of 1477 1478 * the inode has to be re-compressed/encrypted and re-written. 1478 1479 */ 1479 1480 static int truncate_data_node(const struct ubifs_info *c, const struct inode *inode, 1480 1481 unsigned int block, struct ubifs_data_node *dn, 1481 - int *new_len) 1482 + int *new_len, int dn_size) 1482 1483 { 1483 1484 void *buf; 1484 - int err, dlen, compr_type, out_len, old_dlen; 1485 + int err, dlen, compr_type, out_len, data_size; 1485 1486 1486 1487 out_len = le32_to_cpu(dn->size); 1487 1488 buf = kmalloc_array(out_len, WORST_COMPR_FACTOR, GFP_NOFS); 1488 1489 if (!buf) 1489 1490 return -ENOMEM; 1490 1491 1491 - dlen = old_dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; 1492 + dlen = le32_to_cpu(dn->ch.len) - UBIFS_DATA_NODE_SZ; 1493 + data_size = dn_size - UBIFS_DATA_NODE_SZ; 1492 1494 compr_type = le16_to_cpu(dn->compr_type); 1493 1495 1494 1496 if (IS_ENCRYPTED(inode)) { ··· 1510 1508 } 1511 1509 1512 1510 if (IS_ENCRYPTED(inode)) { 1513 - err = ubifs_encrypt(inode, dn, out_len, &old_dlen, block); 1511 + err = ubifs_encrypt(inode, dn, out_len, &data_size, block); 1514 1512 if (err) 1515 1513 goto out; 1516 1514 1517 - out_len = old_dlen; 1515 + out_len = data_size; 1518 1516 } else { 1519 1517 dn->compr_size = 0; 1520 1518 } ··· 1552 1550 struct ubifs_trun_node *trun; 1553 1551 struct ubifs_data_node *dn; 1554 1552 int err, dlen, len, lnum, offs, bit, sz, sync = IS_SYNC(inode); 1553 + int dn_size; 1555 1554 struct ubifs_inode *ui = ubifs_inode(inode); 1556 1555 ino_t inum = inode->i_ino; 1557 1556 unsigned int blk; ··· 1565 1562 ubifs_assert(c, S_ISREG(inode->i_mode)); 1566 1563 ubifs_assert(c, mutex_is_locked(&ui->ui_mutex)); 1567 1564 1568 - sz = UBIFS_TRUN_NODE_SZ + UBIFS_INO_NODE_SZ + 1569 - UBIFS_MAX_DATA_NODE_SZ * WORST_COMPR_FACTOR; 1565 + dn_size = COMPRESSED_DATA_NODE_BUF_SZ; 1570 1566 1571 - sz += ubifs_auth_node_sz(c); 1567 + if (IS_ENCRYPTED(inode)) 1568 + dn_size += UBIFS_CIPHER_BLOCK_SIZE; 1569 + 1570 + sz = UBIFS_TRUN_NODE_SZ + UBIFS_INO_NODE_SZ + 1571 + dn_size + ubifs_auth_node_sz(c); 1572 1572 1573 1573 ino = kmalloc(sz, GFP_NOFS); 1574 1574 if (!ino) ··· 1602 1596 if (dn_len <= 0 || dn_len > UBIFS_BLOCK_SIZE) { 1603 1597 ubifs_err(c, "bad data node (block %u, inode %lu)", 1604 1598 blk, inode->i_ino); 1605 - ubifs_dump_node(c, dn, sz - UBIFS_INO_NODE_SZ - 1606 - UBIFS_TRUN_NODE_SZ); 1599 + ubifs_dump_node(c, dn, dn_size); 1607 1600 goto out_free; 1608 1601 } 1609 1602 1610 1603 if (dn_len <= dlen) 1611 1604 dlen = 0; /* Nothing to do */ 1612 1605 else { 1613 - err = truncate_data_node(c, inode, blk, dn, &dlen); 1606 + err = truncate_data_node(c, inode, blk, dn, 1607 + &dlen, dn_size); 1614 1608 if (err) 1615 1609 goto out_free; 1616 1610 }
+1 -1
fs/ubifs/ubifs.h
··· 2026 2026 2027 2027 /* dir.c */ 2028 2028 struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir, 2029 - umode_t mode); 2029 + umode_t mode, bool is_xattr); 2030 2030 int ubifs_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, 2031 2031 u32 request_mask, unsigned int flags); 2032 2032 int ubifs_check_dir_empty(struct inode *dir);
+1 -1
fs/ubifs/xattr.c
··· 110 110 if (err) 111 111 return err; 112 112 113 - inode = ubifs_new_inode(c, host, S_IFREG | S_IRWXUGO); 113 + inode = ubifs_new_inode(c, host, S_IFREG | S_IRWXUGO, true); 114 114 if (IS_ERR(inode)) { 115 115 err = PTR_ERR(inode); 116 116 goto out_budg;
+7 -1
include/uapi/mtd/ubi-user.h
··· 247 247 * @vid_hdr_offset: VID header offset (use defaults if %0) 248 248 * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs 249 249 * @padding: reserved for future, not used, has to be zeroed 250 + * @disable_fm: whether disable fastmap 250 251 * 251 252 * This data structure is used to specify MTD device UBI has to attach and the 252 253 * parameters it has to use. The number which should be assigned to the new UBI ··· 282 281 * eraseblocks for new bad eraseblocks, but attempts to use available 283 282 * eraseblocks (if any). The accepted range is 0-768. If 0 is given, the 284 283 * default kernel value of %CONFIG_MTD_UBI_BEB_LIMIT will be used. 284 + * 285 + * If @disable_fm is not zero, ubi doesn't create new fastmap even the module 286 + * param 'fm_autoconvert' is set, and existed old fastmap will be destroyed 287 + * after doing full scanning. 285 288 */ 286 289 struct ubi_attach_req { 287 290 __s32 ubi_num; 288 291 __s32 mtd_num; 289 292 __s32 vid_hdr_offset; 290 293 __s16 max_beb_per1024; 291 - __s8 padding[10]; 294 + __s8 disable_fm; 295 + __s8 padding[9]; 292 296 }; 293 297 294 298 /*