Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adbf05e3 authored by Artem Bityutskiy's avatar Artem Bityutskiy
Browse files

UBI: simplify debugging return codes



UBI debugging functions were a little bit over-engineered and
returned more error codes than needed, and the callers had to
do useless checks. Simplify the return codes.

Impact: only debugging code is affected, which means that for
        non-developers this is a no-op patch.

Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 0bf1c439
Loading
Loading
Loading
Loading
+25 −25
Original line number Original line Diff line number Diff line
@@ -143,7 +143,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,


	err = paranoid_check_not_bad(ubi, pnum);
	err = paranoid_check_not_bad(ubi, pnum);
	if (err)
	if (err)
		return err > 0 ? -EINVAL : err;
		return err;


	addr = (loff_t)pnum * ubi->peb_size + offset;
	addr = (loff_t)pnum * ubi->peb_size + offset;
retry:
retry:
@@ -236,12 +236,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,


	err = paranoid_check_not_bad(ubi, pnum);
	err = paranoid_check_not_bad(ubi, pnum);
	if (err)
	if (err)
		return err > 0 ? -EINVAL : err;
		return err;


	/* The area we are writing to has to contain all 0xFF bytes */
	/* The area we are writing to has to contain all 0xFF bytes */
	err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
	err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
	if (err)
	if (err)
		return err > 0 ? -EINVAL : err;
		return err;


	if (offset >= ubi->leb_start) {
	if (offset >= ubi->leb_start) {
		/*
		/*
@@ -250,10 +250,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
		 */
		 */
		err = paranoid_check_peb_ec_hdr(ubi, pnum);
		err = paranoid_check_peb_ec_hdr(ubi, pnum);
		if (err)
		if (err)
			return err > 0 ? -EINVAL : err;
			return err;
		err = paranoid_check_peb_vid_hdr(ubi, pnum);
		err = paranoid_check_peb_vid_hdr(ubi, pnum);
		if (err)
		if (err)
			return err > 0 ? -EINVAL : err;
			return err;
	}
	}


	if (ubi_dbg_is_write_failure()) {
	if (ubi_dbg_is_write_failure()) {
@@ -348,7 +348,7 @@ retry:


	err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
	err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
	if (err)
	if (err)
		return err > 0 ? -EINVAL : err;
		return err;


	if (ubi_dbg_is_erase_failure() && !err) {
	if (ubi_dbg_is_erase_failure() && !err) {
		dbg_err("cannot erase PEB %d (emulated)", pnum);
		dbg_err("cannot erase PEB %d (emulated)", pnum);
@@ -542,7 +542,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)


	err = paranoid_check_not_bad(ubi, pnum);
	err = paranoid_check_not_bad(ubi, pnum);
	if (err != 0)
	if (err != 0)
		return err > 0 ? -EINVAL : err;
		return err;


	if (ubi->ro_mode) {
	if (ubi->ro_mode) {
		ubi_err("read-only mode");
		ubi_err("read-only mode");
@@ -819,7 +819,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,


	err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
	err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
	if (err)
	if (err)
		return -EINVAL;
		return err;


	err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
	err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
	return err;
	return err;
@@ -1083,7 +1083,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,


	err = paranoid_check_peb_ec_hdr(ubi, pnum);
	err = paranoid_check_peb_ec_hdr(ubi, pnum);
	if (err)
	if (err)
		return err > 0 ? -EINVAL : err;
		return err;


	vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
	vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
	vid_hdr->version = UBI_VERSION;
	vid_hdr->version = UBI_VERSION;
@@ -1092,7 +1092,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,


	err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
	err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
	if (err)
	if (err)
		return -EINVAL;
		return err;


	p = (char *)vid_hdr - ubi->vid_hdr_shift;
	p = (char *)vid_hdr - ubi->vid_hdr_shift;
	err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
	err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
@@ -1107,8 +1107,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
 * @ubi: UBI device description object
 * @ubi: UBI device description object
 * @pnum: physical eraseblock number to check
 * @pnum: physical eraseblock number to check
 *
 *
 * This function returns zero if the physical eraseblock is good, a positive
 * This function returns zero if the physical eraseblock is good, %-EINVAL if
 * number if it is bad and a negative error code if an error occurred.
 * it is bad and a negative error code if an error occurred.
 */
 */
static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
{
{
@@ -1120,7 +1120,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)


	ubi_err("paranoid check failed for PEB %d", pnum);
	ubi_err("paranoid check failed for PEB %d", pnum);
	ubi_dbg_dump_stack();
	ubi_dbg_dump_stack();
	return err;
	return err > 0 ? -EINVAL : err;
}
}


/**
/**
@@ -1130,7 +1130,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
 * @ec_hdr: the erase counter header to check
 * @ec_hdr: the erase counter header to check
 *
 *
 * This function returns zero if the erase counter header contains valid
 * This function returns zero if the erase counter header contains valid
 * values, and %1 if not.
 * values, and %-EINVAL if not.
 */
 */
static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
				 const struct ubi_ec_hdr *ec_hdr)
				 const struct ubi_ec_hdr *ec_hdr)
@@ -1156,7 +1156,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
fail:
fail:
	ubi_dbg_dump_ec_hdr(ec_hdr);
	ubi_dbg_dump_ec_hdr(ec_hdr);
	ubi_dbg_dump_stack();
	ubi_dbg_dump_stack();
	return 1;
	return -EINVAL;
}
}


