Commit Graph

4617 Commits

Author SHA1 Message Date
Ezequiel García
d2f08c7521 nand: omap2: Replace pr_err with dev_err
Usage of pr_err is frowned upon, so replace it with dev_err.

Acked-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-22 11:38:18 -07:00
Ezequiel García
93af53b863 nand: omap2: Remove horrible ifdefs to fix module probe
The current code abuses ifdefs to determine if the selected ECC scheme
is supported by the running kernel. As a result the code is hard to read,
and it also fails to load as a module.

This commit removes all the ifdefs and instead introduces a function
omap2_nand_ecc_check() to check if the ECC is supported by using
IS_ENABLED(CONFIG_xxx).

Since IS_ENABLED() is true when a config is =y or =m, this change fixes the
module so it can be loaded with no issues.

Acked-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-22 11:37:51 -07:00
Boris BREZILLON
2a960cce03 mtd: nand: add Hynix's H27UCG8T2ATR-BC to nand_ids table
Add the full description of the Hynix H27UCG8T2ATR-BC NAND chip in the
nand_ids table so that we can later use the NAND ECC infos and ONFI timings
mode in controller drivers.

Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-22 11:31:40 -07:00
Boris BREZILLON
57a94e24bc mtd: nand: support ONFI timing mode retrieval for non-ONFI NANDs
Add an onfi_timing_mode_default field to nand_chip and nand_flash_dev in
order to support NAND timings definition for non-ONFI NAND.

NAND that support better timings mode than the default one have to define
a new entry in the nand_ids table.

The default timing mode should be deduced from timings description from
the datasheet and the ONFI specification
(www.onfi.org/~/media/ONFI/specs/onfi_3_1_spec.pdf, chapter 4.15
"Timing Parameters").
You should choose the closest mode that fit the timings requirements of
your NAND chip.

Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-22 11:29:57 -07:00
Aaron Sierra
e5bffb59cf mtd: physmap_of: Add non-obsolete map_rom probe
Previously, the only way to map a NOR device as a simple ROM was to
use the obsolete "direct-mapped" compatible binding (which further
requires device_type = "nor" and probe-type = "NOR" properties).

This patch adds an "mtd-rom" compatible binding to the "map_rom"
probe type.

Signed-off-by: Aaron Sierra <asierra@xes-inc.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-22 10:13:13 -07:00
Aaron Sierra
9b07a8d1ab mtd: physmap_of: Fix ROM support via OF
The "ROM" and unknown probe types within the obsolete "direct-mapped"
probe function used the nonexistent "mtd_rom" probe instead of the
intended "map_rom".

Signed-off-by: Aaron Sierra <asierra@xes-inc.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-22 10:13:11 -07:00
Masahiro Yamada
8125450cd8 mtd: denali: fix indents and other trivial things
- Fix indents
- Do not break a line unless it is longer than 80 columns
- Do not insert a whitespace before ';'
- Use whitespaces around operators
- Use braces for a "else" block where the "if" block uses ones.

