Skip to content

Commit a87a08e

Browse files
committed
Merge tag 'for-linus-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs
Pull JFFS2, UBI and UBIFS updates from Richard Weinberger: "JFFS2: - Fixes for various memory issues UBI: - Fix for a race condition in cdev ioctl handler UBIFS: - Fixes for O_TMPFILE and whiteout handling - Fixes for various memory issues" * tag 'for-linus-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs: ubifs: rename_whiteout: correct old_dir size computing jffs2: fix memory leak in jffs2_scan_medium jffs2: fix memory leak in jffs2_do_mount_fs jffs2: fix use-after-free in jffs2_clear_xattr_subsystem fs/jffs2: fix comments mentioning i_mutex ubi: fastmap: Return error code if memory allocation fails in add_aeb() ubifs: Fix to add refcount once page is set private ubifs: Fix read out-of-bounds in ubifs_wbuf_write_nolock() ubifs: setflags: Make dirtied_ino_d 8 bytes aligned ubifs: Rectify space amount budget for mkdir/tmpfile operations ubifs: Fix 'ui->dirty' race between do_tmpfile() and writeback work ubifs: Rename whiteout atomically ubifs: Add missing iput if do_tmpfile() failed in rename whiteout ubifs: Fix wrong number of inodes locked by ui_mutex in ubifs_inode comment ubifs: Fix deadlock in concurrent rename whiteout and inode writeback ubifs: rename_whiteout: Fix double free for whiteout_ui->data ubi: Fix race condition between ctrl_cdev_ioctl and ubi_cdev_ioctl
2 parents 3d198e4 + 7057572 commit a87a08e

File tree

13 files changed

+259
-144
lines changed

13 files changed

+259
-144
lines changed

drivers/mtd/ubi/build.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ static ssize_t dev_attribute_show(struct device *dev,
351351
* we still can use 'ubi->ubi_num'.
352352
*/
353353
ubi = container_of(dev, struct ubi_device, dev);
354-
ubi = ubi_get_device(ubi->ubi_num);
355-
if (!ubi)
356-
return -ENODEV;
357354

358355
if (attr == &dev_eraseblock_size)
359356
ret = sprintf(buf, "%d\n", ubi->leb_size);
@@ -382,7 +379,6 @@ static ssize_t dev_attribute_show(struct device *dev,
382379
else
383380
ret = -EINVAL;
384381

385-
ubi_put_device(ubi);
386382
return ret;
387383
}
388384

@@ -979,9 +975,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
979975
goto out_detach;
980976
}
981977

982-
/* Make device "available" before it becomes accessible via sysfs */
983-
ubi_devices[ubi_num] = ubi;
984-
985978
err = uif_init(ubi);
986979
if (err)
987980
goto out_detach;
@@ -1026,6 +1019,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
10261019
wake_up_process(ubi->bgt_thread);
10271020
spin_unlock(&ubi->wl_lock);
10281021

1022+
ubi_devices[ubi_num] = ubi;
10291023
ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
10301024
return ubi_num;
10311025

@@ -1034,7 +1028,6 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
10341028
out_uif:
10351029
uif_close(ubi);
10361030
out_detach:
1037-
ubi_devices[ubi_num] = NULL;
10381031
ubi_wl_close(ubi);
10391032
ubi_free_all_volumes(ubi);
10401033
vfree(ubi->vtbl);

drivers/mtd/ubi/fastmap.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
468468
if (err == UBI_IO_FF_BITFLIPS)
469469
scrub = 1;
470470

471-
add_aeb(ai, free, pnum, ec, scrub);
471+
ret = add_aeb(ai, free, pnum, ec, scrub);
472+
if (ret)
473+
goto out;
472474
continue;
473475
} else if (err == 0 || err == UBI_IO_BITFLIPS) {
474476
dbg_bld("Found non empty PEB:%i in pool", pnum);
@@ -638,8 +640,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
638640
if (fm_pos >= fm_size)
639641
goto fail_bad;
640642

641-
add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
642-
be32_to_cpu(fmec->ec), 0);
643+
ret = add_aeb(ai, &ai->free, be32_to_cpu(fmec->pnum),
644+
be32_to_cpu(fmec->ec), 0);
645+
if (ret)
646+
goto fail;
643647
}
644648

645649
/* read EC values from used list */
@@ -649,8 +653,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
649653
if (fm_pos >= fm_size)
650654
goto fail_bad;
651655

652-
add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
653-
be32_to_cpu(fmec->ec), 0);
656+
ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
657+
be32_to_cpu(fmec->ec), 0);
658+
if (ret)
659+
goto fail;
654660
}
655661

