Skip to contentSkip to conversation

qcom: Add SMEM MTD parser

PATCH Superseded Mathieu Olivari 2 participants 6 messages Aug 15, 2015 – Aug 17, 2015

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover qcom: Add SMEM MTD parser

QCOM platforms such as IPQ806x are using SMEM to store their flash layout. This patch set adds the DT nodes required to instanciate SMEM on IPQ806x and add an MTD parser using it.

This change is based on the SMEM driver posted here:
*https://lkml.org/lkml/2015/7/27/1125

v2:
*Release the SPI device reference after looking it up (put_device()) *Represent SMEM data as __le32 rather than u32
*Move new DT nodes in their proper respective location *Address readability concerns in MTD parser

Mathieu Olivari (3):
ARM: qcom: add SFPB nodes to IPQ806x dts
ARM: qcom: add SMEM device node to IPQ806x dts
mtd: add SMEM parser for QCOM platforms

 arch/arm/boot/dts/qcom-ipq8064.dtsi |  23 +++-
 drivers/mtd/Kconfig                 |   7 ++
 drivers/mtd/Makefile                |   1 +
 drivers/mtd/qcom_smem_part.c        | 224 ++++++++++++++++++++++++++++++++++++
 4 files changed, 254 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mtd/qcom_smem_part.c
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/3 ARM: qcom: add SFPB nodes to IPQ806x dts

Add one new node to the ipq806x.dtsi file to declare & register the hardware spinlock devices. This mechanism is required to be used by other drivers such as SMEM.

---
 arch/arm/boot/dts/qcom-ipq8064.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/boot/dts/qcom-ipq8064.dtsi +11 -0
index 9f727d8..8d366ae 100644
@@ -329,5 +329,16 @@
 			#reset-cells = <1>;
 		};
 
+		sfpb_mutex_block: syscon at 1200600 {
+			compatible = "syscon";
+			reg = <0x01200600 0x100>;
+		};
+	};
+
+	sfpb_mutex: sfpb-mutex {
+		compatible = "qcom,sfpb-mutex";
+		syscon = <&sfpb_mutex_block 4 4>;
+
+		#hwlock-cells = <1>;
 	};
 };
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/3 ARM: qcom: add SMEM device node to IPQ806x dts

In reply to Mathieu Olivari

SMEM is used on IPQ806x to store various board related information such as boot device and flash partition layout. We'll declare it as a device so we can make use of it thanks to the new SMEM soc driver.

---
 arch/arm/boot/dts/qcom-ipq8064.dtsi | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/arm/boot/dts/qcom-ipq8064.dtsi +7 -1
index 8d366ae..85dbccf 100644
@@ -55,7 +55,7 @@
 			no-map;
 		};
 
-		smem at 41000000 {
+		smem: smem at 41000000 {
 			reg = <0x41000000 0x200000>;
 			no-map;
 		};
@@ -341,4 +341,10 @@
 
 		#hwlock-cells = <1>;
 	};
+
+	smem {
+		compatible = "qcom,smem";
+		memory-region = <&smem>;
+		hwlocks = <&sfpb_mutex 3>;
+	};
 };
Signature · 1 line
2.1.4
#3 lore raw

PATCH 3/3 mtd: add SMEM parser for QCOM platforms

In reply to Mathieu Olivari

On QCOM platforms using MTD devices storage (such as IPQ806x), SMEM is used to store partition layout. This new parser can now be used to read SMEM and use it to register an MTD layout according to its content.

---
 drivers/mtd/Kconfig          |   7 ++
 drivers/mtd/Makefile         |   1 +
 drivers/mtd/qcom_smem_part.c | 231 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 239 insertions(+)
 create mode 100644 drivers/mtd/qcom_smem_part.c
drivers/mtd/Kconfig +7 -0
index a03ad29..debc887 100644
@@ -155,6 +155,13 @@ config MTD_BCM47XX_PARTS
 	  This provides partitions parser for devices based on BCM47xx
 	  boards.
 