Besides, eliminate all the warnings reported by checkpatch.pl:
- WARNING: quoted string split across lines
- WARNING: else is not generally useful after a break or return
- WARNING: Missing a blank line after declarations
- WARNING: Avoid line continuations in quoted strings

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-19 09:39:27 -07:00
Masahiro Yamada
7d14ecd050 mtd: denali: remove unnecessary parentheses
We should use parentheses only when they are necessary
or they really improve the readability.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-19 09:39:26 -07:00
Brian Norris
ba5f2bc2af mtd: denali: remove another set-but-unused variable
The variable "irq_status" in denali_read_page_raw() is set, but not used.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-19 09:38:54 -07:00
Masahiro Yamada
a81b470883 mtd: denali: fix include guard and license block of denali.h
It looks like this header file is a concatenation of two headers.
Anyway, the include guard should be renamed and placed at the correct
postion and the license block in the middle should be deleted.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:32:30 -07:00
Rafał Miłecki
2ac63d901b mtd: nand: don't break long print messages
This follows Chapter 2 of Linux's CodingStyle:
> However, never break user-visible strings such as printk messages,
> because that breaks the ability to grep for them.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:29:36 -07:00
Rafał Miłecki
b7ab610f62 mtd: bcm47xxnflash: replace some magic numbers
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:25:03 -07:00
Rafał Miłecki
dfbd7dda0b mtd: bcm47xxnflash: NAND_CMD_RESET support
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:25:01 -07:00
Rafał Miłecki
90de63324f mtd: bcm47xxnflash: add cmd_ctrl handler
This won't be used by NAND subsystem as we implement cmdfunc on our
own, but will allow us to write a bit cleaner code.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:25:00 -07:00
Rafał Miłecki
5282a3acbf mtd: bcm47xxnflash: add dev_ready and fill chip_delay
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:23:24 -07:00
Rafał Miłecki
785e5e111f mtd: bcm47xxnflash: fix typo in freq calculation
We are supposed to mask value, not multiply it. Add some comments btw.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:18:50 -07:00
Rafał Miłecki
024629fdca mtd: bcm47xxpart: find NVRAM partitions in middle blocks
Old devices used to have NVRAM at the very end of flash and they could
be unaligned (starting at some offset in a block).
In new devices NVRAM can be located quite randomly, however it seems to
always start at the beginning of a block. For example Netgear R6250 has
NVRAM located right after the bootloader, before the kernel partition.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:15:38 -07:00
Wu, Josh
022a478ce6 mtd: atmel_nand: remove pmecc_bytes_per_sector, use chip->ecc.bytes instead
For PMECC, the pmecc_bytes_per_sector has same meaning as ecc.bytes.
So remove pmecc_bytes_per_sector and use ecc.bytes instead.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:05:11 -07:00
Wu, Josh
c9447fff34 mtd: atmel_nand: remove pmecc_sector_number, use ecc.steps instead
For PMECC, the pmecc_sector_number has same meaning as ecc.steps.
So use ecc.steps to replace the pmecc_sector_number.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 23:05:10 -07:00
Ezequiel García
fef775caa7 nand: omap2: Add support for flash-based bad block table
This commit adds a new platform-data boolean property that enables use
of a flash-based bad block table. This can also be enabled by setting
the 'nand-on-flash-bbt' devicetree property.

If the flash BBT is not enabled, the driver falls back to use OOB
bad block markers only, as before. If the flash BBT is enabled the
kernel will keep track of bad blocks using a BBT, in addition to
the OOB markers.

As explained by Brian Norris the reasons for using a BBT are:

""
The primary reason would be that NAND datasheets specify it these days.
A better argument is that nobody guarantees that you can write a
bad block marker to a worn out block; you may just get program failures.

This has been acknowledged by several developers over the last several
years.

Additionally, you get a boot-time performance improvement if you only
have to read a few pages, instead of a page or two from every block on
the flash.
""

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Acked-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 01:02:48 -07:00
Boris BREZILLON
2d405ec5fd mtd: nand: atmel_nand: retrieve NFC clock
Retrieve the NFC clock to make sure it is enabled. Make that optional to ensure
compatibility with previous device trees but document it as mandatory so newer
device trees will include it.

Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Josh Wu <josh.wu@atmel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-17 00:45:11 -07:00
Masahiro Yamada
55ab9ec99b mtd: denali: remove a set-but-unused variable
The variable "retry" in wait_for_irq() is set, but not used.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-15 16:31:24 -07:00
Masahiro Yamada
93e3c8adf6 mtd: denali: change the type of iterators to int
We should rathar use "int" type for loop iterators.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-15 16:31:19 -07:00
Masahiro Yamada
3157d1ed23 mtd: denali: remove unnecessary casts
Useless casts result in unreadable source code.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-15 16:31:16 -07:00
Masahiro Yamada
5637b69d1c mtd: denali: remove unnecessary variable initializations
All of these variables are initialized to zero and then
set to a different value below.
Zero-initializing is redundant.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-15 16:31:03 -07:00
Masahiro Yamada
43914a2dcc mtd: denali: fix the format of comment blocks
We should use
/*
 * Blah Blah ...
 * ...
 */

for multi-line comment blocks.

