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

Pull UBI and UBIFS updates from Richard Weinberger:
"UBIFS:
- Misc code cleanups such as removal of unnecessary variables

UBI:
- No longer program unused bit in UBI headers"

* tag 'ubifs-for-linus-6.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs:
ubifs: vmalloc(array_size()) -> vmalloc_array()
ubi: fastmap: fix ubi->fm memory leak
mtd: ubi: skip programming unused bits in ubi headers
ubifs: Remove unnecessary variable assignments
ubifs: Simplify the code using ubifs_crc_node
ubifs: Remove unnecessary parameters '*c'

+39 -35
+3 -1
drivers/mtd/ubi/attach.c
··· 1600 1601 err = ubi_read_volume_table(ubi, ai); 1602 if (err) 1603 - goto out_ai; 1604 1605 err = ubi_wl_init(ubi, ai); 1606 if (err) ··· 1642 out_vtbl: 1643 ubi_free_all_volumes(ubi); 1644 vfree(ubi->vtbl); 1645 out_ai: 1646 destroy_ai(ai); 1647 return err;
··· 1600 1601 err = ubi_read_volume_table(ubi, ai); 1602 if (err) 1603 + goto out_fm; 1604 1605 err = ubi_wl_init(ubi, ai); 1606 if (err) ··· 1642 out_vtbl: 1643 ubi_free_all_volumes(ubi); 1644 vfree(ubi->vtbl); 1645 + out_fm: 1646 + ubi_free_fastmap(ubi); 1647 out_ai: 1648 destroy_ai(ai); 1649 return err;
+1 -7
drivers/mtd/ubi/fastmap-wl.c
··· 530 531 static void ubi_fastmap_close(struct ubi_device *ubi) 532 { 533 - int i; 534 - 535 return_unused_pool_pebs(ubi, &ubi->fm_pool); 536 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); 537 ··· 538 ubi->fm_anchor = NULL; 539 } 540 541 - if (ubi->fm) { 542 - for (i = 0; i < ubi->fm->used_blocks; i++) 543 - kfree(ubi->fm->e[i]); 544 - } 545 - kfree(ubi->fm); 546 } 547 548 /**
··· 530 531 static void ubi_fastmap_close(struct ubi_device *ubi) 532 { 533 return_unused_pool_pebs(ubi, &ubi->fm_pool); 534 return_unused_pool_pebs(ubi, &ubi->fm_wl_pool); 535 ··· 540 ubi->fm_anchor = NULL; 541 } 542 543 + ubi_free_fastmap(ubi); 544 } 545 546 /**
+10
drivers/mtd/ubi/io.c
··· 868 return -EROFS; 869 } 870 871 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); 872 return err; 873 } ··· 1150 ubi_warn(ubi, "emulating a power cut when writing VID header"); 1151 ubi_ro_mode(ubi); 1152 return -EROFS; 1153 } 1154 1155 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
··· 868 return -EROFS; 869 } 870 871 + memset((char *)ec_hdr + UBI_EC_HDR_SIZE, 0xFF, ubi->ec_hdr_alsize - UBI_EC_HDR_SIZE); 872 + 873 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); 874 return err; 875 } ··· 1148 ubi_warn(ubi, "emulating a power cut when writing VID header"); 1149 ubi_ro_mode(ubi); 1150 return -EROFS; 1151 + } 1152 + 1153 + if (ubi->vid_hdr_shift) { 1154 + memset((char *)p, 0xFF, ubi->vid_hdr_shift); 1155 + memset((char *)p + ubi->vid_hdr_shift + UBI_VID_HDR_SIZE, 0xFF, 1156 + ubi->vid_hdr_alsize - (ubi->vid_hdr_shift + UBI_VID_HDR_SIZE)); 1157 + } else { 1158 + memset((char *)p + UBI_VID_HDR_SIZE, 0xFF, ubi->vid_hdr_alsize - UBI_VID_HDR_SIZE); 1159 } 1160 1161 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
+12
drivers/mtd/ubi/ubi.h
··· 969 struct ubi_attach_info *scan_ai); 970 int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count); 971 void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol); 972 #else 973 static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; } 974 static inline int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count) { return 0; } 975 static inline void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol) {} 976 #endif 977 978 /* block.c */
··· 969 struct ubi_attach_info *scan_ai); 970 int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count); 971 void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol); 972 + static inline void ubi_free_fastmap(struct ubi_device *ubi) 973 + { 974 + if (ubi->fm) { 975 + int i; 976 + 977 + for (i = 0; i < ubi->fm->used_blocks; i++) 978 + kmem_cache_free(ubi_wl_entry_slab, ubi->fm->e[i]); 979 + kfree(ubi->fm); 980 + ubi->fm = NULL; 981 + } 982 + } 983 #else 984 static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; } 985 static inline int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count) { return 0; } 986 static inline void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol) {} 987 + static inline void ubi_free_fastmap(struct ubi_device *ubi) { } 988 #endif 989 990 /* block.c */
+4 -9
fs/ubifs/io.c
··· 327 */ 328 void ubifs_pad(const struct ubifs_info *c, void *buf, int pad) 329 { 330 - uint32_t crc; 331 - 332 ubifs_assert(c, pad >= 0); 333 334 if (pad >= UBIFS_PAD_NODE_SZ) { ··· 341 ch->len = cpu_to_le32(UBIFS_PAD_NODE_SZ); 342 pad -= UBIFS_PAD_NODE_SZ; 343 pad_node->pad_len = cpu_to_le32(pad); 344 - crc = crc32(UBIFS_CRC32_INIT, buf + 8, UBIFS_PAD_NODE_SZ - 8); 345 - ch->crc = cpu_to_le32(crc); 346 memset(buf + UBIFS_PAD_NODE_SZ, 0, pad); 347 } else if (pad > 0) 348 /* Too little space, padding node won't fit */ ··· 392 } 393 } 394 395 - void ubifs_crc_node(struct ubifs_info *c, void *node, int len) 396 { 397 struct ubifs_ch *ch = node; 398 uint32_t crc; ··· 429 return err; 430 } 431 432 - ubifs_crc_node(c, node, len); 433 434 return 0; 435 } ··· 466 */ 467 void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last) 468 { 469 - uint32_t crc; 470 struct ubifs_ch *ch = node; 471 unsigned long long sqnum = next_sqnum(c); 472 ··· 479 ch->group_type = UBIFS_IN_NODE_GROUP; 480 ch->sqnum = cpu_to_le64(sqnum); 481 ch->padding[0] = ch->padding[1] = 0; 482 - crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8); 483 - ch->crc = cpu_to_le32(crc); 484 } 485 486 /**
··· 327 */ 328 void ubifs_pad(const struct ubifs_info *c, void *buf, int pad) 329 { 330 ubifs_assert(c, pad >= 0); 331 332 if (pad >= UBIFS_PAD_NODE_SZ) { ··· 343 ch->len = cpu_to_le32(UBIFS_PAD_NODE_SZ); 344 pad -= UBIFS_PAD_NODE_SZ; 345 pad_node->pad_len = cpu_to_le32(pad); 346 + ubifs_crc_node(buf, UBIFS_PAD_NODE_SZ); 347 memset(buf + UBIFS_PAD_NODE_SZ, 0, pad); 348 } else if (pad > 0) 349 /* Too little space, padding node won't fit */ ··· 395 } 396 } 397 398 + void ubifs_crc_node(void *node, int len) 399 { 400 struct ubifs_ch *ch = node; 401 uint32_t crc; ··· 432 return err; 433 } 434 435 + ubifs_crc_node(node, len); 436 437 return 0; 438 } ··· 469 */ 470 void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last) 471 { 472 struct ubifs_ch *ch = node; 473 unsigned long long sqnum = next_sqnum(c); 474 ··· 483 ch->group_type = UBIFS_IN_NODE_GROUP; 484 ch->sqnum = cpu_to_le64(sqnum); 485 ch->padding[0] = ch->padding[1] = 0; 486 + ubifs_crc_node(node, len); 487 } 488 489 /**
+6 -6
fs/ubifs/lpt.c
··· 628 pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL); 629 nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL); 630 buf = vmalloc(c->leb_size); 631 - ltab = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops), 632 - c->lpt_lebs)); 633 if (!pnode || !nnode || !buf || !ltab || !lsave) { 634 err = -ENOMEM; 635 goto out; ··· 1777 { 1778 int err, i; 1779 1780 - c->ltab = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops), 1781 - c->lpt_lebs)); 1782 if (!c->ltab) 1783 return -ENOMEM; 1784 ··· 1846 { 1847 int err, i; 1848 1849 - c->ltab_cmt = vmalloc(array_size(sizeof(struct ubifs_lpt_lprops), 1850 - c->lpt_lebs)); 1851 if (!c->ltab_cmt) 1852 return -ENOMEM; 1853
··· 628 pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL); 629 nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL); 630 buf = vmalloc(c->leb_size); 631 + ltab = vmalloc_array(c->lpt_lebs, 632 + sizeof(struct ubifs_lpt_lprops)); 633 if (!pnode || !nnode || !buf || !ltab || !lsave) { 634 err = -ENOMEM; 635 goto out; ··· 1777 { 1778 int err, i; 1779 1780 + c->ltab = vmalloc_array(c->lpt_lebs, 1781 + sizeof(struct ubifs_lpt_lprops)); 1782 if (!c->ltab) 1783 return -ENOMEM; 1784 ··· 1846 { 1847 int err, i; 1848 1849 + c->ltab_cmt = vmalloc_array(c->lpt_lebs, 1850 + sizeof(struct ubifs_lpt_lprops)); 1851 if (!c->ltab_cmt) 1852 return -ENOMEM; 1853
+1 -3
fs/ubifs/recovery.c
··· 1406 union ubifs_key key; 1407 int err, lnum, offs, len; 1408 loff_t i_size; 1409 - uint32_t crc; 1410 1411 /* Locate the inode node LEB number and offset */ 1412 ino_key_init(c, &key, e->inum); ··· 1427 ino = c->sbuf + offs; 1428 ino->size = cpu_to_le64(e->d_size); 1429 len = le32_to_cpu(ino->ch.len); 1430 - crc = crc32(UBIFS_CRC32_INIT, (void *)ino + 8, len - 8); 1431 - ino->ch.crc = cpu_to_le32(crc); 1432 /* Work out where data in the LEB ends and free space begins */ 1433 p = c->sbuf; 1434 len = c->leb_size - 1;
··· 1406 union ubifs_key key; 1407 int err, lnum, offs, len; 1408 loff_t i_size; 1409 1410 /* Locate the inode node LEB number and offset */ 1411 ino_key_init(c, &key, e->inum); ··· 1428 ino = c->sbuf + offs; 1429 ino->size = cpu_to_le64(e->d_size); 1430 len = le32_to_cpu(ino->ch.len); 1431 + ubifs_crc_node((void *)ino, len); 1432 /* Work out where data in the LEB ends and free space begins */ 1433 p = c->sbuf; 1434 len = c->leb_size - 1;
+1 -8
fs/ubifs/tnc_misc.c
··· 321 c->fanout, znode->child_cnt); 322 ubifs_err(c, "max levels %d, znode level %d", 323 UBIFS_MAX_LEVELS, znode->level); 324 - err = 1; 325 goto out_dump; 326 } 327 ··· 341 zbr->lnum >= c->leb_cnt || zbr->offs < 0 || 342 zbr->offs + zbr->len > c->leb_size || zbr->offs & 7) { 343 ubifs_err(c, "bad branch %d", i); 344 - err = 2; 345 goto out_dump; 346 } 347 ··· 353 default: 354 ubifs_err(c, "bad key type at slot %d: %d", 355 i, key_type(c, &zbr->key)); 356 - err = 3; 357 goto out_dump; 358 } 359 ··· 365 ubifs_err(c, "bad target node (type %d) length (%d)", 366 type, zbr->len); 367 ubifs_err(c, "have to be %d", c->ranges[type].len); 368 - err = 4; 369 goto out_dump; 370 } 371 } else if (zbr->len < c->ranges[type].min_len || ··· 374 ubifs_err(c, "have to be in range of %d-%d", 375 c->ranges[type].min_len, 376 c->ranges[type].max_len); 377 - err = 5; 378 goto out_dump; 379 } 380 } ··· 391 cmp = keys_cmp(c, key1, key2); 392 if (cmp > 0) { 393 ubifs_err(c, "bad key order (keys %d and %d)", i, i + 1); 394 - err = 6; 395 goto out_dump; 396 } else if (cmp == 0 && !is_hash_key(c, key1)) { 397 /* These can only be keys with colliding hash */ 398 ubifs_err(c, "keys %d and %d are not hashed but equivalent", 399 i, i + 1); 400 - err = 7; 401 goto out_dump; 402 } 403 } ··· 404 return 0; 405 406 out_dump: 407 - ubifs_err(c, "bad indexing node at LEB %d:%d, error %d", lnum, offs, err); 408 ubifs_dump_node(c, idx, c->max_idx_node_sz); 409 kfree(idx); 410 return -EINVAL;
··· 321 c->fanout, znode->child_cnt); 322 ubifs_err(c, "max levels %d, znode level %d", 323 UBIFS_MAX_LEVELS, znode->level); 324 goto out_dump; 325 } 326 ··· 342 zbr->lnum >= c->leb_cnt || zbr->offs < 0 || 343 zbr->offs + zbr->len > c->leb_size || zbr->offs & 7) { 344 ubifs_err(c, "bad branch %d", i); 345 goto out_dump; 346 } 347 ··· 355 default: 356 ubifs_err(c, "bad key type at slot %d: %d", 357 i, key_type(c, &zbr->key)); 358 goto out_dump; 359 } 360 ··· 368 ubifs_err(c, "bad target node (type %d) length (%d)", 369 type, zbr->len); 370 ubifs_err(c, "have to be %d", c->ranges[type].len); 371 goto out_dump; 372 } 373 } else if (zbr->len < c->ranges[type].min_len || ··· 378 ubifs_err(c, "have to be in range of %d-%d", 379 c->ranges[type].min_len, 380 c->ranges[type].max_len); 381 goto out_dump; 382 } 383 } ··· 396 cmp = keys_cmp(c, key1, key2); 397 if (cmp > 0) { 398 ubifs_err(c, "bad key order (keys %d and %d)", i, i + 1); 399 goto out_dump; 400 } else if (cmp == 0 && !is_hash_key(c, key1)) { 401 /* These can only be keys with colliding hash */ 402 ubifs_err(c, "keys %d and %d are not hashed but equivalent", 403 i, i + 1); 404 goto out_dump; 405 } 406 } ··· 411 return 0; 412 413 out_dump: 414 + ubifs_err(c, "bad indexing node at LEB %d:%d", lnum, offs); 415 ubifs_dump_node(c, idx, c->max_idx_node_sz); 416 kfree(idx); 417 return -EINVAL;
+1 -1
fs/ubifs/ubifs.h
··· 1747 int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len, 1748 int lnum, int offs, int quiet, int must_chk_crc); 1749 void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad); 1750 - void ubifs_crc_node(struct ubifs_info *c, void *buf, int len); 1751 void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); 1752 int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len, 1753 int hmac_offs, int pad);
··· 1747 int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len, 1748 int lnum, int offs, int quiet, int must_chk_crc); 1749 void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad); 1750 + void ubifs_crc_node(void *buf, int len); 1751 void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad); 1752 int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len, 1753 int hmac_offs, int pad);