All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
@ 2021-01-04 12:28 ` John Thomson
  0 siblings, 0 replies; 7+ messages in thread
From: John Thomson @ 2021-01-04 12:28 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus
  Cc: linux-mtd, linux-kernel, John Thomson

Allow a uniform erase region spi-nor device to be configured
to use the non-uniform erase regions code path for an erase with:
CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE=y

On supporting hardware (SECT_4K),
provides the facility for an erase to use the least number
of SPI-NOR operations, as well as access to 4K erase without
requiring CONFIG_MTD_SPI_NOR_USE_4K_SECTORS

Introduce mtd struct erasesize_minor,
the smallest erasesize supported by the device.

Do not prevent writing to mtd partitions where a partition boundary sits
on a minor erasesize boundary.

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>

---
Have not tested on variable erase regions device
---
 drivers/mtd/mtdpart.c       | 52 ++++++++++++++++++++++++++++---------
 drivers/mtd/spi-nor/Kconfig | 10 +++++++
 drivers/mtd/spi-nor/core.c  | 12 +++++++--
 include/linux/mtd/mtd.h     |  2 ++
 4 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 12ca4f19cb14..7e7d9900aaa2 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -38,10 +38,11 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 	struct mtd_info *master = mtd_get_master(parent);
 	int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
 			   master->writesize : master->erasesize;
+	int wr_alignment_minor;
 	u64 parent_size = mtd_is_partition(parent) ?
 			  parent->part.size : parent->size;
 	struct mtd_info *child;
-	u32 remainder;
+	u32 remainder, remainder_minor;
 	char *name;
 	u64 tmp;
 
@@ -143,6 +144,7 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 		int i, max = parent->numeraseregions;
 		u64 end = child->part.offset + child->part.size;
 		struct mtd_erase_region_info *regions = parent->eraseregions;
+		uint32_t erasesize_minor = child->erasesize;
 
 		/* Find the first erase regions which is part of this
 		 * partition. */
@@ -153,15 +155,24 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 		if (i > 0)
 			i--;
 
-		/* Pick biggest erasesize */
 		for (; i < max && regions[i].offset < end; i++) {
+			/* Pick biggest erasesize */
 			if (child->erasesize < regions[i].erasesize)
 				child->erasesize = regions[i].erasesize;
+			/* Pick smallest non-zero erasesize */
+			if ((erasesize_minor > regions[i].erasesize) && (regions[i].erasesize > 0))
+				erasesize_minor = regions[i].erasesize;
 		}
+
+		if (erasesize_minor < child->erasesize)
+			child->erasesize_minor = erasesize_minor;
+
 		BUG_ON(child->erasesize == 0);
 	} else {
 		/* Single erase size */
 		child->erasesize = master->erasesize;
+		if (master->erasesize_minor)
+			child->erasesize_minor = master->erasesize_minor;
 	}
 
 	/*
@@ -169,26 +180,43 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 	 * exposes several regions with different erasesize. Adjust
 	 * wr_alignment accordingly.
 	 */
-	if (!(child->flags & MTD_NO_ERASE))
+	if (!(child->flags & MTD_NO_ERASE)) {
 		wr_alignment = child->erasesize;
+		if (child->erasesize_minor)
+			wr_alignment_minor = child->erasesize_minor;
+	}
 
 	tmp = mtd_get_master_ofs(child, 0);
 	remainder = do_div(tmp, wr_alignment);
 	if ((child->flags & MTD_WRITEABLE) && remainder) {
-		/* Doesn't start on a boundary of major erase size */
-		/* FIXME: Let it be writable if it is on a boundary of
-		 * _minor_ erase size though */
-		child->flags &= ~MTD_WRITEABLE;
-		printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
-			part->name);
+		if (wr_alignment_minor) {
+			tmp = mtd_get_master_ofs(child, 0);
+			remainder_minor = do_div(tmp, wr_alignment_minor);
+			if (remainder_minor == 0)
+				child->erasesize = child->erasesize_minor;
+		}
+
+		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
+			child->flags &= ~MTD_WRITEABLE;
+			printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
+				part->name);
+		}
 	}
 
 	tmp = mtd_get_master_ofs(child, 0) + child->part.size;
 	remainder = do_div(tmp, wr_alignment);
 	if ((child->flags & MTD_WRITEABLE) && remainder) {
-		child->flags &= ~MTD_WRITEABLE;
-		printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
-			part->name);
+		if (wr_alignment_minor) {
+			tmp = mtd_get_master_ofs(child, 0) + child->part.size;
+			remainder_minor = do_div(tmp, wr_alignment_minor);
+			if (remainder_minor == 0)
+				child->erasesize = child->erasesize_minor;
+		}
+		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
+			child->flags &= ~MTD_WRITEABLE;
+			printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
+				part->name);
+		}
 	}
 
 	child->size = child->part.size;
diff --git a/drivers/mtd/spi-nor/Kconfig b/drivers/mtd/spi-nor/Kconfig
index 24cd25de2b8b..09df9f1a8127 100644
--- a/drivers/mtd/spi-nor/Kconfig
+++ b/drivers/mtd/spi-nor/Kconfig
@@ -10,6 +10,16 @@ menuconfig MTD_SPI_NOR
 
 if MTD_SPI_NOR
 
+config MTD_SPI_NOR_USE_VARIABLE_ERASE
+	bool "Disable uniform_erase to allow use of all hardware supported erasesizes"
+	depends on !MTD_SPI_NOR_USE_4K_SECTORS
+	default n
+	help
+	  Allow mixed use of all hardware supported erasesizes,
+	  by forcing spi_nor to use the multiple eraseregions code path.
+	  For example: A 68K erase will use one 64K erase, and one 4K erase
+	  on supporting hardware.
+
 config MTD_SPI_NOR_USE_4K_SECTORS
 	bool "Use small 4096 B erase sectors"
 	default y
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 20df44b753da..8e678e8e7537 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1225,7 +1225,11 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
 
 static bool spi_nor_has_uniform_erase(const struct spi_nor *nor)
 {
+#ifdef CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE
+	return false;
+#else
 	return !!nor->params->erase_map.uniform_erase_type;
+#endif
 }
 
 static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
@@ -2714,6 +2718,7 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 {
 	struct spi_nor_erase_map *map = &nor->params->erase_map;
 	const struct spi_nor_erase_type *erase = NULL;
+	const struct spi_nor_erase_type *erase_minor = NULL;
 	struct mtd_info *mtd = &nor->mtd;
 	u32 wanted_size = nor->info->sector_size;
 	int i;
@@ -2746,8 +2751,9 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
 		if (map->erase_type[i].size) {
-			erase = &map->erase_type[i];
-			break;
+			if (!erase)
+				erase = &map->erase_type[i];
+			erase_minor = &map->erase_type[i];
 		}
 	}
 
@@ -2755,6 +2761,8 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 		return -EINVAL;
 
 	mtd->erasesize = erase->size;
+	if (erase_minor && erase_minor->size < erase->size)
+		mtd->erasesize_minor = erase_minor->size;
 	return 0;
 }
 
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 157357ec1441..68659e05edc3 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -242,6 +242,8 @@ struct mtd_info {
 	 * information below if they desire
 	 */
 	uint32_t erasesize;
+	/* "Minor" (smallest) erase size supported by the whole device */
+	uint32_t erasesize_minor;
 	/* Minimal writable flash unit size. In case of NOR flash it is 1 (even
 	 * though individual bits can be cleared), in case of NAND flash it is
 	 * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
@ 2021-01-04 12:28 ` John Thomson
  0 siblings, 0 replies; 7+ messages in thread
From: John Thomson @ 2021-01-04 12:28 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus
  Cc: linux-mtd, linux-kernel, John Thomson

Allow a uniform erase region spi-nor device to be configured
to use the non-uniform erase regions code path for an erase with:
CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE=y

On supporting hardware (SECT_4K),
provides the facility for an erase to use the least number
of SPI-NOR operations, as well as access to 4K erase without
requiring CONFIG_MTD_SPI_NOR_USE_4K_SECTORS

Introduce mtd struct erasesize_minor,
the smallest erasesize supported by the device.

Do not prevent writing to mtd partitions where a partition boundary sits
on a minor erasesize boundary.

Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>

---
Have not tested on variable erase regions device
---
 drivers/mtd/mtdpart.c       | 52 ++++++++++++++++++++++++++++---------
 drivers/mtd/spi-nor/Kconfig | 10 +++++++
 drivers/mtd/spi-nor/core.c  | 12 +++++++--
 include/linux/mtd/mtd.h     |  2 ++
 4 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 12ca4f19cb14..7e7d9900aaa2 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -38,10 +38,11 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 	struct mtd_info *master = mtd_get_master(parent);
 	int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
 			   master->writesize : master->erasesize;
