mtd: add offset and length checks to the API function