Skip to contentSkip to conversation

mtd: maps: vmu-flash: Fix build and runtime errors

PATCH Applied Florian Fuchs 2 participants 6 messages May 18 – May 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover mtd: maps: vmu-flash: Fix build and runtime errors

Hi all,

This small series fixes build and runtime errors in the vmu-flash driver (enabled by CONFIG_MTD_VMU) and the related maple.h. These changes were verified on real Dreamcast hardware with a physical VMU. The VMU can now be successfully probed, read and written with MTD tools like mtdinfo and mtd_debug. Previously, the driver failed to build or crashed during probing.

bash-5.3# mtdinfo /dev/mtd0
mtd0
Name: vmu2.1.0
Type: mlc-nand
Eraseblock size: 512 bytes
Amount of eraseblocks: 256 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 512 bytes
Sub-page size: 512 bytes
Character device major/minor: 90:0
Bad blocks are allowed: true
Device is writable: true

Thanks,
Florian
---
v2->v3: Add Fixes tag to respective patches, fix subject to previous
commits
v1->v2: Rebased patches and fixed the hotplug issues in other sh
patches.

v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

The original v1 was postponed until the hotplug issue and other runtime panics were fixed by the following patch:
"[PATCH v3] sh: maple: fix empty port handling":
https://lore.kernel.org/linux-sh/[email protected]/

Using VMUs while some ports are empty requires the above patch.

Florian Fuchs (3):
maple: fix build error due to missing include of linux/device.h
mtd: maps: vmu-flash: fix fault in unaligned fixup
mtd: maps: vmu-flash: fix NULL pointer dereference in initialization

 drivers/mtd/maps/vmu-flash.c | 7 ++++---
 include/linux/maple.h        | 3 +--
 2 files changed, 5 insertions(+), 5 deletions(-)

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731

Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/3 maple: fix build error due to missing include of linux/device.h

The commit 313162d0b838 ("device.h: audit and cleanup users in main include dir") removed the include linux/device.h from linux/maple.h, which led to build errors as linux/maple.h embeds struct device via struct maple_device. So restore this, as it otherwise results in errors:

./include/linux/maple.h:81:16: error: field 'dev' has incomplete type
struct device dev;

Fixes 313162d0b838 ("device.h: audit and cleanup users in main include dir")

---
v2->v3: no functional change, reword commit message, align subject to
main includedir, add Cc tag
v1->v2: no functional change, just rebase patch

v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

 include/linux/maple.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/maple.h +1 -2
index 3be4e567473c..22f2930251ed 100644
@@ -2,10 +2,9 @@
 #ifndef __LINUX_MAPLE_H
 #define __LINUX_MAPLE_H
 
+#include <linux/device.h>
 #include <mach/maple.h>
 