In addition, refactor some comments where it seems reasonable and
remove some comments where the code is clear enough such as:

    /* clear interrupts */
    clear_interrupts(denali);

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-09-15 16:30:57 -07:00
Brian Norris
7622d4905a Linux 3.17-rc5
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQEcBAABAgAGBQJUFjfVAAoJEHm+PkMAQRiGANkIAIU3PNrAz9dIItq8a/rEAhnx
 l2shHoOyEmyNR2apholM3BPUNX50cbsc/HGdi7lZKLkA/ifAj6B9nFD2NzVsIChD
 1QWVcvdkKlVuxXCDd26qbijlfmbTOAWrLw9ntvM+J6ZtECM6zCAZF4MAV/FwogPq
 ETGKD76AxJtVIhBMS99troAiC1YxmQ7DKgEr8CraTOR1qwXEonnPCmN/IZA6x2/G
 EXiihOuQB5me1X7k4PI0V8CDscQOn+3B2CQHIrjRB+KiTF+iKIuI8n6ORC6bpFh+
 U8UZP9wLlIG1BrUHG83pIndglIHotqPcjmtfl1WGrRr2hn7abzVSfV+g5Syo3Vg=
 =Ep+s
 -----END PGP SIGNATURE-----

Merge tag 'v3.17-rc5' from upstream
2014-09-15 16:28:16 -07:00
Linus Torvalds
925e0ea47c Two trivial MTD updates for 3.17-rc4:
* A tiny comment tweak, to kill a bunch of DocBook warnings added during the
    merge window
 
  * A small fixup to the OTP routines' error handling
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQIcBAABAgAGBQJUCkvYAAoJEFySrpd9RFgtoyQP/3xE3ZPOU/6F80VVAVZZqCNa
 rUaaaB+Y25B+2ust2mWWv6hPSDsLOJdcbv5w2aR1PlcjUNuqp+hW+E61BQUEUAwl
 9Rb8GRcduCBgsawv6jYlAgGCN/p8YMNgpdelpDp6OFLwCXrimH/46ZBi9m9vuoO+
 /RqTQT2ZTisqISCApw73l0Cjbne7tIW4ttZ1E0WcREG8egxFTn9uzZ2qA58/QAvD
 3kPfMnmrysBBXIk9w7izSFQV3jXl1amIDL+vHvafo2+0yu/f89Yc+esDp0swSYjF
 ZQrfVLoYbgN3B4utveYxZkkdljBCD3CQRFlOCi3CBiwEqpxQnO4D+F9gUzxGBpYr
 K9DAKlvmqFD3T5fWAwWaQItEu9fJBXRIjOY5Eb7UhXULhWXkN7/VNuWA5qmrydgi
 ZSX7LaRKwdDDHPrrgjBCIS3k5KXFO/VbWIoVsqya8OHMgWbMvv3EWZD8V3hnosus
 OBiAerglNBq658w8H3rKhlhBP5+VxRUJoxlrkHBNeNHlnMD1g4kbt8/SvUKy9jy8
 VKBBiW7MhpfqXbsKjapXzXSNtx5awQU3qFEoo9Jtjs7dFDs90744Zb+T9EaOLKYP
 Y0m+uXooWvhOJEQ9YYCclneizQYKJNpCvgL3tgEIG74UZkquxOc4ecgDwCca2PWK
 Xr7G2kRBInCRTegQBFB6
 =7uT9
 -----END PGP SIGNATURE-----

Merge tag 'for-linus-20140905' of git://git.infradead.org/linux-mtd

Pull mtd fixes from Brian Norris:
 "Two trivial MTD updates for 3.17-rc4:

   - a tiny comment tweak, to kill a bunch of DocBook warnings added
     during the merge window

   - a small fixup to the OTP routines' error handling"

* tag 'for-linus-20140905' of git://git.infradead.org/linux-mtd:
  mtd: nand: fix DocBook warnings on nand_sdr_timings doc
  mtd: cfi_cmdset_0002: check return code for get_chip()
2014-09-06 12:12:09 -07:00
Roger Quadros
40ddbf5069 mtd: nand: omap: Fix 1-bit Hamming code scheme, omap_calculate_ecc()
commit 65b97cf6b8 introduced in v3.7 caused a regression
by using a reversed CS_MASK thus causing omap_calculate_ecc to
always fail. As the NAND base driver never checks for .calculate()'s
return value, the zeroed ECC values are used as is without showing
any error to the user. However, this won't work and the NAND device
won't be guarded by any error code.