/**
/**
@@ -1164,8 +1164,8 @@ fail:
 * @ubi: UBI device description object
 * @ubi: UBI device description object
 * @pnum: the physical eraseblock number to check
 * @pnum: the physical eraseblock number to check
 *
 *
 * This function returns zero if the erase counter header is all right, %1 if
 * This function returns zero if the erase counter header is all right and and
 * not, and a negative error code if an error occurred.
 * a negative error code if not or if an error occurred.
 */
 */
static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
{
{
@@ -1188,7 +1188,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
		ubi_err("paranoid check failed for PEB %d", pnum);
		ubi_err("paranoid check failed for PEB %d", pnum);
		ubi_dbg_dump_ec_hdr(ec_hdr);
		ubi_dbg_dump_ec_hdr(ec_hdr);
		ubi_dbg_dump_stack();
		ubi_dbg_dump_stack();
		err = 1;
		err = -EINVAL;
		goto exit;
		goto exit;
	}
	}


@@ -1206,7 +1206,7 @@ exit:
 * @vid_hdr: the volume identifier header to check
 * @vid_hdr: the volume identifier header to check
 *
 *
 * This function returns zero if the volume identifier header is all right, and
 * This function returns zero if the volume identifier header is all right, and
 * %1 if not.
 * %-EINVAL if not.
 */
 */
static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
				  const struct ubi_vid_hdr *vid_hdr)
				  const struct ubi_vid_hdr *vid_hdr)
@@ -1233,7 +1233,7 @@ fail:
	ubi_err("paranoid check failed for PEB %d", pnum);
	ubi_err("paranoid check failed for PEB %d", pnum);
	ubi_dbg_dump_vid_hdr(vid_hdr);
	ubi_dbg_dump_vid_hdr(vid_hdr);
	ubi_dbg_dump_stack();
	ubi_dbg_dump_stack();
	return 1;
	return -EINVAL;


}
}


@@ -1243,7 +1243,7 @@ fail:
 * @pnum: the physical eraseblock number to check
 * @pnum: the physical eraseblock number to check
 *
 *
 * This function returns zero if the volume identifier header is all right,
 * This function returns zero if the volume identifier header is all right,
 * %1 if not, and a negative error code if an error occurred.
 * and a negative error code if not or if an error occurred.
 */
 */
static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
{
{
@@ -1270,7 +1270,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
		ubi_err("paranoid check failed for PEB %d", pnum);
		ubi_err("paranoid check failed for PEB %d", pnum);
		ubi_dbg_dump_vid_hdr(vid_hdr);
		ubi_dbg_dump_vid_hdr(vid_hdr);
		ubi_dbg_dump_stack();
		ubi_dbg_dump_stack();
		err = 1;
		err = -EINVAL;
		goto exit;
		goto exit;
	}
	}


@@ -1289,8 +1289,8 @@ exit:
 * @len: the length of the region to check
 * @len: the length of the region to check
 *
 *
 * This function returns zero if only 0xFF bytes are present at offset
 * This function returns zero if only 0xFF bytes are present at offset
 * @offset of the physical eraseblock @pnum, %1 if not, and a negative error
 * @offset of the physical eraseblock @pnum, and a negative error code if not
 * code if an error occurred.
 * or if an error occurred.
 */
 */
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
{
{
@@ -1321,7 +1321,7 @@ fail:
	ubi_msg("hex dump of the %d-%d region", offset, offset + len);
	ubi_msg("hex dump of the %d-%d region", offset, offset + len);
	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
		       ubi->dbg_peb_buf, len, 1);
		       ubi->dbg_peb_buf, len, 1);
	err = 1;
	err = -EINVAL;