-struct device;
-
 /* Maple Bus command and response codes */
 enum maple_code {
 	MAPLE_RESPONSE_FILEERR =	-5,
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/3 mtd: maps: vmu-flash: fix fault in unaligned fixup

In reply to Florian Fuchs

Use kzalloc_obj() / kzalloc_objs() to allocate the memcard structs, instead of kmalloc_obj() / kmalloc_objs() to prevent access to uninitialized data.

Fixes runtime error: Fault in unaligned fixup: 0000 [#1] at mtd_get_fact_prot_info.

Fixes 47a72688fae7 ("mtd: flash mapping support for Dreamcast VMU.")

---
v2->v3: no functional change, add Fixes, Cc tag according to feedback v1->v2: no functional change, just rebased.

v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

 drivers/mtd/maps/vmu-flash.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/maps/vmu-flash.c +3 -3
index 75e06d249ce9..b76d0609d1b7 100644
@@ -609,7 +609,7 @@ static int vmu_connect(struct maple_device *mdev)
 
 	basic_flash_data = be32_to_cpu(mdev->devinfo.function_data[c - 1]);
 
-	card = kmalloc_obj(struct memcard);
+	card = kzalloc_obj(struct memcard);
 	if (!card) {
 		error = -ENOMEM;
 		goto fail_nomem;
@@ -627,13 +627,13 @@ static int vmu_connect(struct maple_device *mdev)
 	* Not sure there are actually any multi-partition devices in the
 	* real world, but the hardware supports them, so, so will we
 	*/
-	card->parts = kmalloc_objs(struct vmupart, card->partitions);
+	card->parts = kzalloc_objs(struct vmupart, card->partitions);
 	if (!card->parts) {
 		error = -ENOMEM;
 		goto fail_partitions;
 	}
 
-	card->mtd = kmalloc_objs(struct mtd_info, card->partitions);
+	card->mtd = kzalloc_objs(struct mtd_info, card->partitions);
 	if (!card->mtd) {
 		error = -ENOMEM;
 		goto fail_mtd_info;
Signature · 1 line
2.43.0
#3 lore raw

PATCH v3 3/3 mtd: maps: vmu-flash: fix NULL pointer dereference in initialization

In reply to Florian Fuchs

The mtd_info contains a struct device, which must be linked to its parent. Without this, the initialization of the MTD fails with a NULL pointer dereference.

Fixes 47a72688fae7 ("mtd: flash mapping support for Dreamcast VMU.")

---
v2->v3: no functional change, added Fixes, Cc tag according to feedback v1->v2: no functional change

v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

 drivers/mtd/maps/vmu-flash.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/maps/vmu-flash.c +1 -0
index b76d0609d1b7..10244e6731d0 100644
@@ -547,6 +547,7 @@ static void vmu_queryblocks(struct mapleq *mq)
 	mpart->partition = card->partition;
 	mtd_cur->priv = mpart;
 	mtd_cur->owner = THIS_MODULE;
+	mtd_cur->dev.parent = &mdev->dev;
 
 	pcache = kzalloc_obj(struct vmu_cache);
 	if (!pcache)
Signature · 1 line
2.43.0
maintainer
#4 lore raw
In reply to Florian Fuchs

Hi Florian,

Quoted 21 lines · Florian Fuchs

Hi all,

This small series fixes build and runtime errors in the vmu-flash driver (enabled by CONFIG_MTD_VMU) and the related maple.h. These changes were verified on real Dreamcast hardware with a physical VMU. The VMU can now be successfully probed, read and written with MTD tools like mtdinfo and mtd_debug. Previously, the driver failed to build or crashed during probing.

bash-5.3# mtdinfo /dev/mtd0
mtd0
Name: vmu2.1.0
Type: mlc-nand
Eraseblock size: 512 bytes
Amount of eraseblocks: 256 (131072 bytes, 128.0 KiB)
Minimum input/output unit size: 512 bytes
Sub-page size: 512 bytes
Character device major/minor: 90:0
Bad blocks are allowed: true
Device is writable: true

Quoted 3 lines

Thanks,
Florian
---

I believe there is no issue in applying patches 2 and 3 on top of the mtd tree and let whoever is responsible take patch 1. If I get an ack I can also carry patch 1 through the mtd tree. Without more feedback I plan on applying patches 2 and 3 in the coming weeks.

Thanks,
Miquèl

maintainer Applied
#5 lore raw
In reply to Florian Fuchs
Quoted 8 lines · Florian Fuchs

This small series fixes build and runtime errors in the vmu-flash driver (enabled by CONFIG_MTD_VMU) and the related maple.h. These changes were verified on real Dreamcast hardware with a physical VMU. The VMU can now be successfully probed, read and written with MTD tools like mtdinfo and mtd_debug. Previously, the driver failed to build or crashed during probing.

[...]

Applied to mtd/next, thanks!

[1/3] maple: fix build error due to missing include of linux/device.h
(no commit info)
[2/3] mtd: maps: vmu-flash: fix fault in unaligned fixup

      commit: 79d1661502c6e4b6f626185cef72cf2fa78116e1
[3/3] mtd: maps: vmu-flash: fix NULL pointer dereference in initialization
      commit: 357e3b8e3a8769ba36eb8ec5e053e4825f1a9329

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl