All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org
Subject: Re: [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
Date: Tue, 05 Jan 2021 14:06:51 +0300	[thread overview]
Message-ID: <20210105110651.GX2809@kadam> (raw)
In-Reply-To: <20210104122853.18428-1-git@johnthomson.fastmail.com.au>

[-- 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 --]

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: Re: [RFC PATCH] mtd: spi-nor: write support for minor aligned partitions
Date: Tue, 05 Jan 2021 14:06:51 +0300	[thread overview]
Message-ID: <20210105110651.GX2809@kadam> (raw)
In-Reply-To: <20210104122853.18428-1-git@johnthomson.fastmail.com.au>

[-- 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 --]

  reply	other threads:[~2021-01-05 11:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2021-01-05 11:06   ` Dan Carpenter
2021-02-02 20:08 ` John Thomson
2021-02-02 20:08   ` John Thomson
  -- strict thread matches above, loose matches on Subject: below --
2021-01-04 19:56 kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210105110651.GX2809@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=kbuild@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.