/* This function erases physical eraseblock 'pnum', and writes the erase counter header to it. This function should only be used on UBI device initialization stages, when the EBA unit had not been yet initialized. This function returns zero in case of success and a negative error code in case of failure.  */
int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, int pnum, int ec)
/* This function erases physical eraseblock 'pnum', and writes the erase counter header to it. This function should only be used on UBI device initialization stages, when the EBA unit had not been yet initialized. This function returns zero in case of success and a negative error code in case of failure.  */
int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, int pnum, int ec)
{
	int err;
	struct ubi_ec_hdr *ec_hdr;
	if ((long long)ec >= UBI_MAX_ERASECOUNTER) {
		ubi_err("erase counter overflow at PEB %d, EC %d", pnum, ec);
		return -EINVAL;
	}
	ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
	if (!ec_hdr)
		return -ENOMEM;
	ec_hdr->ec = cpu_to_be64(ec);
	err = ubi_io_sync_erase(ubi, pnum, 0);
	if (err < 0)
		goto out_free;
	err = ubi_io_write_ec_hdr(ubi, pnum, ec_hdr);
out_free:
	kfree(ec_hdr);
	return err;
}