/* This function returns zero in case of success and a negative error code in case of failure.  */
int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum)
/* This function returns zero in case of success and a negative error code in case of failure.  */
int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum)
{
	int err;
	struct mtd_info *mtd = ubi->mtd;
	ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
	if (ubi->ro_mode) {
		ubi_err("read-only mode");
		return -EROFS;
	}
	if (!ubi->bad_allowed)
		return 0;
	err = mtd->block_markbad(mtd, (loff_t)pnum * ubi->peb_size);
	if (err)
		ubi_err("cannot mark PEB %d bad, error %d", pnum, err);
	return err;
}