656662
/* read EC values from scrub list */
@@ -660,8 +666,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
660666
if (fm_pos >= fm_size)
661667
goto fail_bad;
662668

663-
add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
664-
be32_to_cpu(fmec->ec), 1);
669+
ret = add_aeb(ai, &used, be32_to_cpu(fmec->pnum),
670+
be32_to_cpu(fmec->ec), 1);
671+
if (ret)
672+
goto fail;
665673
}
666674

667675
/* read EC values from erase list */
@@ -671,8 +679,10 @@ static int ubi_attach_fastmap(struct ubi_device *ubi,
671679
if (fm_pos >= fm_size)
672680
goto fail_bad;
673681

674-
add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
675-
be32_to_cpu(fmec->ec), 1);
682+
ret = add_aeb(ai, &ai->erase, be32_to_cpu(fmec->pnum),
683+
be32_to_cpu(fmec->ec), 1);
684+
if (ret)
685+
goto fail;
676686
}
677687

678688
ai->mean_ec = div_u64(ai->ec_sum, ai->ec_count);

drivers/mtd/ubi/vmt.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,11 @@ static ssize_t vol_attribute_show(struct device *dev,
5656
{
5757
int ret;
5858
struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
59-
struct ubi_device *ubi;
60-
61-
ubi = ubi_get_device(vol->ubi->ubi_num);
62-
if (!ubi)
63-
return -ENODEV;
59+
struct ubi_device *ubi = vol->ubi;
6460

6561
spin_lock(&ubi->volumes_lock);
6662
if (!ubi->volumes[vol->vol_id]) {
6763
spin_unlock(&ubi->volumes_lock);
68-
ubi_put_device(ubi);
6964
return -ENODEV;
7065
}
7166
/* Take a reference to prevent volume removal */
@@ -103,7 +98,6 @@ static ssize_t vol_attribute_show(struct device *dev,
10398
vol->ref_count -= 1;
10499
ubi_assert(vol->ref_count >= 0);
105100
spin_unlock(&ubi->volumes_lock);
106-
ubi_put_device(ubi);
107101
return ret;
108102
}
109103

fs/jffs2/build.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,15 @@ int jffs2_do_mount_fs(struct jffs2_sb_info *c)
415415
jffs2_free_ino_caches(c);
416416
jffs2_free_raw_node_refs(c);
417417
ret = -EIO;
418-
goto out_free;
418+
goto out_sum_exit;
419419
}
420420

421421
jffs2_calc_trigger_levels(c);
422422

423423
return 0;
424424

425+
out_sum_exit:
426+
jffs2_sum_exit(c);
425427
out_free:
426428
kvfree(c->blocks);
427429

fs/jffs2/fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ int jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc)
603603
jffs2_free_ino_caches(c);
604604
jffs2_free_raw_node_refs(c);
605605
kvfree(c->blocks);
606-
out_inohash:
607606
jffs2_clear_xattr_subsystem(c);
607+
out_inohash:
608608
kfree(c->inocache_list);
609609
out_wbuf:
610610
jffs2_flash_cleanup(c);

fs/jffs2/jffs2_fs_i.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#include <linux/mutex.h>
1919

2020
struct jffs2_inode_info {
21-
/* We need an internal mutex similar to inode->i_mutex.
21+
/* We need an internal mutex similar to inode->i_rwsem.
2222
Unfortunately, we can't used the existing one, because
2323
either the GC would deadlock, or we'd have to release it
2424
before letting GC proceed. Or we'd have to put ugliness
25-
into the GC code so it didn't attempt to obtain the i_mutex
25+
into the GC code so it didn't attempt to obtain the i_rwsem
2626
for the inode(s) which are already locked */
2727
struct mutex sem;
2828

fs/jffs2/scan.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
136136
if (!s) {
137137
JFFS2_WARNING("Can't allocate memory for summary\n");
138138
ret = -ENOMEM;
139-
goto out;
139+
goto out_buf;
140140
}
141141
}
142142

@@ -275,13 +275,15 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
275275
}
276276
ret = 0;
277277
out:
278+
jffs2_sum_reset_collected(s);
279+
kfree(s);
280+
out_buf:
278281
if (buf_size)
279282
kfree(flashbuf);
280283
#ifndef __ECOS
281284
else
282285
mtd_unpoint(c->mtd, 0, c->mtd->size);
283286
#endif
284-
kfree(s);
285287
return ret;
286288
}
287289

0 commit comments

Comments
 (0)