error:
error:
	ubi_dbg_dump_stack();
	ubi_dbg_dump_stack();
	mutex_unlock(&ubi->dbg_buf_mutex);
	mutex_unlock(&ubi->dbg_buf_mutex);
+4 −7
Original line number Original line Diff line number Diff line
@@ -974,11 +974,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
			seb->ec = si->mean_ec;
			seb->ec = si->mean_ec;


	err = paranoid_check_si(ubi, si);
	err = paranoid_check_si(ubi, si);
	if (err) {
	if (err)
		if (err > 0)
			err = -EINVAL;
		goto out_vidh;
		goto out_vidh;
	}


	ubi_free_vid_hdr(ubi, vidh);
	ubi_free_vid_hdr(ubi, vidh);
	kfree(ech);
	kfree(ech);
@@ -1086,8 +1083,8 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
 * @ubi: UBI device description object
 * @ubi: UBI device description object
 * @si: scanning information
 * @si: scanning information
 *
 *
 * This function returns zero if the scanning information is all right, %1 if
 * This function returns zero if the scanning information is all right, and a
 * not and a negative error code if an error occurred.
 * negative error code if not or if an error occurred.
 */
 */
static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
{
{
@@ -1346,7 +1343,7 @@ bad_vid_hdr:


out:
out:
	ubi_dbg_dump_stack();
	ubi_dbg_dump_stack();
	return 1;
	return -EINVAL;
}
}


#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
+8 −9
Original line number Original line Diff line number Diff line
@@ -464,7 +464,7 @@ retry:
				   ubi->peb_size - ubi->vid_hdr_aloffset);
				   ubi->peb_size - ubi->vid_hdr_aloffset);
	if (err) {
	if (err) {
		ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum);
		ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum);
		return err > 0 ? -EINVAL : err;
		return err;
	}
	}


	return e->pnum;
	return e->pnum;
@@ -513,7 +513,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
	dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec);
	dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec);


	err = paranoid_check_ec(ubi, e->pnum, e->ec);
	err = paranoid_check_ec(ubi, e->pnum, e->ec);
	if (err > 0)
	if (err)
		return -EINVAL;
		return -EINVAL;


	ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
	ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
@@ -1572,8 +1572,7 @@ void ubi_wl_close(struct ubi_device *ubi)
 * @ec: the erase counter to check
 * @ec: the erase counter to check
 *
 *
 * This function returns zero if the erase counter of physical eraseblock @pnum
 * This function returns zero if the erase counter of physical eraseblock @pnum
 * is equivalent to @ec, %1 if not, and a negative error code if an error
 * is equivalent to @ec, and a negative error code if not or if an error occurred.
 * occurred.
 */
 */
static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
{
{
@@ -1611,8 +1610,8 @@ out_free:
 * @e: the wear-leveling entry to check
 * @e: the wear-leveling entry to check
 * @root: the root of the tree
 * @root: the root of the tree
 *
 *
 * This function returns zero if @e is in the @root RB-tree and %1 if it is
 * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it
 * not.
 * is not.
 */
 */
static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
				     struct rb_root *root)
				     struct rb_root *root)
@@ -1623,7 +1622,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
	ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ",
	ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ",
		e->pnum, e->ec, root);
		e->pnum, e->ec, root);
	ubi_dbg_dump_stack();
	ubi_dbg_dump_stack();
	return 1;
	return -EINVAL;
}
}


/**
/**
@@ -1632,7 +1631,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
 * @ubi: UBI device description object
 * @ubi: UBI device description object
 * @e: the wear-leveling entry to check
 * @e: the wear-leveling entry to check
 *
 *
 * This function returns zero if @e is in @ubi->pq and %1 if it is not.
 * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not.
 */
 */
static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
{
{
@@ -1647,6 +1646,6 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
	ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue",
	ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue",
		e->pnum, e->ec);
		e->pnum, e->ec);
	ubi_dbg_dump_stack();
	ubi_dbg_dump_stack();
	return 1;
	return -EINVAL;
}
}
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */