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