[PATCH 19/27] ubifs: ubifs_dump: dump master node

David Gstir david at sigma-star.at
Thu Oct 8 03:07:14 PDT 2015


Hi Yang,

I just spotted this issue while reading through your patches:

> On 19.08.2015, at 10:39, Dongsheng Yang <yangds.fnst at cn.fujitsu.com> wrote:

[...]

> +static int scan_for_master(struct ubifs_info *c, struct ubifs_mst_node *mst_node)
> {
> +	struct ubifs_scan_leb *sleb;
> +	struct ubifs_scan_node *snod;
> +	int lnum, offs = 0, nodes_cnt;
> +	static void *leb_buf;
> 	int err = 0;
> +	
> +	lnum = UBIFS_MST_LNUM;
> 
> -	err = init();
> -	if (err)
> +	leb_buf = malloc(c->leb_size);
> +	if (!leb_buf)
> +		return -ENOMEM;
> +
> +	sleb = ubifs_scan(c, lnum, 0, leb_buf, 1);
> +	if (IS_ERR(sleb)) {
> +		err = PTR_ERR(sleb);
> 		goto out;

This goto will run ubifs_scan_destroy(sleb), which does not work since sleb ist just an ERR_PTR here.

> +	}
> +	nodes_cnt = sleb->nodes_cnt;
> +	if (nodes_cnt > 0) {
> +		snod = list_entry(sleb->nodes.prev, struct ubifs_scan_node,
> +				  list);
> +		if (snod->type != UBIFS_MST_NODE) {
> +			err = -EINVAL;
> +			goto out;
> +		}
> +		memcpy(mst_node, snod->node, snod->len);
> +		offs = snod->offs;
> +	}
> +	ubifs_scan_destroy(sleb);
> +
> +	lnum += 1;
> +
> +	sleb = ubifs_scan(c, lnum, 0, leb_buf, 1);
> +	if (IS_ERR(sleb)) {
> +		err = PTR_ERR(sleb);
> +		goto out;

Same here.

> +	}
> +	err = -EUCLEAN;
> +	if (sleb->nodes_cnt != nodes_cnt)
> +		goto out;
> +	if (!sleb->nodes_cnt)
> +		goto out;
> +	snod = list_entry(sleb->nodes.prev, struct ubifs_scan_node, list);
> +	if (snod->type != UBIFS_MST_NODE) {
> +		err = -EINVAL;
> +		goto out;
> +	}
> +	if (snod->offs != offs)
> +		goto out;
> +	if (memcmp((void *)mst_node + UBIFS_CH_SZ,
> +		   (void *)snod->node + UBIFS_CH_SZ,
> +		   UBIFS_MST_NODE_SZ - UBIFS_CH_SZ))
> +		goto out;
> +	err = 0;
> +
> +out:
> +	free(leb_buf);
> +	ubifs_scan_destroy(sleb);
> +	return err;
> +}

Cheers,
David





More information about the linux-mtd mailing list