Fix the issue by using the correct mask.

Code was tested on omap3beagle using the following procedure
- flash the primary bootloader (MLO) from the kernel to the first
NAND partition using nandwrite.
- boot the board from NAND. This utilizes OMAP ROM loader that
relies on 1-bit Hamming code ECC.

Fixes: 65b97cf6b8 (mtd: nand: omap2: handle nand on gpmc)

Cc: <stable@vger.kernel.org>	[3.7+]
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
2014-08-25 16:15:33 -07:00
Roger Quadros
7d5929c1f3 mtd: nand: omap: Revert to using software ECC by default
For v3.12 and prior, 1-bit Hamming code ECC via software was the
default choice. Commit c66d039197 in v3.13 changed the behaviour
to use 1-bit Hamming code via Hardware using a different ECC layout
i.e. (ROM code layout) than what is used by software ECC.

This ECC layout change causes NAND filesystems created in v3.12
and prior to be unusable in v3.13 and later. So revert back to
using software ECC by default if an ECC scheme is not explicitely
specified.

This defect can be observed on the following boards during legacy boot

-omap3beagle
-omap3touchbook
-overo
-am3517crane
-devkit8000
-ldp
-3430sdp

Signed-off-by: Roger Quadros <rogerq@ti.com>
Tested-by: Grazvydas Ignotas <notasas@gmail.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
2014-08-25 16:15:32 -07:00
Brian Norris
5b49ab3e03 Merge l2-mtd/next into l2-mtd/master 2014-08-19 11:57:23 -07:00
Rafał Miłecki
54ea17a597 mtd: spi-nor: drop jedec_probe /helper/ function
It's a one-liner doing no magic and its name may be confusing because
it does not have to use JEDEC (e.g. when using alternative read_id).

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Acked-by: Huang Shijie <shijie8@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:10 -07:00
Rafał Miłecki
ab75e89c01 mtd: spi-nor: remove duplicated w25q128 entry
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Acked-by: Huang Shijie <shijie8@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:10 -07:00
Aaron Wu
02f8a24e7b mtd: gpio_flash: handle case where offset + len exceeds the window size
Fix the bug in handling gpio flash read/write when offset + len
from MTD exceeds the window size

Signed-off-by: Aaron Wu <Aaron.wu@analog.com>

[Brian: made some commentary edits. Also note that the BUG_ON() was
provably false for all non-negative inputs (since x % y <= x), so we
dropped it.]

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:10 -07:00
Geert Uytterhoeven
bd8898db3e mtd: nand: Use ULL-suffix for big u64 constant
drivers/mtd/nand/nand_timings.c:45: warning: integer constant is too large for ‘long’ type

[ Editorial note: This is a false warning. Looking at ISO draft N1124
    (this is approximately C11, the first PDF I had lying around),
    section 6.4.4.1 (statement 5):

       "The type of an integer constant is the first of the
        corresponding list in which its value can be represented."

    So this should not be an overflow, and any toolchain that says so
    (e.g., GCC 4.4) is buggy.

       -Brian ]

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:09 -07:00
Wu, Josh
ff0a215438 mtd: atmel_nand: NFC: fix mtd_nandbiterrs.ko test fail when using sram write
When enable NFC sram write, it will failed the mtd_nandbiterrs.ko test.

As in driver's nfc_sram_write_page(), if ops->mode equal to MTD_OSP_RAW,
driver assumes the data buffer contains one page data and one oob data
followed. And driver will write the page data and oob data to nand.

But this is wrong implementation. Since the data buffer don't contains the
oob data to write. We should write the chip->oob_poi to nand's oob.

So this patch fix it by writing the oob data from chip->oob_poi.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:09 -07:00
Brian Norris
1cc8d84133 mtd: terminate user-provided string
Noticed by Coverity as a potential security issue.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:09 -07:00
Brian Norris
537ab1bd47 mtd: nand: fix integer widening problems
chip->pagebuf is a 32-bit type (int), so the shift will only be applied
as 32-bit. Fix this for 64-bit safety.

Caught by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:09 -07:00
Brian Norris
7a6f43958a mtd: maps: solutionengine: drop excess dependency
Already depends on SOLUTION_ENGINE, so we don't need the SUPERH
dependency too.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:09 -07:00
Brian Norris
b033e1aac9 mtd: nandsim: fix integer widening
This multiplication should be done in 64-bit, not 32-bit.