+config MTD_QCOM_SMEM_PARTS
+	tristate "QCOM SMEM partitioning support"
+	depends on QCOM_SMEM
+	help
+	  This provides partitions parser for QCOM devices using SMEM
+	  such as IPQ806x.
+
 comment "User Modules And Translation Layers"
 
 #
drivers/mtd/Makefile +1 -0
index 99bb9a1..b3c7de4 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_MTD_AFS_PARTS)	+= afs.o
 obj-$(CONFIG_MTD_AR7_PARTS)	+= ar7part.o
 obj-$(CONFIG_MTD_BCM63XX_PARTS)	+= bcm63xxpart.o
 obj-$(CONFIG_MTD_BCM47XX_PARTS)	+= bcm47xxpart.o
+obj-$(CONFIG_MTD_QCOM_SMEM_PARTS) += qcom_smem_part.o
 
 # 'Users' - code which presents functionality to userspace.
 obj-$(CONFIG_MTD_BLKDEVS)	+= mtd_blkdevs.o
drivers/mtd/qcom_smem_part.c new file +231 -0

231 lines not on this page · raw message

Signature · 1 line
2.1.4
#4 lore raw

Re: [PATCH 3/3] mtd: add SMEM parser for QCOM platforms

Quoted 4 lines · Mathieu Olivari

On QCOM platforms using MTD devices storage (such as IPQ806x), SMEM is used to store partition layout. This new parser can now be used to read SMEM and use it to register an MTD layout according to its content.

Nice to see another user of the smem code :)

Quoted 1 line
drivers/mtd/qcom_smem_part.c +0 -0

[..]

drivers/mtd/qcom_smem_part.c line 26

Quoted 3 lines
drivers/mtd/qcom_smem_part.c +3 -0
+
+/* Processor/host identifier for the application processor */
+#define SMEM_HOST_APPS			0

This makes me wonder if there will ever be an apps partition. I would have picked QCOM_SMEM_HOST_ANY, but I don't know what future platforms might hold for us.

And as a side note, I think I will propose that we rename that define QCOM_SMEM_GLOBAL.

Quoted 24 lines
drivers/mtd/qcom_smem_part.c +24 -0
+
+/* SMEM items index */
+#define SMEM_AARM_PARTITION_TABLE	9
+#define SMEM_BOOT_FLASH_TYPE		421
+#define SMEM_BOOT_FLASH_BLOCK_SIZE	424
+
+/* SMEM Flash types */
+#define SMEM_FLASH_NAND			2
+#define SMEM_FLASH_SPI			6
+
+#define SMEM_PART_NAME_SZ		16
+#define SMEM_PARTS_MAX			32
+
+struct smem_partition {
+	char name[SMEM_PART_NAME_SZ];
+	__le32 start;
+	__le32 size;
+	__le32 attr;
+};
+
+struct smem_partition_table {
+	u8 magic[8];
+	__le32 version;
+	__le32 len;

drivers/mtd/qcom_smem_part.c line 60

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+	struct smem_partition parts[SMEM_PARTS_MAX];
+};
+
+/* SMEM Magic values in partition table */
+static const u8 SMEM_PTABLE_MAGIC[] = {
+	0xaa, 0x73, 0xee, 0x55,
+	0xdb, 0xbd, 0x5e, 0xe3,
+};
+
+static int qcom_smem_get_flash_blksz(u64 **smem_blksz)

Instead of passing pointers around I think you should just make this function return < 0 for errors and >= 0 for the requested data. You can probably still have it as an int, as the current values are well below the size of the int.

