[MTD] NAND: Move the NULL check into the calling function
[safe/jmp/linux-2.6] / drivers / mtd / nand / nand_base.c
index 422c465..02e58f5 100644 (file)
@@ -59,7 +59,7 @@
  *     The AG-AND chips have nice features for speed improvement,
  *     which are not supported yet. Read / program 4 pages in one go.
  *
- * $Id: nand_base.c,v 1.137 2005/03/24 14:33:22 dedekind Exp $
+ * $Id: nand_base.c,v 1.140 2005/04/04 18:56:29 gleixner Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -1060,8 +1060,8 @@ out:
  */
 static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf)
 {
-       return nand_do_read_ecc (mtd, from, len, retlen, buf, NULL, NULL, 0xff);
-}                         
+       return nand_do_read_ecc (mtd, from, len, retlen, buf, NULL, &mtd->oobinfo, 0xff);
+}
 
 
 /**
@@ -1079,6 +1079,9 @@ static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * re
 static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
                          size_t * retlen, u_char * buf, u_char * oob_buf, struct nand_oobinfo *oobsel)
 {
+       /* use userspace supplied oobinfo, if zero */
+       if (oobsel == NULL)
+               oobsel = &mtd->oobinfo;
        return nand_do_read_ecc(mtd, from, len, retlen, buf, oob_buf, oobsel, 0xff);
 }
 
@@ -1090,7 +1093,7 @@ static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
  * @len:       number of bytes to read
  * @retlen:    pointer to variable to store the number of read bytes
  * @buf:       the databuffer to put data
- * @oob_buf:   filesystem supplied oob data buffer
+ * @oob_buf:   filesystem supplied oob data buffer (can be NULL)
  * @oobsel:    oob selection structure
  * @flags:     flag to indicate if nand_get_device/nand_release_device should be preformed
  *             and how many corrected error bits are acceptable:
@@ -1103,6 +1106,7 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
                             size_t * retlen, u_char * buf, u_char * oob_buf, 
                             struct nand_oobinfo *oobsel, int flags)
 {
+
        int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1;
        int read = 0, oob = 0, ecc_status = 0, ecc_failed = 0;
        struct nand_chip *this = mtd->priv;
@@ -1130,10 +1134,6 @@ int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len,
        if (flags & NAND_GET_DEVICE)
                nand_get_device (this, mtd, FL_READING);
 
-       /* use userspace supplied oobinfo, if zero */
-       if (oobsel == NULL)
-               oobsel = &mtd->oobinfo;
-       
        /* Autoplace of oob data ? Use the default placement scheme */
        if (oobsel->useecc == MTD_NANDECC_AUTOPLACE)
                oobsel = this->autooob;
@@ -2512,12 +2512,9 @@ int nand_scan (struct mtd_info *mtd, int maxchips)
        
        /* The number of bytes available for the filesystem to place fs dependend
         * oob data */
-       if (this->options & NAND_BUSWIDTH_16) {
-               mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 2);
-               if (this->autooob->eccbytes & 0x01)
-                       mtd->oobavail--;
-       } else
-               mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 1);
+       mtd->oobavail = 0;
+       for (i = 0; this->autooob->oobfree[i][1]; i++)
+               mtd->oobavail += this->autooob->oobfree[i][1];
 
        /* 
         * check ECC mode, default to software