lkml.org 
[lkml]   [2012]   [Feb]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH 6/7] MTD: UBI: Implement checkpointing support
On Tue, 14 Feb 2012 21:06:45 +0100 Richard Weinberger <rw@linutronix.de> wrote:
> Implements UBI checkpointing support.
> It reduces the attaching time from O(N) to O(1).
> Checkpoints are written on demand and upon changes of the volume layout.
> If the recovery from a checkpoint fails we fall back to scanning mode.

Partially reviewed the feature. Great work.
There's some tiny styling/coding issues, will send references if you'd
like.

I'll comment on the feature itself later on.

Meanwhile, there's a potential memleak/crash you might wanna fix.

> +/* Reads the checkpoint data from it's PEBs */
> +struct ubi_scan_info *ubi_read_checkpoint(struct ubi_device *ubi, int cb_sb_pnum)
> +{
> + struct ubi_cp_sb *cpsb;
> + struct ubi_vid_hdr *vh;
> + int ret, i, nblocks;
> + char *cp_raw;
> + size_t cp_size;
> + __be32 data_crc;
> + unsigned long long sqnum = 0;
> + struct ubi_scan_info *si = NULL;
> +
> + cpsb = kmalloc(sizeof(*cpsb), GFP_KERNEL);
> + if (!cpsb) {
> + si = ERR_PTR(-ENOMEM);
> + goto out;
> + }
> +
> + ret = ubi_io_read(ubi, cpsb, cb_sb_pnum, ubi->leb_start, sizeof(*cpsb));
> + if (ret) {
> + ubi_err("Unable to read checkpoint super block");
> + si = ERR_PTR(ret);
> + goto out;

s/goto out/goto free_sb/
(otherwise 'cpsb' not freed)

> + /* cp_raw will contain the whole checkpoint */
> + cp_raw = vzalloc(cp_size);

...

> +
> + cpsb = (struct ubi_cp_sb *)cp_raw;

'cpsb' is overwritten, but formerly kmalloced (at the beginning of
ubi_read_checkpoint).
Should free 'cpsb' prior assignment, or alternatively use different
variable then 'cpsb'.

...

> +
> +free_vhdr:
> + ubi_free_vid_hdr(ubi, vh);
> +free_raw:
> + vfree(cp_raw);
> +free_sb:
> + kfree(cpsb);

Freeing 'cp_raw' and 'cpsb', but in the normal flow, they point to the
same thing.

Regards,
Shmulik


\
 
 \ /
  Last update: 2012-02-20 17:35    [W:0.149 / U:0.328 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site