summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
AgeCommit message (Collapse)AuthorLines
12 daysConvert remaining multi-line kmalloc_obj/flex GFP_KERNEL usesKees Cook-6/+6
Conversion performed via this Coccinelle script: // SPDX-License-Identifier: GPL-2.0-only // Options: --include-headers-for-types --all-includes --include-headers --keep-comments virtual patch @gfp depends on patch && !(file in "tools") && !(file in "samples")@ identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex, kzalloc_obj,kzalloc_objs,kzalloc_flex, kvmalloc_obj,kvmalloc_objs,kvmalloc_flex, kvzalloc_obj,kvzalloc_objs,kvzalloc_flex}; @@ ALLOC(... - , GFP_KERNEL ) $ make coccicheck MODE=patch COCCI=gfp.cocci Build and boot tested x86_64 with Fedora 42's GCC and Clang: Linux version 6.19.0+ (user@host) (gcc (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7), GNU ld version 2.44-12.fc42) #1 SMP PREEMPT_DYNAMIC 1970-01-01 Linux version 6.19.0+ (user@host) (clang version 20.1.8 (Fedora 20.1.8-4.fc42), LLD 20.1.8) #1 SMP PREEMPT_DYNAMIC 1970-01-01 Signed-off-by: Kees Cook <kees@kernel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
13 daysConvert more 'alloc_obj' cases to default GFP_KERNEL argumentsLinus Torvalds-24/+12
This converts some of the visually simpler cases that have been split over multiple lines. I only did the ones that are easy to verify the resulting diff by having just that final GFP_KERNEL argument on the next line. Somebody should probably do a proper coccinelle script for this, but for me the trivial script actually resulted in an assertion failure in the middle of the script. I probably had made it a bit _too_ trivial. So after fighting that far a while I decided to just do some of the syntactically simpler cases with variations of the previous 'sed' scripts. The more syntactically complex multi-line cases would mostly really want whitespace cleanup anyway. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
13 daysConvert 'alloc_flex' family to use the new default GFP_KERNEL argumentLinus Torvalds-5/+5
This is the exact same thing as the 'alloc_obj()' version, only much smaller because there are a lot fewer users of the *alloc_flex() interface. As with alloc_obj() version, this was done entirely with mindless brute force, using the same script, except using 'flex' in the pattern rather than 'objs*'. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
13 daysConvert 'alloc_obj' family to use the new default GFP_KERNEL argumentLinus Torvalds-127/+127
This was done entirely with mindless brute force, using git grep -l '\<k[vmz]*alloc_objs*(.*, GFP_KERNEL)' | xargs sed -i 's/\(alloc_objs*(.*\), GFP_KERNEL)/\1)/' to convert the new alloc_obj() users that had a simple GFP_KERNEL argument to just drop that argument. Note that due to the extreme simplicity of the scripting, any slightly more complex cases spread over multiple lines would not be triggered: they definitely exist, but this covers the vast bulk of the cases, and the resulting diff is also then easier to check automatically. For the same reason the 'flex' versions will be done as a separate conversion. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
14 daystreewide: Replace kmalloc with kmalloc_obj for non-scalar typesKees Cook-192/+175
This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances: Single allocations: kmalloc(sizeof(TYPE), ...) are replaced with: kmalloc_obj(TYPE, ...) Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...) are replaced with: kmalloc_objs(TYPE, COUNT, ...) Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...) are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...) (where TYPE may also be *VAR) The resulting allocations no longer return "void *", instead returning "TYPE *". Signed-off-by: Kees Cook <kees@kernel.org>
2026-02-13Merge tag 'mtd/for-7.0' of ↵Linus Torvalds-167/+675
git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux Pull MTD updates from Miquel Raynal: "MTD: - prioritize ofpart in physmap-core probing - conversions to scoped for each OF child loops Bindings: - The bulk of the changes consists of binding fixes/updates to restrict the use of undefined properties, which was mostly ineffective in the current form because of the nesting of partition nodes and the lack of compatible strings - YAML conversions and the addition of a dma-coherent property in the cdns,hp-nfc driver SPI NAND: - support for octal DTR modes (8D-8D-8D) - support for Foresee F35SQB002G chips And small misc fixes" * tag 'mtd/for-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: (65 commits) mtd: spi-nor: hisi-sfc: fix refcounting bug in hisi_spi_nor_register_all() mtd: spinand: fix NULL pointer dereference in spinand_support_vendor_ops() mtd: rawnand: pl353: Add message about ECC mode mtd: rawnand: pl353: Fix software ECC support mtd: spinand: winbond: Remove unneeded semicolon dt-bindings: mtd: cdns,hp-nfc: Add dma-coherent property mtd: spinand: Disable continuous read during probe mtd: spinand: add Foresee F35SQB002G flash support mtd: spinand: winbond: W35N octal DTR support mtd: spinand: Add octal DTR support mtd: spinand: Warn if using SSDR-only vendor commands in a non SSDR mode mtd: spinand: Give the bus interface to the configuration helper mtd: spinand: Propagate the bus interface across core helpers mtd: spinand: Add support for setting a bus interface mtd: spinand: Gather all the bus interface steps in one single function mtd: spinand: winbond: Configure the IO mode after the dummy cycles mtd: spinand: winbond: Rename IO_MODE register macro mtd: spinand: winbond: Fix style mtd: spinand: winbond: Register W35N vendor specific operation mtd: spinand: winbond: Register W25N vendor specific operation ...
2026-02-13Merge tag 'nand/for-7.0' into mtd/nextMiquel Raynal-156/+653
SPI NAND - The major feature this release is the support for octal DTR modes (8D-8D-8D). - There has been as well a series of conversion to scoped for each OF child loops. - Support for Foresee F35SQB002G chips has been added. Other changes are small fixes.
2026-02-06mtd: spi-nor: hisi-sfc: fix refcounting bug in hisi_spi_nor_register_all()Dan Carpenter-1/+0
This was converted to a _scoped() loop but this of_node_put() was accidentally left behind which is a double free. Fixes: aa8cb72c2018 ("mtd: spi-nor: hisi-sfc: Simplify with scoped for each OF child loop") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-02-06mtd: spinand: fix NULL pointer dereference in spinand_support_vendor_ops()Md Sadre Alam-0/+2
The spinand_support_vendor_ops() helper unconditionally dereferences info->vendor_ops. For chips that do not define vendor_ops, this pointer is NULL, leading to a kernel panic during probe: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 Add a guard to return early when vendor_ops is NULL. This prevents the crash and allows SPI NAND devices without vendor-specific operations to be probed correctly. Fixes: fbc7538782f8 ("mtd: spinand: List vendor specific operations and make sure they are supported") Cc: stable@vger.kernel.org Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-02-05mtd: rawnand: pl353: Add message about ECC modeAndrea Scian-0/+3
This just add some information on kernel log about the selected ECC Signed-off-by: Andrea Scian <andrea.scian@dave.eu> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-02-05mtd: rawnand: pl353: Fix software ECC supportAndrea Scian-0/+1
We need to set also write_page_raw in ecc structure to allow choosing SW ECC instead of HW one, otherwise write operation fail. Fixes: 08d8c62164a322 ("mtd: rawnand: pl353: Add support for the ARM PL353 SMC NAND controller") Signed-off-by: Andrea Scian <andrea.scian@dave.eu> Cc: stable@kernel.org Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-02-03mtd: spinand: winbond: Remove unneeded semicolonChen Ni-1/+1
Remove unnecessary semicolons reported by Coccinelle/coccicheck and the semantic patch at scripts/coccinelle/misc/semicolon.cocci. Signed-off-by: Chen Ni <nichen@iscas.ac.cn> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-30mtd: spinand: Disable continuous read during probeDavid LaPorte-0/+8
Macronix serial NAND devices with continuous read support do not clear the configuration register on soft reset and lack a hardware reset pin. When continuous read is interrupted (e.g., during reboot), the feature remains enabled at the device level. With continuous read enabled, the OOB area becomes inaccessible and all reads are instead directed to the main area. As a result, during partition allocation as part of MTD device registration, the first two bytes of the main area for the master block are read and indicate that the block is bad. This process repeats for every subsequent block for the partition. All reads and writes that reference the BBT find no good blocks and fail. The only paths for recovery from this state are triggering the continuous read feature by way of raw MTD reads or through a NAND device power drain. Disable continuous read explicitly during spinand probe to ensure quiescent feature state. Fixes: 631cfdd0520d ("mtd: spi-nand: Add continuous read support") Cc: stable@vger.kernel.org Signed-off-by: David LaPorte <dalaport@amazon.com> Reviewed-by: Gunnar Kudrjavets <gunnarku@amazon.com> Reviewed-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29Merge tag 'mtd/fixes-for-6.19-rc8' of ↵Linus Torvalds-1/+1
git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux Pull MTD fix from Miquel Raynal: "A single late MTD fix, which reverts a fix that turned out to be incorrect. The observations of the committer was that the number of IDs to be used to probe a chip was incorrect. It happened to be a limitation of his controller, not a chip issue. Restore the chip description, a solution must be found somewhere else" * tag 'mtd/fixes-for-6.19-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: Revert "mtd: spinand: esmt: fix id code for F50D1G41LB"
2026-01-29mtd: spinand: add Foresee F35SQB002G flash supportMikhail Kshevetskiy-0/+34
Add support of Foresee F35SQB002G spinand flash Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: W35N octal DTR supportMiquel Raynal-2/+18
Extend the support for the W35N chip family by supporting the ODTR bus interface. The chip is capable to run in this mode, which brings a significant performance improvement. 1S-8S-8S: # flash_speed /dev/mtd0 -c1 -d eraseblock write speed is 7529 KiB/s eraseblock read speed is 15058 KiB/s 8D-8D-8D: # flash_speed /dev/mtd0 -c1 -d eraseblock write speed is 9481 KiB/s eraseblock read speed is 23272 KiB/s This is +55% read speed and +26% write speed with the same hardware. Tests have been conducted with a TI AM62A7 using the Cadence quad SPI controller. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Add octal DTR supportMiquel Raynal-1/+139
Create a new bus interface named ODTR for "octal DTR", which matches the following pattern: 8D-8D-8D. Add octal DTR support for all the existing core operations. Add a second set of templates for this bus interface. Give the possibility for drivers to register their read, write and update cache variants as well as their vendor specific operations. Check the SPI controller driver supports all the octal DTR commands that we might need before switching to the ODTR bus interface. Make the switch by calling ->configure_chip() with the ODTR parameter. Fallback in case this step fails. If someone ever attempts to suspend a chip in octal DTR mode, there are changes that it will loose its configuration at resume. Prevent any problem by explicitly switching back to SSDR while suspending. Note: there is a limitation in the current approach, page I/Os are not available as the dirmaps will be created for the ODTR bus interface if that option is supported and not switched back to SSDR during suspend. Switching them is possible but would be costly and would not bring anything as right after resuming we will switch again to ODTR. In case this capability is used for debug, developpers should mind to destroy and recreate suitable direct mappings. Finally, as a side effect, we increase the buffer for reading IDs to 6. No device at this point returns 6 bytes, but we support 5 bytes IDs, which means in octal DTR mode we have no other choice than reading an even number of bytes, hence 6. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Warn if using SSDR-only vendor commands in a non SSDR modeMiquel Raynal-0/+4
Both Macronix and Winbond have chip specific operations which are SSDR only. Trying to use them in an ODTR setup will fail and doing this is a pure software bug. Warn explicitly in this case. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Give the bus interface to the configuration helperMiquel Raynal-8/+22
The chip configuration hook is the one responsible to actually switch the switch between bus interfaces. It is natural to give it the bus interface we expect with a new parameter. For now the only value we can give is SSDR, but this is subject to change in the future, so add a bit of extra logic in the implementations of this callback to make sure both the core and the chip driver are aligned on the request. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Propagate the bus interface across core helpersMiquel Raynal-6/+7
For now all drivers provide SSDR variants only. When we add support for ODTR modes, there will be a need to differentiate the type of variant we target as well as the need to check if we support one or the other type of operations. Pass this parameter to lower level helpers, which for now is unused, in order to simplify the patch introducing ODTR support. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Add support for setting a bus interfaceMiquel Raynal-0/+1
Create a bus interface enumeration, currently only containing the one we support: SSDR, for single SDR, so any operation whose command is sent over a single data line in SDR mode, ie. any operation matching 1S-XX-XX. The main spinand_device structure gets a new parameter to store this enumeration, for now unused. Of course it is set to SSDR during the SSDR templates initialization to further clarify the state we are in at the moment. This member is subject to be used to know in which bus configuration we and be updated by the core when we switch to faster mode(s). Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Gather all the bus interface steps in one single functionMiquel Raynal-25/+37
Writing the quad enable bit in one helper and doing the chip configuration in another does not make much sense from a bus interface setup point of view. Instead, let's create a broader helper which is going to be in charge of all the bus configuration steps at once. This will specifically allow to transition to octal DDR mode, and even fallback to quad (if suppoorted) or single mode otherwise. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: Configure the IO mode after the dummy cyclesMiquel Raynal-15/+15
When we will change the bus interface, the action that actually performs the transition is the IO mode register write. This means after the IO mode register write, we should use the new bus interface. But the ->configure_chip() hook itself is not responsible of making this change official, it is the caller that must act according to the return value. Reorganize this helper to first configure the dummy cycles before possibly switching to another bus interface. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: Rename IO_MODE register macroMiquel Raynal-2/+2
Suffix the macro name with *_REG to align with the rest of the driver. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: Fix styleMiquel Raynal-0/+1
Add a missing new line in the middle of the driver. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: Register W35N vendor specific operationMiquel Raynal-0/+6
Provide the Winbond W35N specific "write VCR register" operation to let the core verify it is supported by the controller before using it. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: Register W25N vendor specific operationMiquel Raynal-0/+4
Provide the Winbond W25N specific "select target" operation to let the core verify it is supported by the controller before using it. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: macronix: Register vendor specific operationMiquel Raynal-0/+23
Provide the Macronix specific "read ECC status register" operation so that the core can verify if it is supported by the controller before using it. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: List vendor specific operations and make sure they are supportedMiquel Raynal-0/+26
It is probably safe to expect that all SPI controller drivers will ever support all the most basic SPI NAND operations, such as write enable, register reads, page program, block erases, etc. However, what about vendor specific operations? So far nobody complained about it, but as we are about to introduce octal DTR support, and as none of the SPI NAND instruction set is defined in any standard, we must remain careful about these extra operations. One way to make sure we do not blindly get ourselves in strange situations with vendor commands failing silently is to make the check once for all, while probing the chip. However at this stage we have no such list, so let's add the necessary infrastructure to allow: - registering vendor operations, - checking they are actually supported when appropriate. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: Convert W35N specific operation to SPINAND_OP()Miquel Raynal-5/+14
Winbond W35N* chips require a vendor specific operation to write their VCR register (a configuration register, typically used for tuning the number of dummy cycles and switching to a different bus interface). Instead of defining this op only in the function that needs it, hiding it from the core, make it a proper define like all other spi-mem operations, and implement the necessary spinand_fill_*_op() helper to make the SPINAND_OP() macro work. This way we can use it from any function without any extra handling outside of this helper when we will convert the core to support octal DDR busses. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: winbond: Convert W25N specific operation to SPINAND_OP()Miquel Raynal-6/+14
Winbond W25N* chips require a vendor specific operation to select the target. Instead of defining this op only in the function that needs it, hiding it from the core, make it a proper define like all other spi-mem operations, and implement the necessary spinand_fill_*_op() helper to make the SPINAND_OP() macro work. This way we can use it from any function without any extra handling outside of this helper when we will convert the core to support octal DDR busses. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: macronix: Convert vendor specific operation to SPINAND_OP()Miquel Raynal-5/+15
Macronix chips require a vendor specific operation to read the ECC status register. Instead of defining this op only in the function that needs it, hiding it from the core, make it a proper define like all other spi-mem operations, and implement the necessary spinand_fill_*_op() helper to make the SPINAND_OP() macro work. This way we can use it from any function without any extra handling outside of this helper when we will convert the core to support octal DDR busses. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Make use of the operation templates through SPINAND_OP()Miquel Raynal-27/+113
Create a SPINAND_OP() macro to which we give the name of the operation we want. This macro retrieves the correct operation template based on the current bus interface (currently only single SDR, will soon be extended to octal DTR) and fills it with the usual parameters. This macro makes the transition from calling directly the low-level macros into using the (bus interface dependent) templates very smooth. Use it in all places that can be trivially converted. At this stage there is no functional change expected, until octal DTR support gets added. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Create an array of operation templatesMiquel Raynal-12/+30
Currently, the SPI NAND core implementation directly calls macros to get the various operations in shape. These macros are specific to the bus interface, currently only supporting the single SDR interface (any command following the 1S-XX-XX pattern). Introducing support for other bus interfaces (such as octal DTR) would mean that every user of these macros should become aware of the current bus interface and act accordingly, picking up and adapting to the current configuration. This would add quite a bit of boilerplate, be repetitive as well as error prone in case we miss one occurrence. Instead, let's create a table with all SPI NAND memory operations that are currently supported. We initialize them with the same single SDR _OP macros as before. This opens the possibility for users of the individual macros to make use of these templates instead. This way, when we will add another bus interface, we can just switch to another set of templates and all users will magically fill in their spi_mem_op structures with the correct ops. The existing read, write and update cache variants are also moved in this template array, which is barely noticeable by callers as we also add a structure member pointing to it. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Decouple write enable and write disable operationsMiquel Raynal-3/+3
In order to introduce templates for all operations and not only for page helpers (in order to introduce octal DDR support), decouple the WR_EN and WR_DIS operations into two separate macros. Adapt the callers accordingly. There is no functional change. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Use standard return valuesMiquel Raynal-4/+4
Replace -ENOTSUPP with -EOPNOTSUPP which is as relevant in this case but is standard. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: spinand: Add missing checkMiquel Raynal-0/+3
The update cache variant is mandatory, both read and write versions are being checked, but not this one. All chip drivers seem to implement this variant, so there should be no breakage. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29Merge tag 'tags/spi-octal-dtr' into nand/nextMiquel Raynal-10/+10
spi: Octal DTR support This series adds support for 8D-8D-8D in SPI NAND, which can already be leveraged without any SPI changes as controllers already have this support for some SPI NOR devices. Among the few spi-mem patches, they are needed for building the SPI NAND changes (especially the ODTR introduction at the end) and therefore an immutable tag will be needed for merging in the MTD tree (unless all the series goes through MTD directly ofc).
2026-01-29mtd: physmap-core: Prioritize ofparts for OF probeLinus Walleij-1/+1
Place the ofparts before RedBoot partitions in the OF probe path: this makes it possible to override any existing RedBoot partitions with fixed-partitions which may be necessary, such as when you need to repartition the flash from Linux' point of view but not necessary from the bootloaders point of view. This happens when a device such as Raidsonic IB-4220-B has three partitions named "Kern", "Ramdisk" and "Application" that we want to merge into one for more efficient use of the flash memory in OpenWrt. Signed-off-by: Linus Walleij <linusw@kernel.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-29mtd: parsers: ofpart: fix OF node refcount leak in parse_fixed_partitions()Weigang He-2/+14
of_get_child_by_name() returns a node pointer with refcount incremented, which must be released with of_node_put() when done. However, in parse_fixed_partitions(), when dedicated is true (i.e., a "partitions" subnode was found), the ofpart_node obtained from of_get_child_by_name() is never released on any code path. Add of_node_put(ofpart_node) calls on all exit paths when dedicated is true to fix the reference count leak. This bug was detected by our static analysis tool. Fixes: 562b4e91d3b2 ("mtd: parsers: ofpart: fix parsing subpartitions") Signed-off-by: Weigang He <geoffreyhe2@gmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-22mtd: parsers: Fix memory leak in mtd_parser_tplink_safeloader_parse()Zilin Guan-0/+1
The function mtd_parser_tplink_safeloader_parse() allocates buf via mtd_parser_tplink_safeloader_read_table(). If the allocation for parts[idx].name fails inside the loop, the code jumps to the err_free label without freeing buf, leading to a memory leak. Fix this by freeing the temporary buffer buf in the err_free label. Compile tested only. Issue found using a prototype static analysis tool and code review. Fixes: 00a3588084be ("mtd: parsers: add TP-Link SafeLoader partitions table parser") Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-22mtd: jedec_probe: fix shift-out-of-bounds UB in JEDEC ID maskingChenxi Hou-2/+2
UBSAN reports shift-out-of-bounds in jedec_read_mfr() and jedec_read_id():   UBSAN: shift-out-of-bounds in drivers/mtd/chips/jedec_probe.c:1924:13   shift exponent 32 is too large for 32-bit type 'int'   UBSAN: shift-out-of-bounds in drivers/mtd/chips/jedec_probe.c:1940:12   shift exponent 32 is too large for 32-bit type 'int' The JEDEC manufacturer/device ID masking uses:   (1 << (cfi->device_type * 8)) - 1 When cfi->device_type is 4, this evaluates to 1 << 32. Since the literal '1' has type int, this is a 32-bit shift and is undefined behavior. Fix it by using a 64-bit literal (1ULL) so the shift is performed in a 64-bit type. Co-developed-by: Hui Peng <benquike@gmail.com> Signed-off-by: Hui Peng <benquike@gmail.com> Co-developed-by: Zhihao Yao (Zephyr) <zhihao.yao@njit.edu> Signed-off-by: Zhihao Yao (Zephyr) <zhihao.yao@njit.edu> Signed-off-by: Chenxi Hou <ch395@njit.edu> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: rawnand: sunxi: Convert to common field_{get,prep}() helpersGeert Uytterhoeven-6/+0
Drop the driver-specific field_get() and field_prep() macros, in favor of the globally available variants from <linux/bitfield.h>. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Acked-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: intel-dg: Fix accessing regions before setting nregionsAlexander Usyskin-3/+6
The regions array is counted by nregions, but it's set only after accessing it: [] UBSAN: array-index-out-of-bounds in drivers/mtd/devices/mtd_intel_dg.c:750:15 [] index 0 is out of range for type '<unknown> [*]' Fix it by also fixing an undesired behavior: the loop silently ignores ENOMEM and continues setting the other entries. CC: Gustavo A. R. Silva <gustavoars@kernel.org> CC: Raag Jadav <raag.jadav@intel.com> Reported-by: Jani Partanen <jiipee@sotapeli.fi> Closes: https://lore.kernel.org/all/caca6c67-4f1d-49f1-948f-e63b6b937b29@sotapeli.fi Fixes: ceb5ab3cb646 ("mtd: add driver for intel graphics non-volatile memory device") Signed-off-by: Lucas De Marchi <demarchi@kernel.org> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com> Reviewed-by: Raag Jadav <raag.jadav@intel.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: rawnand: atmel: Defer probe if SRAM is missingRob Herring (Arm)-4/+2
The Atmel NAND controller driver depends on an SRAM pool and has an implicit assumption that the SRAM pool has already been created. Changing the initcall ordering can break this. Unfortunately, fw_devlink can't save us here as there's not a standard property to track the dependency. So it's up to deferring probe to save us. Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Tested-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Rob Herring (Arm) <robh@kernel.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: parsers: ofpart: Remove code/data for disabled custom parsersDaniel Palmer-13/+8
Currently even if none of the custom parsers are selected a struct of_device_id and a dummy function that just returns -EOPNOTSUPP is compiled in for each of them. Its not obvious from the code but struct of_device_id is massive, 196 or 200 bytes (see link), so this is a lot more wasteful than you'd think just skimming the code and assuming the wasted size is just the length of the string with some small overhead. If they aren't enabled use ifdef's to avoid anything being compiled in and remove the dummy functions. Link: https://lore.kernel.org/all/ef59d6fd3b2201b912d5eaa7f7a037d8f9adb744.1636561068.git.geert+renesas@glider.be/ Signed-off-by: Daniel Palmer <daniel@thingy.jp> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: spi-nor: hisi-sfc: Simplify with scoped for each OF child loopKrzysztof Kozlowski-5/+2
Use scoped for-each loop when iterating over device nodes to make code a bit simpler. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Acked-by: Pratyush Yadav <pratyush@kernel.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: rawnand: vf610: Simplify with scoped for each OF child loopKrzysztof Kozlowski-3/+1
Use scoped for-each loop when iterating over device nodes to make code a bit simpler. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: rawnand: vf610: Fix Wvoid-pointer-to-enum-cast warningKrzysztof Kozlowski-1/+1
"nfc->variant" is an enum, thus cast of pointer on 64-bit compile test with clang W=1 causes: vf610_nfc.c:843:17: error: cast to smaller integer type 'enum vf610_nfc_variant' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-01-19mtd: rawnand: qcom: Simplify with scoped for each OF child loopKrzysztof Kozlowski-5/+3
Use scoped for-each loop when iterating over device nodes to make code a bit simpler. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Reviewed-by: Manivannan Sadhasivam <mani@kernel.org> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>