Quoted 11 lines
drivers/mtd/qcom_smem_part.c +11 -0
+{
+	int ret;
+	size_t size;
+
+	ret = qcom_smem_get(SMEM_HOST_APPS, SMEM_BOOT_FLASH_BLOCK_SIZE,
+			    (void **) smem_blksz, &size);
+
+	if (ret < 0) {
+		pr_err("Unable to read flash blksz from SMEM\n");
+		return -ENOENT;
+	}

drivers/mtd/qcom_smem_part.c line 81

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+
+	if (size != sizeof(**smem_blksz)) {
+		pr_err("Invalid flash blksz size in SMEM\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int qcom_smem_get_flash_type(u64 **smem_flash_type)

Same as above.

Quoted 18 lines
drivers/mtd/qcom_smem_part.c +18 -0
+{
+	int ret;
+	size_t size;
+
+	ret = qcom_smem_get(SMEM_HOST_APPS, SMEM_BOOT_FLASH_TYPE,
+			    (void **) smem_flash_type, &size);
+
+	if (ret < 0) {
+		pr_err("Unable to read flash type from SMEM\n");
+		return -ENOENT;
+	}
+
+	if (size != sizeof(**smem_flash_type)) {
+		pr_err("Invalid flash type size in SMEM\n");
+		return -EINVAL;
+	}
+
+	return 0;

drivers/mtd/qcom_smem_part.c line 109

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+}
+
+static int qcom_smem_get_flash_partitions(struct smem_partition_table **pparts)
+{
+	int ret;
+	size_t size;
+
+	ret = qcom_smem_get(SMEM_HOST_APPS, SMEM_AARM_PARTITION_TABLE,
+			    (void **) pparts, &size);
+

If you don't care about the size just pass NULL as the last argument.

drivers/mtd/qcom_smem_part.c line 113

Quoted 4 lines
drivers/mtd/qcom_smem_part.c +4 -0
+	if (ret < 0) {
+		pr_err("Unable to read partition table from SMEM\n");
+		return -ENOENT;
+	}

I think it would be cleaner if you had this function check the magic and version and then return the partition pointer. That is:

static smem_partition *qcom_smem_get_flash_partitions(size_t *count)

And make *count = le32_to_cpu(table->len); so you don't have to care about that below.

(And use NULL or ERR_PTR for the error paths)

Quoted 25 lines
drivers/mtd/qcom_smem_part.c +25 -0
+
+	return 0;
+}
+
+static int of_dev_node_match(struct device *dev, void *data)
+{
+	return dev->of_node == data;
+}
+
+static bool is_spi_device(struct device_node *np)
+{
+	struct device *dev;
+
+	dev = bus_find_device(&spi_bus_type, NULL, np, of_dev_node_match);
+	if (!dev)
+		return false;
+
+	put_device(dev);
+	return true;
+}
+
+static int parse_qcom_smem_partitions(struct mtd_info *master,
+				      struct mtd_partition **pparts,
+				      struct mtd_part_parser_data *data)
+{

drivers/mtd/qcom_smem_part.c line 148

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+	struct smem_partition_table *smem_parts;
+	u64 *smem_flash_type, *smem_blksz;
+	struct mtd_partition *mtd_parts;
+	struct device_node *of_node = data->of_node;
+	int i, ret;
+
+	/*
+	 * SMEM will only store the partition table of the boot device.
+	 * If this is not the boot device, do not return any partition.
+	 */

I guess this is the result of below checks, but it's not describing what's actually done here. I think it should say "only parse partitions on the specified memory type" or something like that.

drivers/mtd/qcom_smem_part.c line 160

Quoted 12 lines
drivers/mtd/qcom_smem_part.c +12 -0
+	ret = qcom_smem_get_flash_type(&smem_flash_type);
+	if (ret < 0)
+		return ret;
+
+	if ((*smem_flash_type == SMEM_FLASH_NAND && !mtd_type_is_nand(master))
+	    || (*smem_flash_type == SMEM_FLASH_SPI && !is_spi_device(of_node)))
+		return 0;
+
+	/*
+	 * Just for sanity purpose, make sure the block size in SMEM matches the
+	 * block size of the MTD device
+	 */

Well, this is not only for sanity purpose, as you multiply all sizes with this number below...

Quoted 17 lines
drivers/mtd/qcom_smem_part.c +17 -0
+	ret = qcom_smem_get_flash_blksz(&smem_blksz);
+	if (ret < 0)
+		return ret;
+
+	if (*smem_blksz != master->erasesize) {
+		pr_err("SMEM block size differs from MTD block size\n");
+		return -EINVAL;
+	}
+
+	/* Get partition pointer from SMEM */
+	ret = qcom_smem_get_flash_partitions(&smem_parts);
+	if (ret < 0)
+		return ret;
+
+	if (memcmp(SMEM_PTABLE_MAGIC, smem_parts->magic,
+		   sizeof(SMEM_PTABLE_MAGIC))) {
+		pr_err("SMEM partition magic invalid\n");

drivers/mtd/qcom_smem_part.c line 187

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+		return -EINVAL;
+	}
+
+	/* Allocate and populate the mtd structures */
+	mtd_parts = kcalloc(le32_to_cpu(smem_parts->len), sizeof(*mtd_parts),
+			    GFP_KERNEL);
+	if (!mtd_parts)
+		return -ENOMEM;
+
+	for (i = 0; i < smem_parts->len; i++) {

This might have the wrong endian...

drivers/mtd/qcom_smem_part.c line 189

Quoted 2 lines
drivers/mtd/qcom_smem_part.c +2 -0
+		struct smem_partition *s_part = &smem_parts->parts[i];
+		struct mtd_partition *m_part = &mtd_parts[i];

I think Stephens suggestion was that you assign *pparts before looping and then you simply do:

*pparts = mtd_parts;

while (len--) {
	..

	s_part++;
	mtd_parts++;
}

drivers/mtd/qcom_smem_part.c

Quoted 2 lines
drivers/mtd/qcom_smem_part.c +2 -0
+
+		m_part->name = s_part->name;

I tried to follow the mtd code, and I believe that this pointer might be freed in free_partition(). If so you must kstrdup it here.

Quoted 5 lines
drivers/mtd/qcom_smem_part.c +5 -0
+		m_part->size = le32_to_cpu(s_part->size) * (*smem_blksz);
+		m_part->offset = le32_to_cpu(s_part->start) * (*smem_blksz);
+
+		/*
+		 * The last SMEM partition may have its size marked as

drivers/mtd/qcom_smem_part.c line 206

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+		 * something like 0xffffffff, which means "until the end of the
+		 * flash device". In this case, truncate it.
+		 */
+		if (m_part->offset + m_part->size > master->size)
+			m_part->size = master->size - m_part->offset;
+	}
+
+	*pparts = mtd_parts;
+
+	return smem_parts->len;

Again, this might be in the wrong endian.

Quoted 11 lines
drivers/mtd/qcom_smem_part.c +11 -0
+}
+
+static struct mtd_part_parser qcom_smem_parser = {
+	.owner = THIS_MODULE,
+	.parse_fn = parse_qcom_smem_partitions,
+	.name = "qcom-smem",
+};
+
+static int __init qcom_smem_parser_init(void)
+{
+	register_mtd_parser(&qcom_smem_parser);

drivers/mtd/qcom_smem_part.c line 227

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+	return 0;
+}
+
+static void __exit qcom_smem_parser_exit(void)
+{
+	deregister_mtd_parser(&qcom_smem_parser);
+}
+
+module_init(qcom_smem_parser_init);
+module_exit(qcom_smem_parser_exit);

Mostly unrelated to this patch; This makes me appreciate the module_platform_driver() macro, would be nice to see a patch that introduces something similar for partition parsers.

drivers/mtd/qcom_smem_part.c line 229

Quoted 2 lines
drivers/mtd/qcom_smem_part.c +2 -0
+
+MODULE_LICENSE("GPL");

Are you sure you don't mean "GPL v2" here?

drivers/mtd/qcom_smem_part.c line 231

Quoted 2 lines
drivers/mtd/qcom_smem_part.c +2 -0
+MODULE_AUTHOR("Mathieu Olivari <[email protected]>");
+MODULE_DESCRIPTION("Parsing code for SMEM based partition tables");

Regards,
Bjorn

#5 lore raw

Re: [PATCH 3/3] mtd: add SMEM parser for QCOM platforms

Quoted 20 lines · Bjorn Andersson
Quoted 4 lines · Mathieu Olivari

On QCOM platforms using MTD devices storage (such as IPQ806x), SMEM is used to store partition layout. This new parser can now be used to read SMEM and use it to register an MTD layout according to its content.

Nice to see another user of the smem code :)

Quoted 1 line
drivers/mtd/qcom_smem_part.c +0 -0

[..]

drivers/mtd/qcom_smem_part.c line 26

Quoted 3 lines
drivers/mtd/qcom_smem_part.c +3 -0
+
+/* Processor/host identifier for the application processor */
+#define SMEM_HOST_APPS			0

This makes me wonder if there will ever be an apps partition. I would have picked QCOM_SMEM_HOST_ANY, but I don't know what future platforms might hold for us.

Quoted 2 lines

And as a side note, I think I will propose that we rename that define QCOM_SMEM_GLOBAL.

OK; I'll rename it in QCOM_SMEM_GLOBAL then to be in sync.

Quoted 32 lines
Quoted 32 lines
drivers/mtd/qcom_smem_part.c +31 -0
+
+/* SMEM items index */
+#define SMEM_AARM_PARTITION_TABLE	9
+#define SMEM_BOOT_FLASH_TYPE		421
+#define SMEM_BOOT_FLASH_BLOCK_SIZE	424
+
+/* SMEM Flash types */
+#define SMEM_FLASH_NAND			2
+#define SMEM_FLASH_SPI			6
+
+#define SMEM_PART_NAME_SZ		16
+#define SMEM_PARTS_MAX			32
+
+struct smem_partition {
+	char name[SMEM_PART_NAME_SZ];
+	__le32 start;
+	__le32 size;
+	__le32 attr;
+};
+
+struct smem_partition_table {
+	u8 magic[8];
+	__le32 version;
+	__le32 len;
+	struct smem_partition parts[SMEM_PARTS_MAX];
+};
+
+/* SMEM Magic values in partition table */
+static const u8 SMEM_PTABLE_MAGIC[] = {
+	0xaa, 0x73, 0xee, 0x55,
+	0xdb, 0xbd, 0x5e, 0xe3,
Quoted 8 lines

drivers/mtd/qcom_smem_part.c line 60

Quoted 3 lines
drivers/mtd/qcom_smem_part.c +3 -0
+};
+
+static int qcom_smem_get_flash_blksz(u64 **smem_blksz)

Instead of passing pointers around I think you should just make this function return < 0 for errors and >= 0 for the requested data. You can probably still have it as an int, as the current values are well below the size of the int.

Good point. Thanks. I'll report it.

Quoted 16 lines
Quoted 16 lines
drivers/mtd/qcom_smem_part.c +15 -0
+{
+	int ret;
+	size_t size;
+
+	ret = qcom_smem_get(SMEM_HOST_APPS, SMEM_BOOT_FLASH_BLOCK_SIZE,
+			    (void **) smem_blksz, &size);
+
+	if (ret < 0) {
+		pr_err("Unable to read flash blksz from SMEM\n");
+		return -ENOENT;
+	}
+
+	if (size != sizeof(**smem_blksz)) {
+		pr_err("Invalid flash blksz size in SMEM\n");
+		return -EINVAL;
Quoted 8 lines

drivers/mtd/qcom_smem_part.c line 81

Quoted 6 lines
drivers/mtd/qcom_smem_part.c +6 -0
+	}
+
+	return 0;
+}
+
+static int qcom_smem_get_flash_type(u64 **smem_flash_type)

Same as above.

OK.

Quoted 23 lines
Quoted 23 lines
drivers/mtd/qcom_smem_part.c +22 -0
+{
+	int ret;
+	size_t size;
+
+	ret = qcom_smem_get(SMEM_HOST_APPS, SMEM_BOOT_FLASH_TYPE,
+			    (void **) smem_flash_type, &size);
+
+	if (ret < 0) {
+		pr_err("Unable to read flash type from SMEM\n");
+		return -ENOENT;
+	}
+
+	if (size != sizeof(**smem_flash_type)) {
+		pr_err("Invalid flash type size in SMEM\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int qcom_smem_get_flash_partitions(struct smem_partition_table **pparts)
+{
Quoted 8 lines

drivers/mtd/qcom_smem_part.c line 109

Quoted 6 lines
drivers/mtd/qcom_smem_part.c +6 -0
+	int ret;
+	size_t size;
+
+	ret = qcom_smem_get(SMEM_HOST_APPS, SMEM_AARM_PARTITION_TABLE,
+			    (void **) pparts, &size);
+

If you don't care about the size just pass NULL as the last argument.

OK.

Quoted 9 lines

drivers/mtd/qcom_smem_part.c line 113

Quoted 5 lines
drivers/mtd/qcom_smem_part.c +4 -0
+	if (ret < 0) {
+		pr_err("Unable to read partition table from SMEM\n");
+		return -ENOENT;
+	}

I think it would be cleaner if you had this function check the magic and version and then return the partition pointer. That is:

Quoted 7 lines

static smem_partition *qcom_smem_get_flash_partitions(size_t *count)

And make *count = le32_to_cpu(table->len); so you don't have to care about that below.

(And use NULL or ERR_PTR for the error paths)

Same; good idea. I'll make the mod.

Quoted 32 lines
Quoted 32 lines
drivers/mtd/qcom_smem_part.c +31 -0
+
+	return 0;
+}
+
+static int of_dev_node_match(struct device *dev, void *data)
+{
+	return dev->of_node == data;
+}
+
+static bool is_spi_device(struct device_node *np)
+{
+	struct device *dev;
+
+	dev = bus_find_device(&spi_bus_type, NULL, np, of_dev_node_match);
+	if (!dev)
+		return false;
+
+	put_device(dev);
+	return true;
+}
+
+static int parse_qcom_smem_partitions(struct mtd_info *master,
+				      struct mtd_partition **pparts,
+				      struct mtd_part_parser_data *data)
+{
+	struct smem_partition_table *smem_parts;
+	u64 *smem_flash_type, *smem_blksz;
+	struct mtd_partition *mtd_parts;
+	struct device_node *of_node = data->of_node;
+	int i, ret;
+
Quoted 8 lines

drivers/mtd/qcom_smem_part.c line 148

Quoted 4 lines
drivers/mtd/qcom_smem_part.c +4 -0
+	/*
+	 * SMEM will only store the partition table of the boot device.
+	 * If this is not the boot device, do not return any partition.
+	 */

I guess this is the result of below checks, but it's not describing what's actually done here. I think it should say "only parse partitions on the specified memory type" or something like that.

OK.

Quoted 16 lines

drivers/mtd/qcom_smem_part.c line 160

Quoted 13 lines
drivers/mtd/qcom_smem_part.c +12 -0
+	ret = qcom_smem_get_flash_type(&smem_flash_type);
+	if (ret < 0)
+		return ret;
+
+	if ((*smem_flash_type == SMEM_FLASH_NAND && !mtd_type_is_nand(master))
+	    || (*smem_flash_type == SMEM_FLASH_SPI && !is_spi_device(of_node)))
+		return 0;
+
+	/*
+	 * Just for sanity purpose, make sure the block size in SMEM matches the
+	 * block size of the MTD device
+	 */

Well, this is not only for sanity purpose, as you multiply all sizes with this number below...

I'll update the comment.

Quoted 22 lines
Quoted 22 lines
drivers/mtd/qcom_smem_part.c +21 -0
+	ret = qcom_smem_get_flash_blksz(&smem_blksz);
+	if (ret < 0)
+		return ret;
+
+	if (*smem_blksz != master->erasesize) {
+		pr_err("SMEM block size differs from MTD block size\n");
+		return -EINVAL;
+	}
+
+	/* Get partition pointer from SMEM */
+	ret = qcom_smem_get_flash_partitions(&smem_parts);
+	if (ret < 0)
+		return ret;
+
+	if (memcmp(SMEM_PTABLE_MAGIC, smem_parts->magic,
+		   sizeof(SMEM_PTABLE_MAGIC))) {
+		pr_err("SMEM partition magic invalid\n");
+		return -EINVAL;
+	}
+
+	/* Allocate and populate the mtd structures */
Quoted 8 lines

drivers/mtd/qcom_smem_part.c line 187

Quoted 6 lines
drivers/mtd/qcom_smem_part.c +6 -0
+	mtd_parts = kcalloc(le32_to_cpu(smem_parts->len), sizeof(*mtd_parts),
+			    GFP_KERNEL);
+	if (!mtd_parts)
+		return -ENOMEM;
+
+	for (i = 0; i < smem_parts->len; i++) {

This might have the wrong endian...

Right. I'll do a le32_to_cpu()

Quoted 16 lines

drivers/mtd/qcom_smem_part.c line 189

Quoted 3 lines
drivers/mtd/qcom_smem_part.c +2 -0
+		struct smem_partition *s_part = &smem_parts->parts[i];
+		struct mtd_partition *m_part = &mtd_parts[i];

I think Stephens suggestion was that you assign *pparts before looping and then you simply do:

*pparts = mtd_parts;

while (len--) {
	..

	s_part++;
	mtd_parts++;
}
Quoted 5 lines

drivers/mtd/qcom_smem_part.c

Quoted 2 lines
drivers/mtd/qcom_smem_part.c +2 -0
+
+		m_part->name = s_part->name;

I tried to follow the mtd code, and I believe that this pointer might be freed in free_partition(). If so you must kstrdup it here.

OK.

Quoted 10 lines
Quoted 10 lines
drivers/mtd/qcom_smem_part.c +9 -0
+		m_part->size = le32_to_cpu(s_part->size) * (*smem_blksz);
+		m_part->offset = le32_to_cpu(s_part->start) * (*smem_blksz);
+
+		/*
+		 * The last SMEM partition may have its size marked as
+		 * something like 0xffffffff, which means "until the end of the
+		 * flash device". In this case, truncate it.
+		 */
+		if (m_part->offset + m_part->size > master->size)
Quoted 8 lines

drivers/mtd/qcom_smem_part.c line 206

Quoted 6 lines
drivers/mtd/qcom_smem_part.c +6 -0
+			m_part->size = master->size - m_part->offset;
+	}
+
+	*pparts = mtd_parts;
+
+	return smem_parts->len;

Again, this might be in the wrong endian.

Yes.

Quoted 27 lines
Quoted 12 lines
drivers/mtd/qcom_smem_part.c +11 -0
+}
+
+static struct mtd_part_parser qcom_smem_parser = {
+	.owner = THIS_MODULE,
+	.parse_fn = parse_qcom_smem_partitions,
+	.name = "qcom-smem",
+};
+
+static int __init qcom_smem_parser_init(void)
+{
+	register_mtd_parser(&qcom_smem_parser);

drivers/mtd/qcom_smem_part.c line 227

Quoted 10 lines
drivers/mtd/qcom_smem_part.c +10 -0
+	return 0;
+}
+
+static void __exit qcom_smem_parser_exit(void)
+{
+	deregister_mtd_parser(&qcom_smem_parser);
+}
+
+module_init(qcom_smem_parser_init);
+module_exit(qcom_smem_parser_exit);

Mostly unrelated to this patch; This makes me appreciate the module_platform_driver() macro, would be nice to see a patch that introduces something similar for partition parsers.

Quoted 4 lines

drivers/mtd/qcom_smem_part.c line 229

Quoted 2 lines
drivers/mtd/qcom_smem_part.c +2 -0
+
+MODULE_LICENSE("GPL");

Are you sure you don't mean "GPL v2" here?

I'll update it.

Quoted 6 lines

drivers/mtd/qcom_smem_part.c line 231

Quoted 3 lines
drivers/mtd/qcom_smem_part.c +2 -0
+MODULE_AUTHOR("Mathieu Olivari <[email protected]>");
+MODULE_DESCRIPTION("Parsing code for SMEM based partition tables");

Regards,
Bjorn