Skip to content

Commit 70e3083

Browse files
committed
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'
2 parents b88b2f8 + 0695aef commit 70e3083

File tree

9 files changed

+39
-35
lines changed

9 files changed

+39
-35
lines changed

drivers/mtd/ubi/attach.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
16001600

16011601
err = ubi_read_volume_table(ubi, ai);
16021602
if (err)
1603-
goto out_ai;
1603+
goto out_fm;
16041604

16051605
err = ubi_wl_init(ubi, ai);
16061606
if (err)
@@ -1642,6 +1642,8 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
16421642
out_vtbl:
16431643
ubi_free_all_volumes(ubi);
16441644
vfree(ubi->vtbl);
1645+
out_fm:
1646+
ubi_free_fastmap(ubi);
16451647
out_ai:
16461648
destroy_ai(ai);
16471649
return err;

drivers/mtd/ubi/fastmap-wl.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,6 @@ int ubi_is_erase_work(struct ubi_work *wrk)
530530

531531
static void ubi_fastmap_close(struct ubi_device *ubi)
532532
{
533-
int i;
534-
535533
return_unused_pool_pebs(ubi, &ubi->fm_pool);
536534
return_unused_pool_pebs(ubi, &ubi->fm_wl_pool);
537535

@@ -540,11 +538,7 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
540538
ubi->fm_anchor = NULL;
541539
}
542540

543-
if (ubi->fm) {
544-
for (i = 0; i < ubi->fm->used_blocks; i++)
545-
kfree(ubi->fm->e[i]);
546-
}
547-
kfree(ubi->fm);
541+
ubi_free_fastmap(ubi);
548542
}
549543

550544
/**

drivers/mtd/ubi/io.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
868868
return -EROFS;
869869
}
870870

871+
memset((char *)ec_hdr + UBI_EC_HDR_SIZE, 0xFF, ubi->ec_hdr_alsize - UBI_EC_HDR_SIZE);
872+
871873
err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
872874
return err;
873875
}
@@ -1150,6 +1152,14 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
11501152
return -EROFS;
11511153
}
11521154

1155+
if (ubi->vid_hdr_shift) {
1156+
memset((char *)p, 0xFF, ubi->vid_hdr_shift);
1157+
memset((char *)p + ubi->vid_hdr_shift + UBI_VID_HDR_SIZE, 0xFF,
1158+
ubi->vid_hdr_alsize - (ubi->vid_hdr_shift + UBI_VID_HDR_SIZE));
1159+
} else {
1160+
memset((char *)p + UBI_VID_HDR_SIZE, 0xFF, ubi->vid_hdr_alsize - UBI_VID_HDR_SIZE);
1161+
}
1162+
11531163
err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
11541164
ubi->vid_hdr_alsize);
11551165
return err;

drivers/mtd/ubi/ubi.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,22 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
969969
struct ubi_attach_info *scan_ai);
970970
int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count);
971971
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+
}
972983
#else
973984
static inline int ubi_update_fastmap(struct ubi_device *ubi) { return 0; }
974985
static inline int ubi_fastmap_init_checkmap(struct ubi_volume *vol, int leb_count) { return 0; }
975986
static inline void ubi_fastmap_destroy_checkmap(struct ubi_volume *vol) {}
987+
static inline void ubi_free_fastmap(struct ubi_device *ubi) { }
976988
#endif
977989

978990
/* block.c */

fs/ubifs/io.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,
327327
*/
328328
void ubifs_pad(const struct ubifs_info *c, void *buf, int pad)
329329
{
330-
uint32_t crc;
331-
332330
ubifs_assert(c, pad >= 0);
333331

334332
if (pad >= UBIFS_PAD_NODE_SZ) {
@@ -343,8 +341,7 @@ void ubifs_pad(const struct ubifs_info *c, void *buf, int pad)
343341
ch->len = cpu_to_le32(UBIFS_PAD_NODE_SZ);
344342
pad -= UBIFS_PAD_NODE_SZ;
345343
pad_node->pad_len = cpu_to_le32(pad);
346-
crc = crc32(UBIFS_CRC32_INIT, buf + 8, UBIFS_PAD_NODE_SZ - 8);
347-
ch->crc = cpu_to_le32(crc);
344+
ubifs_crc_node(buf, UBIFS_PAD_NODE_SZ);
348345
memset(buf + UBIFS_PAD_NODE_SZ, 0, pad);
349346
} else if (pad > 0)
350347
/* Too little space, padding node won't fit */
@@ -395,7 +392,7 @@ void ubifs_init_node(struct ubifs_info *c, void *node, int len, int pad)
395392
}
396393
}
397394

398-
void ubifs_crc_node(struct ubifs_info *c, void *node, int len)
395+
void ubifs_crc_node(void *node, int len)
399396
{
400397
struct ubifs_ch *ch = node;
401398
uint32_t crc;
@@ -432,7 +429,7 @@ int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
432429
return err;
433430
}
434431

435-
ubifs_crc_node(c, node, len);
432+
ubifs_crc_node(node, len);
436433

437434
return 0;
438435
}
@@ -469,7 +466,6 @@ void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad)
469466
*/
470467
void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last)
471468
{
472-
uint32_t crc;
473469
struct ubifs_ch *ch = node;
474470
unsigned long long sqnum = next_sqnum(c);
475471

@@ -483,8 +479,7 @@ void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last)
483479
ch->group_type = UBIFS_IN_NODE_GROUP;
484480
ch->sqnum = cpu_to_le64(sqnum);
485481
ch->padding[0] = ch->padding[1] = 0;
486-
crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
487-
ch->crc = cpu_to_le32(crc);
482+
ubifs_crc_node(node, len);
488483
}
489484

490485
/**

fs/ubifs/lpt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
628628
pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
629629
nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL);
630630
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));
633633
if (!pnode || !nnode || !buf || !ltab || !lsave) {
634634
err = -ENOMEM;
635635
goto out;
@@ -1777,8 +1777,8 @@ static int lpt_init_rd(struct ubifs_info *c)
17771777
{
17781778
int err, i;
17791779

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));
17821782
if (!c->ltab)
17831783
return -ENOMEM;
17841784

@@ -1846,8 +1846,8 @@ static int lpt_init_wr(struct ubifs_info *c)
18461846
{
18471847
int err, i;
18481848

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));
18511851
if (!c->ltab_cmt)
18521852
return -ENOMEM;
18531853

fs/ubifs/recovery.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,6 @@ static int fix_size_in_place(struct ubifs_info *c, struct size_entry *e)
14061406
union ubifs_key key;
14071407
int err, lnum, offs, len;
14081408
loff_t i_size;
1409-
uint32_t crc;
14101409

14111410
/* Locate the inode node LEB number and offset */
14121411
ino_key_init(c, &key, e->inum);
@@ -1428,8 +1427,7 @@ static int fix_size_in_place(struct ubifs_info *c, struct size_entry *e)
14281427
ino = c->sbuf + offs;
14291428
ino->size = cpu_to_le64(e->d_size);
14301429
len = le32_to_cpu(ino->ch.len);
1431-
crc = crc32(UBIFS_CRC32_INIT, (void *)ino + 8, len - 8);
1432-
ino->ch.crc = cpu_to_le32(crc);
1430+
ubifs_crc_node((void *)ino, len);
14331431
/* Work out where data in the LEB ends and free space begins */
14341432
p = c->sbuf;
14351433
len = c->leb_size - 1;

fs/ubifs/tnc_misc.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ static int read_znode(struct ubifs_info *c, struct ubifs_zbranch *zzbr,
321321
c->fanout, znode->child_cnt);
322322
ubifs_err(c, "max levels %d, znode level %d",
323323
UBIFS_MAX_LEVELS, znode->level);
324-
err = 1;
325324
goto out_dump;
326325
}
327326

@@ -342,7 +341,6 @@ static int read_znode(struct ubifs_info *c, struct ubifs_zbranch *zzbr,
342341
zbr->lnum >= c->leb_cnt || zbr->offs < 0 ||
343342
zbr->offs + zbr->len > c->leb_size || zbr->offs & 7) {
344343
ubifs_err(c, "bad branch %d", i);
345-
err = 2;
346344
goto out_dump;
347345
}
348346

@@ -355,7 +353,6 @@ static int read_znode(struct ubifs_info *c, struct ubifs_zbranch *zzbr,
355353
default:
356354
ubifs_err(c, "bad key type at slot %d: %d",
357355
i, key_type(c, &zbr->key));
358-
err = 3;
359356
goto out_dump;
360357
}
361358

@@ -368,7 +365,6 @@ static int read_znode(struct ubifs_info *c, struct ubifs_zbranch *zzbr,
368365
ubifs_err(c, "bad target node (type %d) length (%d)",
369366
type, zbr->len);
370367
ubifs_err(c, "have to be %d", c->ranges[type].len);
371-
err = 4;
372368
goto out_dump;
373369
}
374370
} else if (zbr->len < c->ranges[type].min_len ||
@@ -378,7 +374,6 @@ static int read_znode(struct ubifs_info *c, struct ubifs_zbranch *zzbr,
378374
ubifs_err(c, "have to be in range of %d-%d",
379375
c->ranges[type].min_len,
380376
c->ranges[type].max_len);
381-
err = 5;
382377
goto out_dump;
383378
}
384379
}
@@ -396,13 +391,11 @@ static int read_znode(struct ubifs_info *c, struct ubifs_zbranch *zzbr,
396391
cmp = keys_cmp(c, key1, key2);
397392
if (cmp > 0) {
398393
ubifs_err(c, "bad key order (keys %d and %d)", i, i + 1);
399-
err = 6;
400394
goto out_dump;
401395
} else if (cmp == 0 && !is_hash_key(c, key1)) {
402396
/* These can only be keys with colliding hash */
403397
ubifs_err(c, "keys %d and %d are not hashed but equivalent",
404398
i, i + 1);
405-
err = 7;
406399
goto out_dump;
407400
}
408401
}
@@ -411,7 +404,7 @@ static int read_znode(struct ubifs_info *c, struct ubifs_zbranch *zzbr,
411404
return 0;
412405

413406
out_dump:
414-
ubifs_err(c, "bad indexing node at LEB %d:%d, error %d", lnum, offs, err);
407+
ubifs_err(c, "bad indexing node at LEB %d:%d", lnum, offs);
415408
ubifs_dump_node(c, idx, c->max_idx_node_sz);
416409
kfree(idx);
417410
return -EINVAL;

fs/ubifs/ubifs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ int ubifs_write_node_hmac(struct ubifs_info *c, void *buf, int len, int lnum,
17471747
int ubifs_check_node(const struct ubifs_info *c, const void *buf, int len,
17481748
int lnum, int offs, int quiet, int must_chk_crc);
17491749
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);
17511751
void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
17521752
int ubifs_prepare_node_hmac(struct ubifs_info *c, void *node, int len,
17531753
int hmac_offs, int pad);

0 commit comments

Comments
 (0)