+	int wr_alignment_minor;
 	u64 parent_size = mtd_is_partition(parent) ?
 			  parent->part.size : parent->size;
 	struct mtd_info *child;
-	u32 remainder;
+	u32 remainder, remainder_minor;
 	char *name;
 	u64 tmp;
 
@@ -143,6 +144,7 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 		int i, max = parent->numeraseregions;
 		u64 end = child->part.offset + child->part.size;
 		struct mtd_erase_region_info *regions = parent->eraseregions;
+		uint32_t erasesize_minor = child->erasesize;
 
 		/* Find the first erase regions which is part of this
 		 * partition. */
@@ -153,15 +155,24 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 		if (i > 0)
 			i--;
 
-		/* Pick biggest erasesize */
 		for (; i < max && regions[i].offset < end; i++) {
+			/* Pick biggest erasesize */
 			if (child->erasesize < regions[i].erasesize)
 				child->erasesize = regions[i].erasesize;
+			/* Pick smallest non-zero erasesize */
+			if ((erasesize_minor > regions[i].erasesize) && (regions[i].erasesize > 0))
+				erasesize_minor = regions[i].erasesize;
 		}
+
+		if (erasesize_minor < child->erasesize)
+			child->erasesize_minor = erasesize_minor;
+
 		BUG_ON(child->erasesize == 0);
 	} else {
 		/* Single erase size */
 		child->erasesize = master->erasesize;
+		if (master->erasesize_minor)
+			child->erasesize_minor = master->erasesize_minor;
 	}
 
 	/*
@@ -169,26 +180,43 @@ static struct mtd_info *allocate_partition(struct mtd_info *parent,
 	 * exposes several regions with different erasesize. Adjust
 	 * wr_alignment accordingly.
 	 */
-	if (!(child->flags & MTD_NO_ERASE))
+	if (!(child->flags & MTD_NO_ERASE)) {
 		wr_alignment = child->erasesize;
+		if (child->erasesize_minor)
+			wr_alignment_minor = child->erasesize_minor;
+	}
 
 	tmp = mtd_get_master_ofs(child, 0);
 	remainder = do_div(tmp, wr_alignment);
 	if ((child->flags & MTD_WRITEABLE) && remainder) {
-		/* Doesn't start on a boundary of major erase size */
-		/* FIXME: Let it be writable if it is on a boundary of
-		 * _minor_ erase size though */
-		child->flags &= ~MTD_WRITEABLE;
-		printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
-			part->name);
+		if (wr_alignment_minor) {
+			tmp = mtd_get_master_ofs(child, 0);
+			remainder_minor = do_div(tmp, wr_alignment_minor);
+			if (remainder_minor == 0)
+				child->erasesize = child->erasesize_minor;
+		}
+
+		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
+			child->flags &= ~MTD_WRITEABLE;
+			printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
+				part->name);
+		}
 	}
 
 	tmp = mtd_get_master_ofs(child, 0) + child->part.size;
 	remainder = do_div(tmp, wr_alignment);
 	if ((child->flags & MTD_WRITEABLE) && remainder) {
-		child->flags &= ~MTD_WRITEABLE;
-		printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
-			part->name);
+		if (wr_alignment_minor) {
+			tmp = mtd_get_master_ofs(child, 0) + child->part.size;
+			remainder_minor = do_div(tmp, wr_alignment_minor);
+			if (remainder_minor == 0)
+				child->erasesize = child->erasesize_minor;
+		}
+		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
+			child->flags &= ~MTD_WRITEABLE;
+			printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
+				part->name);
+		}
 	}
 
 	child->size = child->part.size;
diff --git a/drivers/mtd/spi-nor/Kconfig b/drivers/mtd/spi-nor/Kconfig
index 24cd25de2b8b..09df9f1a8127 100644
--- a/drivers/mtd/spi-nor/Kconfig
+++ b/drivers/mtd/spi-nor/Kconfig
@@ -10,6 +10,16 @@ menuconfig MTD_SPI_NOR
 
 if MTD_SPI_NOR
 
+config MTD_SPI_NOR_USE_VARIABLE_ERASE
+	bool "Disable uniform_erase to allow use of all hardware supported erasesizes"
+	depends on !MTD_SPI_NOR_USE_4K_SECTORS
+	default n
+	help
+	  Allow mixed use of all hardware supported erasesizes,
+	  by forcing spi_nor to use the multiple eraseregions code path.
+	  For example: A 68K erase will use one 64K erase, and one 4K erase
+	  on supporting hardware.
+
 config MTD_SPI_NOR_USE_4K_SECTORS
 	bool "Use small 4096 B erase sectors"
 	default y
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 20df44b753da..8e678e8e7537 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1225,7 +1225,11 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
 
 static bool spi_nor_has_uniform_erase(const struct spi_nor *nor)
 {
+#ifdef CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE
+	return false;
+#else
 	return !!nor->params->erase_map.uniform_erase_type;
+#endif
 }
 
 static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
@@ -2714,6 +2718,7 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 {
 	struct spi_nor_erase_map *map = &nor->params->erase_map;
 	const struct spi_nor_erase_type *erase = NULL;
+	const struct spi_nor_erase_type *erase_minor = NULL;
 	struct mtd_info *mtd = &nor->mtd;
 	u32 wanted_size = nor->info->sector_size;
 	int i;
@@ -2746,8 +2751,9 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 	 */
 	for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
 		if (map->erase_type[i].size) {
-			erase = &map->erase_type[i];
-			break;
+			if (!erase)
+				erase = &map->erase_type[i];
+			erase_minor = &map->erase_type[i];
 		}
 	}
 
@@ -2755,6 +2761,8 @@ static int spi_nor_select_erase(struct spi_nor *nor)
 		return -EINVAL;
 
 	mtd->erasesize = erase->size;