Caught by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:08 -07:00
Brian Norris
c115add9d0 mtd: nand: denali: set proper error code on timeout
The condition "if (irq_status == 0)" already ensures that one half of
the ternary ?: is dead. I think this should probably actually be a FAIL,
not a PASS.

Caught by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: Jamie Iles <jamie@jamieiles.com>
2014-08-19 11:53:08 -07:00
Brian Norris
31f754628c mtd: use __packed shorthand
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:08 -07:00
Brian Norris
1001ff7a4f mtd: tests: fix integer overflow issues
These multiplications are done with 32-bit arithmetic, then converted to
64-bit. We should widen the integers first to prevent overflow. This
could be a problem for large (>4GB) MTD's.

Detected by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: Akinobu Mita <akinobu.mita@gmail.com>
2014-08-19 11:53:08 -07:00
Brian Norris
8c3f3f1d79 mtd: mtdswap: fix integer overflow
Caught by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:08 -07:00
Brian Norris
5e47212831 mtd: remove dead non-char logic
MTD used to allow compiling out character device support. This was
dropped in the following commit, but some of the accompanying logic was
never dropped:

  commit 660685d9d1
  Author: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
  Date:   Thu Mar 14 13:27:40 2013 +0200

      mtd: merge mtdchar module with mtdcore

The weird logic was flagged by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2014-08-19 11:53:08 -07:00
Brian Norris
f7f0d358f5 mtd: sm_ftl: initialize error code
There is one theoretical case that could fall through to using an
uninitialized value as the return code. Let's give it a value of 0.

Untested.

Caught by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:07 -07:00
Brian Norris
0c2b4e2144 mtd: correct upper bounds check for mtd_*() APIs
When checking the upper boundary (i.e., whether an address is higher
than the maximum size of the MTD), we should be doing an inclusive check
(greater or equal). For instance, an address of 16MB (0x1000000) on a
16MB device is invalid.

The strengthening of this bounds check is redundant for those which
already have a address+length check and ensure that the length is
non-zero, but let's just fix them all, for completeness.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:07 -07:00
Brian Norris
36c6a7ac74 mtd: cfi_cmdset_0002: allow retry/timeout loop to exit
The variable 'retries' is never modified, so if the reset operation
never is going to complete, we'll get stuck in an infinite loop.

It looks like the intention was to decrement 'retries' on every loop.
Untested.

Caught by Coverity.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:07 -07:00
White Ding
57d3a9a89a mtd: nand: fix nand_lock/unlock() function
Do nand reset before write protect check.

If we want to check the WP# low or high through STATUS READ and check bit 7,
we must reset the device, other operation (eg.erase/program a locked block) can
also clear the bit 7 of status register.

As we know the status register can be refreshed, if we do some operation to trigger it,
for example if we do erase/program operation to one block that is locked, then READ STATUS,
the bit 7 of READ STATUS will be 0 indicate the device in write protect, then if we do
erase/program operation to another block that is unlocked, the bit 7 of READ STATUS will
be 1 indicate the device is not write protect.
Suppose we checked the bit 7 of READ STATUS is 0 then judge the WP# is low (write protect),
but in this case the WP# maybe high if we do erase/program operation to a locked block,
so we must reset the device if we want to check the WP# low or high through STATUS READ and
check bit 7.

Signed-off-by: White Ding <bpqw@micron.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:07 -07:00
Samarth Parikh
6f3c0f1631 mtd: Fixed checkpatch seq_printf warnings
Fixed checkpatch warnings: "WARNING: Prefer seq_puts to seq_printf"

This patch is created with reference to the ongoing lkml thread
https://lkml.org/lkml/2014/7/15/646
where Andrew Morton wrote:

"
- puts is presumably faster

- puts doesn't go rogue if you accidentally pass it a "%".

- this patch would actually make compiled object files few bytes smaller.
  Perhaps because seq_printf() is a varargs function, forcing the
  caller to pass args on the stack instead of in registers.
"

Signed-off-by: Samarth Parikh <samarthp@ymail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
2014-08-19 11:53:07 -07:00