static int check_offs_len(struct mtd_info *mtd,
                                        loff_t ofs, uint64_t len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret = 0;
 
        /* Start address must align on block boundary */
  */
 static void nand_release_device(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Release the controller and the chip */
        spin_lock(&chip->controller->lock);
  */
 static uint8_t nand_read_byte(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        return readb(chip->IO_ADDR_R);
 }
 
  */
 static uint8_t nand_read_byte16(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        return (uint8_t) cpu_to_le16(readw(chip->IO_ADDR_R));
 }
 
  */
 static u16 nand_read_word(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        return readw(chip->IO_ADDR_R);
 }
 
  */
 static void nand_select_chip(struct mtd_info *mtd, int chipnr)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        switch (chipnr) {
        case -1:
  */
 static void nand_write_byte(struct mtd_info *mtd, uint8_t byte)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        chip->write_buf(mtd, &byte, 1);
 }
  */
 static void nand_write_byte16(struct mtd_info *mtd, uint8_t byte)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint16_t word = byte;
 
        /*
  */
 static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        iowrite8_rep(chip->IO_ADDR_W, buf, len);
 }
  */
 static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        ioread8_rep(chip->IO_ADDR_R, buf, len);
 }
  */
 static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u16 *p = (u16 *) buf;
 
        iowrite16_rep(chip->IO_ADDR_W, p, len >> 1);
  */
 static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u16 *p = (u16 *) buf;
 
        ioread16_rep(chip->IO_ADDR_R, p, len >> 1);
 static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
 {
        int page, chipnr, res = 0, i = 0;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        u16 bad;
 
        if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
  */
 static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mtd_oob_ops ops;
        uint8_t buf[2] = { 0, 0 };
        int ret = 0, res, i = 0;
 */
 static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int res, ret = 0;
 
        if (!(chip->bbt_options & NAND_BBT_NO_OOB_BBM)) {
  */
 static int nand_check_wp(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Broken xD cards report WP despite being writable */
        if (chip->options & NAND_BROKEN_XD)
  */
 static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (!chip->bbt)
                return 0;
 static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip,
                               int allowbbt)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (!chip->bbt)
                return chip->block_bad(mtd, ofs, getchip);
  */
 static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int i;
 
        /* Wait for the device to get ready */
  */
 void nand_wait_ready(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        unsigned long timeo = 400;
 
        if (in_interrupt() || oops_in_progress)
  */
 static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo)
 {
-       register struct nand_chip *chip = mtd->priv;
+       register struct nand_chip *chip = mtd_to_nand(mtd);
 
        timeo = jiffies + msecs_to_jiffies(timeo);
        do {
 static void nand_command(struct mtd_info *mtd, unsigned int command,
                         int column, int page_addr)
 {
-       register struct nand_chip *chip = mtd->priv;
+       register struct nand_chip *chip = mtd_to_nand(mtd);
        int ctrl = NAND_CTRL_CLE | NAND_CTRL_CHANGE;
 
        /* Write out the command to the device */
 static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
                            int column, int page_addr)
 {
-       register struct nand_chip *chip = mtd->priv;
+       register struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Emulate NAND_CMD_READOOB */
        if (command == NAND_CMD_READOOB) {
 static int
 nand_get_device(struct mtd_info *mtd, int new_state)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        spinlock_t *lock = &chip->controller->lock;
        wait_queue_head_t *wq = &chip->controller->wq;
        DECLARE_WAITQUEUE(wait, current);
 {
        int ret = 0;
        int status, page;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /* Submit address of first page to unlock */
        page = ofs >> chip->page_shift;
 {
        int ret = 0;
        int chipnr;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
                        __func__, (unsigned long long)ofs, len);
 {
        int ret = 0;
        int chipnr, status, page;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
                        __func__, (unsigned long long)ofs, len);
  */
 static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("setting READ RETRY mode %d\n", retry_mode);
 
                            struct mtd_oob_ops *ops)
 {
        int chipnr, page, realpage, col, bytes, aligned, oob_required;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        int ret = 0;
        uint32_t readlen = ops->len;
        uint32_t oobreadlen = ops->ooblen;
                            struct mtd_oob_ops *ops)
 {
        int page, realpage, chipnr;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mtd_ecc_stats stats;
        int readlen = ops->ooblen;
        int len;
 static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len,
                              struct mtd_oob_ops *ops)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        /*
         * Initialise to all 0xFF, to avoid the possibility of left over OOB
                             struct mtd_oob_ops *ops)
 {
        int chipnr, realpage, page, blockmask, column;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint32_t writelen = ops->len;
 
        uint32_t oobwritelen = ops->ooblen;
 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
                            size_t *retlen, const uint8_t *buf)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct mtd_oob_ops ops;
        int ret;
 
                             struct mtd_oob_ops *ops)
 {
        int chipnr, page, status, len;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        pr_debug("%s: to = 0x%08x, len = %i\n",
                         __func__, (unsigned int)to, (int)ops->ooblen);
  */
 static int single_erase(struct mtd_info *mtd, int page)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        /* Send commands to erase a block */
        chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
        chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
                    int allowbbt)
 {
        int page, status, pages_per_block, ret, chipnr;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        loff_t len;
 
        pr_debug("%s: start = 0x%012llx, len = %llu\n",
  */
 static void nand_resume(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (chip->state == FL_PM_SUSPENDED)
                nand_release_device(mtd);
 
 static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        uint8_t feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode};
 
        return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY,
                    struct nand_flash_dev *table)
 {
        int i, nand_maf_id, nand_dev_id;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_flash_dev *type;
        int ret;
 
  */
 static bool nand_ecc_strength_good(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        int corr, ds_corr;
 
 int nand_scan_tail(struct mtd_info *mtd)
 {
        int i;
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        struct nand_buffers *nbuf;
 
  */
 void nand_release(struct mtd_info *mtd)
 {
-       struct nand_chip *chip = mtd->priv;
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
        if (chip->ecc.mode == NAND_ECC_SOFT_BCH)
                nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
 
                struct nand_bbt_descr *td, int offs)
 {
        int res, ret = 0, i, j, act = 0;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        size_t retlen, len, totlen;
        loff_t from;
        int bits = td->options & NAND_BBT_NRBITS_MSK;
  */
 static int read_abs_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td, int chip)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int res = 0, i;
 
        if (td->options & NAND_BBT_PERCHIP) {
 static void read_abs_bbts(struct mtd_info *mtd, uint8_t *buf,
                          struct nand_bbt_descr *td, struct nand_bbt_descr *md)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        /* Read the primary version, if available */
        if (td->options & NAND_BBT_VERSION) {
 static int create_bbt(struct mtd_info *mtd, uint8_t *buf,
        struct nand_bbt_descr *bd, int chip)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int i, numblocks, numpages;
        int startblock;
        loff_t from;
  */
 static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *td)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int i, chips;
        int startblock, block, dir;
        int scanlen = mtd->writesize + mtd->oobsize;
                     struct nand_bbt_descr *td, struct nand_bbt_descr *md,
                     int chipsel)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct erase_info einfo;
        int i, res, chip = 0;
        int bits, startblock, dir, page, offs, numblocks, sft, sftmsk;
  */
 static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
 
        return create_bbt(mtd, this->buffers->databuf, bd, -1);
 }
 static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd)
 {
        int i, chips, writeops, create, chipsel, res, res2;
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        struct nand_bbt_descr *td = this->bbt_td;
        struct nand_bbt_descr *md = this->bbt_md;
        struct nand_bbt_descr *rd, *rd2;
  */
 static void mark_bbt_region(struct mtd_info *mtd, struct nand_bbt_descr *td)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int i, j, chips, block, nrblocks, update;
        uint8_t oldval;
 
  */
 static void verify_bbt_descr(struct mtd_info *mtd, struct nand_bbt_descr *bd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        u32 pattern_len;
        u32 bits;
        u32 table_size;
  */
 static int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int len, res;
        uint8_t *buf;
        struct nand_bbt_descr *td = this->bbt_td;
  */
 static int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int len, res = 0;
        int chip, chipsel;
        uint8_t *buf;
  */
 int nand_default_bbt(struct mtd_info *mtd)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int ret;
 
        /* Is a flash based bad block table requested? */
  */
 int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int block;
 
        block = (int)(offs >> this->bbt_erase_shift);
  */
 int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int block, res;
 
        block = (int)(offs >> this->bbt_erase_shift);
  */
 int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs)
 {
-       struct nand_chip *this = mtd->priv;
+       struct nand_chip *this = mtd_to_nand(mtd);
        int block, ret = 0;
 
        block = (int)(offs >> this->bbt_erase_shift);