+	if (erase_minor && erase_minor->size < erase->size)
+		mtd->erasesize_minor = erase_minor->size;
 	return 0;
 }
 
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 157357ec1441..68659e05edc3 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -242,6 +242,8 @@ struct mtd_info {
 	 * information below if they desire
 	 */
 	uint32_t erasesize;
+	/* "Minor" (smallest) erase size supported by the whole device */
+	uint32_t erasesize_minor;
 	/* Minimal writable flash unit size. In case of NOR flash it is 1 (even
 	 * though individual bits can be cleared), in case of NAND flash it is
 	 * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
-- 
2.30.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
  2021-01-04 12:28 ` John Thomson
@ 2021-01-05 11:06   ` Dan Carpenter
  -1 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2021-01-05 11:06 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 15513 bytes --]

Hi John,

url:    https://github.com/0day-ci/linux/commits/John-Thomson/mtd-spi-nor-write-support-for-minor-aligned-partitions/20210104-203259
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e71ba9452f0b5b2e8dc8aa5445198cd9214a6a62
config: x86_64-randconfig-m001-20210105 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/mtd/mtdpart.c:192 allocate_partition() error: uninitialized symbol 'wr_alignment_minor'.

vim +/wr_alignment_minor +192 drivers/mtd/mtdpart.c

46b5889cc2c54bac Miquel Raynal     2020-01-14   34  static struct mtd_info *allocate_partition(struct mtd_info *parent,
46b5889cc2c54bac Miquel Raynal     2020-01-14   35  					   const struct mtd_partition *part,
46b5889cc2c54bac Miquel Raynal     2020-01-14   36  					   int partno, uint64_t cur_offset)
^1da177e4c3f4152 Linus Torvalds    2005-04-16   37  {
9e3307a169537a6a Boris Brezillon   2020-05-03   38  	struct mtd_info *master = mtd_get_master(parent);
9e3307a169537a6a Boris Brezillon   2020-05-03   39  	int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
9e3307a169537a6a Boris Brezillon   2020-05-03   40  			   master->writesize : master->erasesize;
f861aba424a94bfa John Thomson      2021-01-04   41  	int wr_alignment_minor;
                                                        ^^^^^^^^^^^^^^^^^^^^^^

9e3307a169537a6a Boris Brezillon   2020-05-03   42  	u64 parent_size = mtd_is_partition(parent) ?
9e3307a169537a6a Boris Brezillon   2020-05-03   43  			  parent->part.size : parent->size;
9e3307a169537a6a Boris Brezillon   2020-05-03   44  	struct mtd_info *child;
f861aba424a94bfa John Thomson      2021-01-04   45  	u32 remainder, remainder_minor;
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   46  	char *name;
1eeef2d7483a7e3f Chris Packham     2017-06-09   47  	u64 tmp;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   48  
^1da177e4c3f4152 Linus Torvalds    2005-04-16   49  	/* allocate the partition structure */
46b5889cc2c54bac Miquel Raynal     2020-01-14   50  	child = kzalloc(sizeof(*child), GFP_KERNEL);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   51  	name = kstrdup(part->name, GFP_KERNEL);
46b5889cc2c54bac Miquel Raynal     2020-01-14   52  	if (!name || !child) {
b33a2887396a1a52 Atsushi Nemoto    2008-07-19   53  		printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
0a9d72b69da6d8da Rafał Miłecki     2017-06-21   54  		       parent->name);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   55  		kfree(name);
46b5889cc2c54bac Miquel Raynal     2020-01-14   56  		kfree(child);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   57  		return ERR_PTR(-ENOMEM);
^1da177e4c3f4152 Linus Torvalds    2005-04-16   58  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16   59  
^1da177e4c3f4152 Linus Torvalds    2005-04-16   60  	/* set up the MTD object for this partition */
46b5889cc2c54bac Miquel Raynal     2020-01-14   61  	child->type = parent->type;
46b5889cc2c54bac Miquel Raynal     2020-01-14   62  	child->part.flags = parent->flags & ~part->mask_flags;
9e3307a169537a6a Boris Brezillon   2020-05-03   63  	child->part.flags |= part->add_flags;
46b5889cc2c54bac Miquel Raynal     2020-01-14   64  	child->flags = child->part.flags;
9e3307a169537a6a Boris Brezillon   2020-05-03   65  	child->part.size = part->size;
46b5889cc2c54bac Miquel Raynal     2020-01-14   66  	child->writesize = parent->writesize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   67  	child->writebufsize = parent->writebufsize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   68  	child->oobsize = parent->oobsize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   69  	child->oobavail = parent->oobavail;
46b5889cc2c54bac Miquel Raynal     2020-01-14   70  	child->subpage_sft = parent->subpage_sft;
46b5889cc2c54bac Miquel Raynal     2020-01-14   71  
46b5889cc2c54bac Miquel Raynal     2020-01-14   72  	child->name = name;
46b5889cc2c54bac Miquel Raynal     2020-01-14   73  	child->owner = parent->owner;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   74  
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   75  	/* NOTE: Historically, we didn't arrange MTDs as a tree out of
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   76  	 * concern for showing the same data in multiple partitions.
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   77  	 * However, it is very useful to have the master node present,
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   78  	 * so the MTD_PARTITIONED_MASTER option allows that. The master
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   79  	 * will have device nodes etc only if this is set, so make the
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   80  	 * parent conditional on that option. Note, this is a way to
46b5889cc2c54bac Miquel Raynal     2020-01-14   81  	 * distinguish between the parent and its partitions in sysfs.
1f24b5a8ecbb2a3c David Brownell    2009-03-26   82  	 */
46b5889cc2c54bac Miquel Raynal     2020-01-14   83  	child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ?
46b5889cc2c54bac Miquel Raynal     2020-01-14   84  			    &parent->dev : parent->dev.parent;
46b5889cc2c54bac Miquel Raynal     2020-01-14   85  	child->dev.of_node = part->of_node;
46b5889cc2c54bac Miquel Raynal     2020-01-14   86  	child->parent = parent;
46b5889cc2c54bac Miquel Raynal     2020-01-14   87  	child->part.offset = part->offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   88  	INIT_LIST_HEAD(&child->partitions);
46b5889cc2c54bac Miquel Raynal     2020-01-14   89  
46b5889cc2c54bac Miquel Raynal     2020-01-14   90  	if (child->part.offset == MTDPART_OFS_APPEND)
46b5889cc2c54bac Miquel Raynal     2020-01-14   91  		child->part.offset = cur_offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   92  	if (child->part.offset == MTDPART_OFS_NXTBLK) {
1eeef2d7483a7e3f Chris Packham     2017-06-09   93  		tmp = cur_offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   94  		child->part.offset = cur_offset;
1eeef2d7483a7e3f Chris Packham     2017-06-09   95  		remainder = do_div(tmp, wr_alignment);
1eeef2d7483a7e3f Chris Packham     2017-06-09   96  		if (remainder) {
46b5889cc2c54bac Miquel Raynal     2020-01-14   97  			child->part.offset += wr_alignment - remainder;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   98  			printk(KERN_NOTICE "Moving partition %d: "
69423d99fc182a81 Adrian Hunter     2008-12-10   99  			       "0x%012llx -> 0x%012llx\n", partno,
46b5889cc2c54bac Miquel Raynal     2020-01-14  100  			       (unsigned long long)cur_offset,
46b5889cc2c54bac Miquel Raynal     2020-01-14  101  			       child->part.offset);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  102  		}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  103  	}
46b5889cc2c54bac Miquel Raynal     2020-01-14  104  	if (child->part.offset == MTDPART_OFS_RETAIN) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  105  		child->part.offset = cur_offset;
9e3307a169537a6a Boris Brezillon   2020-05-03  106  		if (parent_size - child->part.offset >= child->part.size) {
9e3307a169537a6a Boris Brezillon   2020-05-03  107  			child->part.size = parent_size - child->part.offset -
9e3307a169537a6a Boris Brezillon   2020-05-03  108  					   child->part.size;
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  109  		} else {
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  110  			printk(KERN_ERR "mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  111  				part->name, parent_size - child->part.offset,
9e3307a169537a6a Boris Brezillon   2020-05-03  112  				child->part.size);
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  113  			/* register to preserve ordering */
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  114  			goto out_register;
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  115  		}
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  116  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  117  	if (child->part.size == MTDPART_SIZ_FULL)
9e3307a169537a6a Boris Brezillon   2020-05-03  118  		child->part.size = parent_size - child->part.offset;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  119  
46b5889cc2c54bac Miquel Raynal     2020-01-14  120  	printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  121  	       child->part.offset, child->part.offset + child->part.size,
46b5889cc2c54bac Miquel Raynal     2020-01-14  122  	       child->name);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  123  
^1da177e4c3f4152 Linus Torvalds    2005-04-16  124  	/* let's do some sanity checks */
9e3307a169537a6a Boris Brezillon   2020-05-03  125  	if (child->part.offset >= parent_size) {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  126  		/* let's register it anyway to preserve ordering */
46b5889cc2c54bac Miquel Raynal     2020-01-14  127  		child->part.offset = 0;
9e3307a169537a6a Boris Brezillon   2020-05-03  128  		child->part.size = 0;
ad4635153034c20c Boris Brezillon   2019-01-30  129  
ad4635153034c20c Boris Brezillon   2019-01-30  130  		/* Initialize ->erasesize to make add_mtd_device() happy. */
46b5889cc2c54bac Miquel Raynal     2020-01-14  131  		child->erasesize = parent->erasesize;
b33a2887396a1a52 Atsushi Nemoto    2008-07-19  132  		printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
7788ba71a6046de1 Atsushi Nemoto    2008-07-19  133  			part->name);
f636ffb420f0f905 Atsushi Nemoto    2008-07-19  134  		goto out_register;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  135  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  136  	if (child->part.offset + child->part.size > parent->size) {
9e3307a169537a6a Boris Brezillon   2020-05-03  137  		child->part.size = parent_size - child->part.offset;
69423d99fc182a81 Adrian Hunter     2008-12-10  138  		printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  139  			part->name, parent->name, child->part.size);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  140  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  141  
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  142  	if (parent->numeraseregions > 1) {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  143  		/* Deal with variable erase size stuff */
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  144  		int i, max = parent->numeraseregions;
9e3307a169537a6a Boris Brezillon   2020-05-03  145  		u64 end = child->part.offset + child->part.size;
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  146  		struct mtd_erase_region_info *regions = parent->eraseregions;
f861aba424a94bfa John Thomson      2021-01-04  147  		uint32_t erasesize_minor = child->erasesize;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  148  
6910c1368104d50e Atsushi Nemoto    2008-07-19  149  		/* Find the first erase regions which is part of this
6910c1368104d50e Atsushi Nemoto    2008-07-19  150  		 * partition. */
46b5889cc2c54bac Miquel Raynal     2020-01-14  151  		for (i = 0; i < max && regions[i].offset <= child->part.offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14  152  		     i++)
^1da177e4c3f4152 Linus Torvalds    2005-04-16  153  			;
6910c1368104d50e Atsushi Nemoto    2008-07-19  154  		/* The loop searched for the region _behind_ the first one */
a57ca0466af5da83 Roel Kluin        2009-09-18  155  		if (i > 0)
6910c1368104d50e Atsushi Nemoto    2008-07-19  156  			i--;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  157  
6910c1368104d50e Atsushi Nemoto    2008-07-19  158  		for (; i < max && regions[i].offset < end; i++) {
f861aba424a94bfa John Thomson      2021-01-04  159  			/* Pick biggest erasesize */
46b5889cc2c54bac Miquel Raynal     2020-01-14  160  			if (child->erasesize < regions[i].erasesize)
46b5889cc2c54bac Miquel Raynal     2020-01-14  161  				child->erasesize = regions[i].erasesize;
f861aba424a94bfa John Thomson      2021-01-04  162  			/* Pick smallest non-zero erasesize */
f861aba424a94bfa John Thomson      2021-01-04  163  			if ((erasesize_minor > regions[i].erasesize) && (regions[i].erasesize > 0))
f861aba424a94bfa John Thomson      2021-01-04  164  				erasesize_minor = regions[i].erasesize;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  165  		}
f861aba424a94bfa John Thomson      2021-01-04  166  
f861aba424a94bfa John Thomson      2021-01-04  167  		if (erasesize_minor < child->erasesize)
f861aba424a94bfa John Thomson      2021-01-04  168  			child->erasesize_minor = erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  169  
46b5889cc2c54bac Miquel Raynal     2020-01-14  170  		BUG_ON(child->erasesize == 0);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  171  	} else {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  172  		/* Single erase size */
9e3307a169537a6a Boris Brezillon   2020-05-03  173  		child->erasesize = master->erasesize;
f861aba424a94bfa John Thomson      2021-01-04  174  		if (master->erasesize_minor)
f861aba424a94bfa John Thomson      2021-01-04  175  			child->erasesize_minor = master->erasesize_minor;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  176  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  177  
7e439681af829840 Boris Brezillon   2017-09-25  178  	/*
46b5889cc2c54bac Miquel Raynal     2020-01-14  179  	 * Child erasesize might differ from the parent one if the parent
7e439681af829840 Boris Brezillon   2017-09-25  180  	 * exposes several regions with different erasesize. Adjust
7e439681af829840 Boris Brezillon   2017-09-25  181  	 * wr_alignment accordingly.
7e439681af829840 Boris Brezillon   2017-09-25  182  	 */
f861aba424a94bfa John Thomson      2021-01-04  183  	if (!(child->flags & MTD_NO_ERASE)) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  184  		wr_alignment = child->erasesize;
f861aba424a94bfa John Thomson      2021-01-04  185  		if (child->erasesize_minor)
f861aba424a94bfa John Thomson      2021-01-04  186  			wr_alignment_minor = child->erasesize_minor;


Not initialized on else statement.

f861aba424a94bfa John Thomson      2021-01-04  187  	}
7e439681af829840 Boris Brezillon   2017-09-25  188  
46b5889cc2c54bac Miquel Raynal     2020-01-14  189  	tmp = mtd_get_master_ofs(child, 0);
1eeef2d7483a7e3f Chris Packham     2017-06-09  190  	remainder = do_div(tmp, wr_alignment);
46b5889cc2c54bac Miquel Raynal     2020-01-14  191  	if ((child->flags & MTD_WRITEABLE) && remainder) {
f861aba424a94bfa John Thomson      2021-01-04 @192  		if (wr_alignment_minor) {
                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^

f861aba424a94bfa John Thomson      2021-01-04  193  			tmp = mtd_get_master_ofs(child, 0);
f861aba424a94bfa John Thomson      2021-01-04  194  			remainder_minor = do_div(tmp, wr_alignment_minor);
f861aba424a94bfa John Thomson      2021-01-04  195  			if (remainder_minor == 0)
f861aba424a94bfa John Thomson      2021-01-04  196  				child->erasesize = child->erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  197  		}
f861aba424a94bfa John Thomson      2021-01-04  198  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 32879 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
@ 2021-01-05 11:06   ` Dan Carpenter
  0 siblings, 0 replies; 7+ messages in thread
From: Dan Carpenter @ 2021-01-05 11:06 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 15513 bytes --]

Hi John,

url:    https://github.com/0day-ci/linux/commits/John-Thomson/mtd-spi-nor-write-support-for-minor-aligned-partitions/20210104-203259
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e71ba9452f0b5b2e8dc8aa5445198cd9214a6a62
config: x86_64-randconfig-m001-20210105 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/mtd/mtdpart.c:192 allocate_partition() error: uninitialized symbol 'wr_alignment_minor'.

vim +/wr_alignment_minor +192 drivers/mtd/mtdpart.c

46b5889cc2c54bac Miquel Raynal     2020-01-14   34  static struct mtd_info *allocate_partition(struct mtd_info *parent,
46b5889cc2c54bac Miquel Raynal     2020-01-14   35  					   const struct mtd_partition *part,
46b5889cc2c54bac Miquel Raynal     2020-01-14   36  					   int partno, uint64_t cur_offset)
^1da177e4c3f4152 Linus Torvalds    2005-04-16   37  {
9e3307a169537a6a Boris Brezillon   2020-05-03   38  	struct mtd_info *master = mtd_get_master(parent);
9e3307a169537a6a Boris Brezillon   2020-05-03   39  	int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
9e3307a169537a6a Boris Brezillon   2020-05-03   40  			   master->writesize : master->erasesize;
f861aba424a94bfa John Thomson      2021-01-04   41  	int wr_alignment_minor;
                                                        ^^^^^^^^^^^^^^^^^^^^^^

9e3307a169537a6a Boris Brezillon   2020-05-03   42  	u64 parent_size = mtd_is_partition(parent) ?
9e3307a169537a6a Boris Brezillon   2020-05-03   43  			  parent->part.size : parent->size;
9e3307a169537a6a Boris Brezillon   2020-05-03   44  	struct mtd_info *child;
f861aba424a94bfa John Thomson      2021-01-04   45  	u32 remainder, remainder_minor;
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   46  	char *name;
1eeef2d7483a7e3f Chris Packham     2017-06-09   47  	u64 tmp;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   48  
^1da177e4c3f4152 Linus Torvalds    2005-04-16   49  	/* allocate the partition structure */
46b5889cc2c54bac Miquel Raynal     2020-01-14   50  	child = kzalloc(sizeof(*child), GFP_KERNEL);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   51  	name = kstrdup(part->name, GFP_KERNEL);
46b5889cc2c54bac Miquel Raynal     2020-01-14   52  	if (!name || !child) {
b33a2887396a1a52 Atsushi Nemoto    2008-07-19   53  		printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
0a9d72b69da6d8da Rafał Miłecki     2017-06-21   54  		       parent->name);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   55  		kfree(name);
46b5889cc2c54bac Miquel Raynal     2020-01-14   56  		kfree(child);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   57  		return ERR_PTR(-ENOMEM);
^1da177e4c3f4152 Linus Torvalds    2005-04-16   58  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16   59  
^1da177e4c3f4152 Linus Torvalds    2005-04-16   60  	/* set up the MTD object for this partition */
46b5889cc2c54bac Miquel Raynal     2020-01-14   61  	child->type = parent->type;
46b5889cc2c54bac Miquel Raynal     2020-01-14   62  	child->part.flags = parent->flags & ~part->mask_flags;
9e3307a169537a6a Boris Brezillon   2020-05-03   63  	child->part.flags |= part->add_flags;
46b5889cc2c54bac Miquel Raynal     2020-01-14   64  	child->flags = child->part.flags;
9e3307a169537a6a Boris Brezillon   2020-05-03   65  	child->part.size = part->size;
46b5889cc2c54bac Miquel Raynal     2020-01-14   66  	child->writesize = parent->writesize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   67  	child->writebufsize = parent->writebufsize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   68  	child->oobsize = parent->oobsize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   69  	child->oobavail = parent->oobavail;
46b5889cc2c54bac Miquel Raynal     2020-01-14   70  	child->subpage_sft = parent->subpage_sft;
46b5889cc2c54bac Miquel Raynal     2020-01-14   71  
46b5889cc2c54bac Miquel Raynal     2020-01-14   72  	child->name = name;
46b5889cc2c54bac Miquel Raynal     2020-01-14   73  	child->owner = parent->owner;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   74  
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   75  	/* NOTE: Historically, we didn't arrange MTDs as a tree out of
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   76  	 * concern for showing the same data in multiple partitions.
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   77  	 * However, it is very useful to have the master node present,
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   78  	 * so the MTD_PARTITIONED_MASTER option allows that. The master
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   79  	 * will have device nodes etc only if this is set, so make the
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   80  	 * parent conditional on that option. Note, this is a way to
46b5889cc2c54bac Miquel Raynal     2020-01-14   81  	 * distinguish between the parent and its partitions in sysfs.
1f24b5a8ecbb2a3c David Brownell    2009-03-26   82  	 */
46b5889cc2c54bac Miquel Raynal     2020-01-14   83  	child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ?
46b5889cc2c54bac Miquel Raynal     2020-01-14   84  			    &parent->dev : parent->dev.parent;
46b5889cc2c54bac Miquel Raynal     2020-01-14   85  	child->dev.of_node = part->of_node;
46b5889cc2c54bac Miquel Raynal     2020-01-14   86  	child->parent = parent;
46b5889cc2c54bac Miquel Raynal     2020-01-14   87  	child->part.offset = part->offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   88  	INIT_LIST_HEAD(&child->partitions);
46b5889cc2c54bac Miquel Raynal     2020-01-14   89  
46b5889cc2c54bac Miquel Raynal     2020-01-14   90  	if (child->part.offset == MTDPART_OFS_APPEND)
46b5889cc2c54bac Miquel Raynal     2020-01-14   91  		child->part.offset = cur_offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   92  	if (child->part.offset == MTDPART_OFS_NXTBLK) {
1eeef2d7483a7e3f Chris Packham     2017-06-09   93  		tmp = cur_offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   94  		child->part.offset = cur_offset;
1eeef2d7483a7e3f Chris Packham     2017-06-09   95  		remainder = do_div(tmp, wr_alignment);
1eeef2d7483a7e3f Chris Packham     2017-06-09   96  		if (remainder) {
46b5889cc2c54bac Miquel Raynal     2020-01-14   97  			child->part.offset += wr_alignment - remainder;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   98  			printk(KERN_NOTICE "Moving partition %d: "
69423d99fc182a81 Adrian Hunter     2008-12-10   99  			       "0x%012llx -> 0x%012llx\n", partno,
46b5889cc2c54bac Miquel Raynal     2020-01-14  100  			       (unsigned long long)cur_offset,
46b5889cc2c54bac Miquel Raynal     2020-01-14  101  			       child->part.offset);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  102  		}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  103  	}
46b5889cc2c54bac Miquel Raynal     2020-01-14  104  	if (child->part.offset == MTDPART_OFS_RETAIN) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  105  		child->part.offset = cur_offset;
9e3307a169537a6a Boris Brezillon   2020-05-03  106  		if (parent_size - child->part.offset >= child->part.size) {
9e3307a169537a6a Boris Brezillon   2020-05-03  107  			child->part.size = parent_size - child->part.offset -
9e3307a169537a6a Boris Brezillon   2020-05-03  108  					   child->part.size;
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  109  		} else {
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  110  			printk(KERN_ERR "mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  111  				part->name, parent_size - child->part.offset,
9e3307a169537a6a Boris Brezillon   2020-05-03  112  				child->part.size);
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  113  			/* register to preserve ordering */
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  114  			goto out_register;
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  115  		}
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  116  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  117  	if (child->part.size == MTDPART_SIZ_FULL)
9e3307a169537a6a Boris Brezillon   2020-05-03  118  		child->part.size = parent_size - child->part.offset;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  119  
46b5889cc2c54bac Miquel Raynal     2020-01-14  120  	printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  121  	       child->part.offset, child->part.offset + child->part.size,
46b5889cc2c54bac Miquel Raynal     2020-01-14  122  	       child->name);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  123  
^1da177e4c3f4152 Linus Torvalds    2005-04-16  124  	/* let's do some sanity checks */
9e3307a169537a6a Boris Brezillon   2020-05-03  125  	if (child->part.offset >= parent_size) {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  126  		/* let's register it anyway to preserve ordering */
46b5889cc2c54bac Miquel Raynal     2020-01-14  127  		child->part.offset = 0;
9e3307a169537a6a Boris Brezillon   2020-05-03  128  		child->part.size = 0;
ad4635153034c20c Boris Brezillon   2019-01-30  129  
ad4635153034c20c Boris Brezillon   2019-01-30  130  		/* Initialize ->erasesize to make add_mtd_device() happy. */
46b5889cc2c54bac Miquel Raynal     2020-01-14  131  		child->erasesize = parent->erasesize;
b33a2887396a1a52 Atsushi Nemoto    2008-07-19  132  		printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
7788ba71a6046de1 Atsushi Nemoto    2008-07-19  133  			part->name);
f636ffb420f0f905 Atsushi Nemoto    2008-07-19  134  		goto out_register;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  135  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  136  	if (child->part.offset + child->part.size > parent->size) {
9e3307a169537a6a Boris Brezillon   2020-05-03  137  		child->part.size = parent_size - child->part.offset;
69423d99fc182a81 Adrian Hunter     2008-12-10  138  		printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  139  			part->name, parent->name, child->part.size);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  140  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  141  
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  142  	if (parent->numeraseregions > 1) {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  143  		/* Deal with variable erase size stuff */
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  144  		int i, max = parent->numeraseregions;
9e3307a169537a6a Boris Brezillon   2020-05-03  145  		u64 end = child->part.offset + child->part.size;
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  146  		struct mtd_erase_region_info *regions = parent->eraseregions;
f861aba424a94bfa John Thomson      2021-01-04  147  		uint32_t erasesize_minor = child->erasesize;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  148  
6910c1368104d50e Atsushi Nemoto    2008-07-19  149  		/* Find the first erase regions which is part of this
6910c1368104d50e Atsushi Nemoto    2008-07-19  150  		 * partition. */
46b5889cc2c54bac Miquel Raynal     2020-01-14  151  		for (i = 0; i < max && regions[i].offset <= child->part.offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14  152  		     i++)
^1da177e4c3f4152 Linus Torvalds    2005-04-16  153  			;
6910c1368104d50e Atsushi Nemoto    2008-07-19  154  		/* The loop searched for the region _behind_ the first one */
a57ca0466af5da83 Roel Kluin        2009-09-18  155  		if (i > 0)
6910c1368104d50e Atsushi Nemoto    2008-07-19  156  			i--;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  157  
6910c1368104d50e Atsushi Nemoto    2008-07-19  158  		for (; i < max && regions[i].offset < end; i++) {
f861aba424a94bfa John Thomson      2021-01-04  159  			/* Pick biggest erasesize */
46b5889cc2c54bac Miquel Raynal     2020-01-14  160  			if (child->erasesize < regions[i].erasesize)
46b5889cc2c54bac Miquel Raynal     2020-01-14  161  				child->erasesize = regions[i].erasesize;
f861aba424a94bfa John Thomson      2021-01-04  162  			/* Pick smallest non-zero erasesize */
f861aba424a94bfa John Thomson      2021-01-04  163  			if ((erasesize_minor > regions[i].erasesize) && (regions[i].erasesize > 0))
f861aba424a94bfa John Thomson      2021-01-04  164  				erasesize_minor = regions[i].erasesize;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  165  		}
f861aba424a94bfa John Thomson      2021-01-04  166  
f861aba424a94bfa John Thomson      2021-01-04  167  		if (erasesize_minor < child->erasesize)
f861aba424a94bfa John Thomson      2021-01-04  168  			child->erasesize_minor = erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  169  
46b5889cc2c54bac Miquel Raynal     2020-01-14  170  		BUG_ON(child->erasesize == 0);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  171  	} else {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  172  		/* Single erase size */
9e3307a169537a6a Boris Brezillon   2020-05-03  173  		child->erasesize = master->erasesize;
f861aba424a94bfa John Thomson      2021-01-04  174  		if (master->erasesize_minor)
f861aba424a94bfa John Thomson      2021-01-04  175  			child->erasesize_minor = master->erasesize_minor;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  176  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  177  
7e439681af829840 Boris Brezillon   2017-09-25  178  	/*
46b5889cc2c54bac Miquel Raynal     2020-01-14  179  	 * Child erasesize might differ from the parent one if the parent
7e439681af829840 Boris Brezillon   2017-09-25  180  	 * exposes several regions with different erasesize. Adjust
7e439681af829840 Boris Brezillon   2017-09-25  181  	 * wr_alignment accordingly.
7e439681af829840 Boris Brezillon   2017-09-25  182  	 */
f861aba424a94bfa John Thomson      2021-01-04  183  	if (!(child->flags & MTD_NO_ERASE)) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  184  		wr_alignment = child->erasesize;
f861aba424a94bfa John Thomson      2021-01-04  185  		if (child->erasesize_minor)
f861aba424a94bfa John Thomson      2021-01-04  186  			wr_alignment_minor = child->erasesize_minor;


Not initialized on else statement.

f861aba424a94bfa John Thomson      2021-01-04  187  	}
7e439681af829840 Boris Brezillon   2017-09-25  188  
46b5889cc2c54bac Miquel Raynal     2020-01-14  189  	tmp = mtd_get_master_ofs(child, 0);
1eeef2d7483a7e3f Chris Packham     2017-06-09  190  	remainder = do_div(tmp, wr_alignment);
46b5889cc2c54bac Miquel Raynal     2020-01-14  191  	if ((child->flags & MTD_WRITEABLE) && remainder) {
f861aba424a94bfa John Thomson      2021-01-04 @192  		if (wr_alignment_minor) {
                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^

f861aba424a94bfa John Thomson      2021-01-04  193  			tmp = mtd_get_master_ofs(child, 0);
f861aba424a94bfa John Thomson      2021-01-04  194  			remainder_minor = do_div(tmp, wr_alignment_minor);
f861aba424a94bfa John Thomson      2021-01-04  195  			if (remainder_minor == 0)
f861aba424a94bfa John Thomson      2021-01-04  196  				child->erasesize = child->erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  197  		}
f861aba424a94bfa John Thomson      2021-01-04  198  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 32879 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
  2021-01-04 12:28 ` John Thomson
@ 2021-02-02 20:08   ` John Thomson
  -1 siblings, 0 replies; 7+ messages in thread
From: John Thomson @ 2021-02-02 20:08 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus
  Cc: linux-mtd, linux-kernel

On Mon, 4 Jan 2021, at 12:28, John Thomson wrote:
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
> @@ -38,10 +38,11 @@ static struct mtd_info *allocate_partition(struct 
> mtd_info *parent,
>  	struct mtd_info *master = mtd_get_master(parent);
>  	int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
>  			   master->writesize : master->erasesize;
> +	int wr_alignment_minor;

int wr_alignment_minor = 0;

> +	if (!(child->flags & MTD_NO_ERASE)) {
> 	wr_alignment = child->erasesize;
> +	if (child->erasesize_minor)

if (child->erasesize_minor && IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE)) {
Config test wrap wr_alignment_minor being set,
so that a partition on a minor boundary is only set writeable if the non-uniform erase path can be used.

> +		wr_alignment_minor = child->erasesize_minor;
> +	}

> +		if (wr_alignment_minor) {

smatch picked up a tested uninitialized symbol 'wr_alignment_minor' here,
initialise as 0.
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

> +		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {

If it is safe to boolean test the ints and u32, I should use this consistently?
if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor)) {
Or is it clearer to use the math tests?
if ((wr_alignment_minor == 0) || (wr_alignment_minor > 0 && remainder_minor > 0)) {

> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1225,7 +1225,11 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
>  
>  static bool spi_nor_has_uniform_erase(const struct spi_nor *nor)
>  {
> +#ifdef CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE

if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE)) {
and the closing brace better than the #ifdef here?

> +	return false;
> +#else
>  	return !!nor->params->erase_map.uniform_erase_type;
> +#endif
>  }
>  
>  static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)


Otherwise, is this approach valid, or is there a better method I can use?

Cheers,
-- 
  John Thomson

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
@ 2021-02-02 20:08   ` John Thomson
  0 siblings, 0 replies; 7+ messages in thread
From: John Thomson @ 2021-02-02 20:08 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus
  Cc: linux-mtd, linux-kernel

On Mon, 4 Jan 2021, at 12:28, John Thomson wrote:
> --- a/drivers/mtd/mtdpart.c
> +++ b/drivers/mtd/mtdpart.c
> @@ -38,10 +38,11 @@ static struct mtd_info *allocate_partition(struct 
> mtd_info *parent,
>  	struct mtd_info *master = mtd_get_master(parent);
>  	int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
>  			   master->writesize : master->erasesize;
> +	int wr_alignment_minor;

int wr_alignment_minor = 0;

> +	if (!(child->flags & MTD_NO_ERASE)) {
> 	wr_alignment = child->erasesize;
> +	if (child->erasesize_minor)

if (child->erasesize_minor && IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE)) {
Config test wrap wr_alignment_minor being set,
so that a partition on a minor boundary is only set writeable if the non-uniform erase path can be used.

> +		wr_alignment_minor = child->erasesize_minor;
> +	}

> +		if (wr_alignment_minor) {

smatch picked up a tested uninitialized symbol 'wr_alignment_minor' here,
initialise as 0.
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

> +		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {

If it is safe to boolean test the ints and u32, I should use this consistently?
if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor)) {
Or is it clearer to use the math tests?
if ((wr_alignment_minor == 0) || (wr_alignment_minor > 0 && remainder_minor > 0)) {

> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1225,7 +1225,11 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
>  
>  static bool spi_nor_has_uniform_erase(const struct spi_nor *nor)
>  {
> +#ifdef CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE

if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE)) {
and the closing brace better than the #ifdef here?

> +	return false;
> +#else
>  	return !!nor->params->erase_map.uniform_erase_type;
> +#endif
>  }
>  
>  static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)


Otherwise, is this approach valid, or is there a better method I can use?

Cheers,
-- 
  John Thomson

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
@ 2021-01-04 19:56 kernel test robot
  0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2021-01-04 19:56 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 19793 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210104122853.18428-1-git@johnthomson.fastmail.com.au>
References: <20210104122853.18428-1-git@johnthomson.fastmail.com.au>
TO: John Thomson <git@johnthomson.fastmail.com.au>

Hi John,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on v5.11-rc2 next-20210104]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/John-Thomson/mtd-spi-nor-write-support-for-minor-aligned-partitions/20210104-203259
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e71ba9452f0b5b2e8dc8aa5445198cd9214a6a62
:::::: branch date: 7 hours ago
:::::: commit date: 7 hours ago
config: x86_64-randconfig-m001-20210105 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
drivers/mtd/mtdpart.c:192 allocate_partition() error: uninitialized symbol 'wr_alignment_minor'.

Old smatch warnings:
drivers/mtd/mtdpart.c:209 allocate_partition() error: uninitialized symbol 'wr_alignment_minor'.

vim +/wr_alignment_minor +192 drivers/mtd/mtdpart.c

^1da177e4c3f4152 Linus Torvalds    2005-04-16   33  
46b5889cc2c54bac Miquel Raynal     2020-01-14   34  static struct mtd_info *allocate_partition(struct mtd_info *parent,
46b5889cc2c54bac Miquel Raynal     2020-01-14   35  					   const struct mtd_partition *part,
46b5889cc2c54bac Miquel Raynal     2020-01-14   36  					   int partno, uint64_t cur_offset)
^1da177e4c3f4152 Linus Torvalds    2005-04-16   37  {
9e3307a169537a6a Boris Brezillon   2020-05-03   38  	struct mtd_info *master = mtd_get_master(parent);
9e3307a169537a6a Boris Brezillon   2020-05-03   39  	int wr_alignment = (parent->flags & MTD_NO_ERASE) ?
9e3307a169537a6a Boris Brezillon   2020-05-03   40  			   master->writesize : master->erasesize;
f861aba424a94bfa John Thomson      2021-01-04   41  	int wr_alignment_minor;
9e3307a169537a6a Boris Brezillon   2020-05-03   42  	u64 parent_size = mtd_is_partition(parent) ?
9e3307a169537a6a Boris Brezillon   2020-05-03   43  			  parent->part.size : parent->size;
9e3307a169537a6a Boris Brezillon   2020-05-03   44  	struct mtd_info *child;
f861aba424a94bfa John Thomson      2021-01-04   45  	u32 remainder, remainder_minor;
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   46  	char *name;
1eeef2d7483a7e3f Chris Packham     2017-06-09   47  	u64 tmp;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   48  
^1da177e4c3f4152 Linus Torvalds    2005-04-16   49  	/* allocate the partition structure */
46b5889cc2c54bac Miquel Raynal     2020-01-14   50  	child = kzalloc(sizeof(*child), GFP_KERNEL);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   51  	name = kstrdup(part->name, GFP_KERNEL);
46b5889cc2c54bac Miquel Raynal     2020-01-14   52  	if (!name || !child) {
b33a2887396a1a52 Atsushi Nemoto    2008-07-19   53  		printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
0a9d72b69da6d8da Rafał Miłecki     2017-06-21   54  		       parent->name);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   55  		kfree(name);
46b5889cc2c54bac Miquel Raynal     2020-01-14   56  		kfree(child);
5daa7b21496aebf0 Roman Tereshonkov 2010-09-17   57  		return ERR_PTR(-ENOMEM);
^1da177e4c3f4152 Linus Torvalds    2005-04-16   58  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16   59  
^1da177e4c3f4152 Linus Torvalds    2005-04-16   60  	/* set up the MTD object for this partition */
46b5889cc2c54bac Miquel Raynal     2020-01-14   61  	child->type = parent->type;
46b5889cc2c54bac Miquel Raynal     2020-01-14   62  	child->part.flags = parent->flags & ~part->mask_flags;
9e3307a169537a6a Boris Brezillon   2020-05-03   63  	child->part.flags |= part->add_flags;
46b5889cc2c54bac Miquel Raynal     2020-01-14   64  	child->flags = child->part.flags;
9e3307a169537a6a Boris Brezillon   2020-05-03   65  	child->part.size = part->size;
46b5889cc2c54bac Miquel Raynal     2020-01-14   66  	child->writesize = parent->writesize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   67  	child->writebufsize = parent->writebufsize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   68  	child->oobsize = parent->oobsize;
46b5889cc2c54bac Miquel Raynal     2020-01-14   69  	child->oobavail = parent->oobavail;
46b5889cc2c54bac Miquel Raynal     2020-01-14   70  	child->subpage_sft = parent->subpage_sft;
46b5889cc2c54bac Miquel Raynal     2020-01-14   71  
46b5889cc2c54bac Miquel Raynal     2020-01-14   72  	child->name = name;
46b5889cc2c54bac Miquel Raynal     2020-01-14   73  	child->owner = parent->owner;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   74  
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   75  	/* NOTE: Historically, we didn't arrange MTDs as a tree out of
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   76  	 * concern for showing the same data in multiple partitions.
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   77  	 * However, it is very useful to have the master node present,
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   78  	 * so the MTD_PARTITIONED_MASTER option allows that. The master
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   79  	 * will have device nodes etc only if this is set, so make the
727dc612c46b8f38 Dan Ehrenberg     2015-04-02   80  	 * parent conditional on that option. Note, this is a way to
46b5889cc2c54bac Miquel Raynal     2020-01-14   81  	 * distinguish between the parent and its partitions in sysfs.
1f24b5a8ecbb2a3c David Brownell    2009-03-26   82  	 */
46b5889cc2c54bac Miquel Raynal     2020-01-14   83  	child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ?
46b5889cc2c54bac Miquel Raynal     2020-01-14   84  			    &parent->dev : parent->dev.parent;
46b5889cc2c54bac Miquel Raynal     2020-01-14   85  	child->dev.of_node = part->of_node;
46b5889cc2c54bac Miquel Raynal     2020-01-14   86  	child->parent = parent;
46b5889cc2c54bac Miquel Raynal     2020-01-14   87  	child->part.offset = part->offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   88  	INIT_LIST_HEAD(&child->partitions);
46b5889cc2c54bac Miquel Raynal     2020-01-14   89  
46b5889cc2c54bac Miquel Raynal     2020-01-14   90  	if (child->part.offset == MTDPART_OFS_APPEND)
46b5889cc2c54bac Miquel Raynal     2020-01-14   91  		child->part.offset = cur_offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   92  	if (child->part.offset == MTDPART_OFS_NXTBLK) {
1eeef2d7483a7e3f Chris Packham     2017-06-09   93  		tmp = cur_offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14   94  		child->part.offset = cur_offset;
1eeef2d7483a7e3f Chris Packham     2017-06-09   95  		remainder = do_div(tmp, wr_alignment);
1eeef2d7483a7e3f Chris Packham     2017-06-09   96  		if (remainder) {
46b5889cc2c54bac Miquel Raynal     2020-01-14   97  			child->part.offset += wr_alignment - remainder;
^1da177e4c3f4152 Linus Torvalds    2005-04-16   98  			printk(KERN_NOTICE "Moving partition %d: "
69423d99fc182a81 Adrian Hunter     2008-12-10   99  			       "0x%012llx -> 0x%012llx\n", partno,
46b5889cc2c54bac Miquel Raynal     2020-01-14  100  			       (unsigned long long)cur_offset,
46b5889cc2c54bac Miquel Raynal     2020-01-14  101  			       child->part.offset);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  102  		}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  103  	}
46b5889cc2c54bac Miquel Raynal     2020-01-14  104  	if (child->part.offset == MTDPART_OFS_RETAIN) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  105  		child->part.offset = cur_offset;
9e3307a169537a6a Boris Brezillon   2020-05-03  106  		if (parent_size - child->part.offset >= child->part.size) {
9e3307a169537a6a Boris Brezillon   2020-05-03  107  			child->part.size = parent_size - child->part.offset -
9e3307a169537a6a Boris Brezillon   2020-05-03  108  					   child->part.size;
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  109  		} else {
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  110  			printk(KERN_ERR "mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  111  				part->name, parent_size - child->part.offset,
9e3307a169537a6a Boris Brezillon   2020-05-03  112  				child->part.size);
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  113  			/* register to preserve ordering */
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  114  			goto out_register;
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  115  		}
1a31368bf92ef2a7 Dmitry Baryshkov  2011-06-06  116  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  117  	if (child->part.size == MTDPART_SIZ_FULL)
9e3307a169537a6a Boris Brezillon   2020-05-03  118  		child->part.size = parent_size - child->part.offset;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  119  
46b5889cc2c54bac Miquel Raynal     2020-01-14  120  	printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  121  	       child->part.offset, child->part.offset + child->part.size,
46b5889cc2c54bac Miquel Raynal     2020-01-14  122  	       child->name);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  123  
^1da177e4c3f4152 Linus Torvalds    2005-04-16  124  	/* let's do some sanity checks */
9e3307a169537a6a Boris Brezillon   2020-05-03  125  	if (child->part.offset >= parent_size) {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  126  		/* let's register it anyway to preserve ordering */
46b5889cc2c54bac Miquel Raynal     2020-01-14  127  		child->part.offset = 0;
9e3307a169537a6a Boris Brezillon   2020-05-03  128  		child->part.size = 0;
ad4635153034c20c Boris Brezillon   2019-01-30  129  
ad4635153034c20c Boris Brezillon   2019-01-30  130  		/* Initialize ->erasesize to make add_mtd_device() happy. */
46b5889cc2c54bac Miquel Raynal     2020-01-14  131  		child->erasesize = parent->erasesize;
b33a2887396a1a52 Atsushi Nemoto    2008-07-19  132  		printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
7788ba71a6046de1 Atsushi Nemoto    2008-07-19  133  			part->name);
f636ffb420f0f905 Atsushi Nemoto    2008-07-19  134  		goto out_register;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  135  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  136  	if (child->part.offset + child->part.size > parent->size) {
9e3307a169537a6a Boris Brezillon   2020-05-03  137  		child->part.size = parent_size - child->part.offset;
69423d99fc182a81 Adrian Hunter     2008-12-10  138  		printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
9e3307a169537a6a Boris Brezillon   2020-05-03  139  			part->name, parent->name, child->part.size);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  140  	}
9e3307a169537a6a Boris Brezillon   2020-05-03  141  
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  142  	if (parent->numeraseregions > 1) {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  143  		/* Deal with variable erase size stuff */
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  144  		int i, max = parent->numeraseregions;
9e3307a169537a6a Boris Brezillon   2020-05-03  145  		u64 end = child->part.offset + child->part.size;
0a9d72b69da6d8da Rafał Miłecki     2017-06-21  146  		struct mtd_erase_region_info *regions = parent->eraseregions;
f861aba424a94bfa John Thomson      2021-01-04  147  		uint32_t erasesize_minor = child->erasesize;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  148  
6910c1368104d50e Atsushi Nemoto    2008-07-19  149  		/* Find the first erase regions which is part of this
6910c1368104d50e Atsushi Nemoto    2008-07-19  150  		 * partition. */
46b5889cc2c54bac Miquel Raynal     2020-01-14  151  		for (i = 0; i < max && regions[i].offset <= child->part.offset;
46b5889cc2c54bac Miquel Raynal     2020-01-14  152  		     i++)
^1da177e4c3f4152 Linus Torvalds    2005-04-16  153  			;
6910c1368104d50e Atsushi Nemoto    2008-07-19  154  		/* The loop searched for the region _behind_ the first one */
a57ca0466af5da83 Roel Kluin        2009-09-18  155  		if (i > 0)
6910c1368104d50e Atsushi Nemoto    2008-07-19  156  			i--;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  157  
6910c1368104d50e Atsushi Nemoto    2008-07-19  158  		for (; i < max && regions[i].offset < end; i++) {
f861aba424a94bfa John Thomson      2021-01-04  159  			/* Pick biggest erasesize */
46b5889cc2c54bac Miquel Raynal     2020-01-14  160  			if (child->erasesize < regions[i].erasesize)
46b5889cc2c54bac Miquel Raynal     2020-01-14  161  				child->erasesize = regions[i].erasesize;
f861aba424a94bfa John Thomson      2021-01-04  162  			/* Pick smallest non-zero erasesize */
f861aba424a94bfa John Thomson      2021-01-04  163  			if ((erasesize_minor > regions[i].erasesize) && (regions[i].erasesize > 0))
f861aba424a94bfa John Thomson      2021-01-04  164  				erasesize_minor = regions[i].erasesize;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  165  		}
f861aba424a94bfa John Thomson      2021-01-04  166  
f861aba424a94bfa John Thomson      2021-01-04  167  		if (erasesize_minor < child->erasesize)
f861aba424a94bfa John Thomson      2021-01-04  168  			child->erasesize_minor = erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  169  
46b5889cc2c54bac Miquel Raynal     2020-01-14  170  		BUG_ON(child->erasesize == 0);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  171  	} else {
^1da177e4c3f4152 Linus Torvalds    2005-04-16  172  		/* Single erase size */
9e3307a169537a6a Boris Brezillon   2020-05-03  173  		child->erasesize = master->erasesize;
f861aba424a94bfa John Thomson      2021-01-04  174  		if (master->erasesize_minor)
f861aba424a94bfa John Thomson      2021-01-04  175  			child->erasesize_minor = master->erasesize_minor;
^1da177e4c3f4152 Linus Torvalds    2005-04-16  176  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  177  
7e439681af829840 Boris Brezillon   2017-09-25  178  	/*
46b5889cc2c54bac Miquel Raynal     2020-01-14  179  	 * Child erasesize might differ from the parent one if the parent
7e439681af829840 Boris Brezillon   2017-09-25  180  	 * exposes several regions with different erasesize. Adjust
7e439681af829840 Boris Brezillon   2017-09-25  181  	 * wr_alignment accordingly.
7e439681af829840 Boris Brezillon   2017-09-25  182  	 */
f861aba424a94bfa John Thomson      2021-01-04  183  	if (!(child->flags & MTD_NO_ERASE)) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  184  		wr_alignment = child->erasesize;
f861aba424a94bfa John Thomson      2021-01-04  185  		if (child->erasesize_minor)
f861aba424a94bfa John Thomson      2021-01-04  186  			wr_alignment_minor = child->erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  187  	}
7e439681af829840 Boris Brezillon   2017-09-25  188  
46b5889cc2c54bac Miquel Raynal     2020-01-14  189  	tmp = mtd_get_master_ofs(child, 0);
1eeef2d7483a7e3f Chris Packham     2017-06-09  190  	remainder = do_div(tmp, wr_alignment);
46b5889cc2c54bac Miquel Raynal     2020-01-14  191  	if ((child->flags & MTD_WRITEABLE) && remainder) {
f861aba424a94bfa John Thomson      2021-01-04 @192  		if (wr_alignment_minor) {
f861aba424a94bfa John Thomson      2021-01-04  193  			tmp = mtd_get_master_ofs(child, 0);
f861aba424a94bfa John Thomson      2021-01-04  194  			remainder_minor = do_div(tmp, wr_alignment_minor);
f861aba424a94bfa John Thomson      2021-01-04  195  			if (remainder_minor == 0)
f861aba424a94bfa John Thomson      2021-01-04  196  				child->erasesize = child->erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  197  		}
f861aba424a94bfa John Thomson      2021-01-04  198  
f861aba424a94bfa John Thomson      2021-01-04  199  		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  200  			child->flags &= ~MTD_WRITEABLE;
1eeef2d7483a7e3f Chris Packham     2017-06-09  201  			printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n",
7788ba71a6046de1 Atsushi Nemoto    2008-07-19  202  				part->name);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  203  		}
f861aba424a94bfa John Thomson      2021-01-04  204  	}
1eeef2d7483a7e3f Chris Packham     2017-06-09  205  
9e3307a169537a6a Boris Brezillon   2020-05-03  206  	tmp = mtd_get_master_ofs(child, 0) + child->part.size;
1eeef2d7483a7e3f Chris Packham     2017-06-09  207  	remainder = do_div(tmp, wr_alignment);
46b5889cc2c54bac Miquel Raynal     2020-01-14  208  	if ((child->flags & MTD_WRITEABLE) && remainder) {
f861aba424a94bfa John Thomson      2021-01-04  209  		if (wr_alignment_minor) {
f861aba424a94bfa John Thomson      2021-01-04  210  			tmp = mtd_get_master_ofs(child, 0) + child->part.size;
f861aba424a94bfa John Thomson      2021-01-04  211  			remainder_minor = do_div(tmp, wr_alignment_minor);
f861aba424a94bfa John Thomson      2021-01-04  212  			if (remainder_minor == 0)
f861aba424a94bfa John Thomson      2021-01-04  213  				child->erasesize = child->erasesize_minor;
f861aba424a94bfa John Thomson      2021-01-04  214  		}
f861aba424a94bfa John Thomson      2021-01-04  215  		if ((!wr_alignment_minor) || (wr_alignment_minor && remainder_minor != 0)) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  216  			child->flags &= ~MTD_WRITEABLE;
1eeef2d7483a7e3f Chris Packham     2017-06-09  217  			printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n",
7788ba71a6046de1 Atsushi Nemoto    2008-07-19  218  				part->name);
^1da177e4c3f4152 Linus Torvalds    2005-04-16  219  		}
f861aba424a94bfa John Thomson      2021-01-04  220  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  221  
9e3307a169537a6a Boris Brezillon   2020-05-03  222  	child->size = child->part.size;
46b5889cc2c54bac Miquel Raynal     2020-01-14  223  	child->ecc_step_size = parent->ecc_step_size;
46b5889cc2c54bac Miquel Raynal     2020-01-14  224  	child->ecc_strength = parent->ecc_strength;
46b5889cc2c54bac Miquel Raynal     2020-01-14  225  	child->bitflip_threshold = parent->bitflip_threshold;
d062d4ede877fcd2 Mike Dunn         2012-04-25  226  
46b5889cc2c54bac Miquel Raynal     2020-01-14  227  	if (master->_block_isbad) {
69423d99fc182a81 Adrian Hunter     2008-12-10  228  		uint64_t offs = 0;
f1a28c02843efcfc Thomas Gleixner   2006-05-30  229  
9e3307a169537a6a Boris Brezillon   2020-05-03  230  		while (offs < child->part.size) {
46b5889cc2c54bac Miquel Raynal     2020-01-14  231  			if (mtd_block_isreserved(child, offs))
46b5889cc2c54bac Miquel Raynal     2020-01-14  232  				child->ecc_stats.bbtblocks++;
46b5889cc2c54bac Miquel Raynal     2020-01-14  233  			else if (mtd_block_isbad(child, offs))
46b5889cc2c54bac Miquel Raynal     2020-01-14  234  				child->ecc_stats.badblocks++;
46b5889cc2c54bac Miquel Raynal     2020-01-14  235  			offs += child->erasesize;
f1a28c02843efcfc Thomas Gleixner   2006-05-30  236  		}
f1a28c02843efcfc Thomas Gleixner   2006-05-30  237  	}
^1da177e4c3f4152 Linus Torvalds    2005-04-16  238  
f636ffb420f0f905 Atsushi Nemoto    2008-07-19  239  out_register:
46b5889cc2c54bac Miquel Raynal     2020-01-14  240  	return child;
7788ba71a6046de1 Atsushi Nemoto    2008-07-19  241  }
7788ba71a6046de1 Atsushi Nemoto    2008-07-19  242  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 32879 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-02-02 20:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04 12:28 [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions John Thomson
2021-01-04 12:28 ` John Thomson
2021-01-05 11:06 ` Dan Carpenter
2021-01-05 11:06   ` Dan Carpenter
2021-02-02 20:08 ` John Thomson
2021-02-02 20:08   ` John Thomson
2021-01-04 19:56 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.