diff mbox

[v3,3/3] mtd: block2mtd: Removes PAGE_MASK as a index to partition size

Message ID 1874445287.7454806.1415535792984.JavaMail.zimbra@redhat.com
State Rejected
Headers show

Commit Message

Rodrigo Freire Nov. 9, 2014, 12:23 p.m. UTC
From: Felix Fietkau <nbd@openwrt.org>

mtd: block2mtd: Removes PAGE_MASK as a index to partition size

PAGE_MASK is no longer needed with the new term.
This patch keeps the device size aligned with the erase_size.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
Signed-off-by: Herton Krzesinski <herton@redhat.com>
---
V3: Separated on a single patch
---
1.7.1

Comments

Brian Norris Nov. 26, 2014, 7:21 a.m. UTC | #1
On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> From: Felix Fietkau <nbd@openwrt.org>
> 
> mtd: block2mtd: Removes PAGE_MASK as a index to partition size

You don't need to repeat the subject here.

> 
> PAGE_MASK is no longer needed with the new term.

This isn't too descriptive. What you probably mean is that we assume the
erase size is always larger than PAGE_SIZE.

> This patch keeps the device size aligned with the erase_size.
> 
> Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> Signed-off-by: Herton Krzesinski <herton@redhat.com>
> ---
> V3: Separated on a single patch
> --- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:40:58.688747820 -0200
> +++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:41:28.054750893 -0200
> @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
>  		goto err_destroy_mutex;
>  
>  	dev->mtd.name = name;
> -
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

You never guaranteed that erase_size is a power of two, so this doesn't
necessarily mask the way you'd like...

But also, why is this even necessary? I see that we should already have
errored out if this was actually significant, since we have above:

	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
		pr_err("erasesize must be a divisor of device size\n");
		goto err_free_block2mtd;
	}

>  	dev->mtd.erasesize = erase_size;
>  	dev->mtd.writesize = 1;
>  	dev->mtd.writebufsize = PAGE_SIZE;

Brian
Rodrigo Freire Nov. 26, 2014, 1:19 p.m. UTC | #2
From: "Brian Norris" <computersforpeace@gmail.com>
Sent: Wednesday, November 26, 2014 5:21:47 AM
Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
partition size

> On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> > PAGE_MASK is no longer needed with the new term.

> This isn't too descriptive. What you probably mean is that we assume the
> erase size is always larger than PAGE_SIZE.

> > This patch keeps the device size aligned with the erase_size.
> >
> > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> > Signed-off-by: Herton Krzesinski <herton@redhat.com>
> > ---
> > V3: Separated on a single patch
> > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
> > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
> > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
> > goto err_destroy_mutex;
> >
> > dev->mtd.name = name;
> > -
> > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);

> You never guaranteed that erase_size is a power of two, so this doesn't
> necessarily mask the way you'd like...

> But also, why is this even necessary? I see that we should already have
> errored out if this was actually significant, since we have above:

> if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> pr_err("erasesize must be a divisor of device size\n");
> goto err_free_block2mtd;
> }

Hello Brian, and thanks for the review.

Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680

I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
Brian Norris Feb. 24, 2015, 8:07 a.m. UTC | #3
On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
> From: "Brian Norris" <computersforpeace@gmail.com>
> Sent: Wednesday, November 26, 2014 5:21:47 AM
> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
> partition size
> 
> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> > > PAGE_MASK is no longer needed with the new term.
> 
> > This isn't too descriptive. What you probably mean is that we assume the
> > erase size is always larger than PAGE_SIZE.
> 
> > > This patch keeps the device size aligned with the erase_size.
> > >
> > > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
> > > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
> > > Signed-off-by: Herton Krzesinski <herton@redhat.com>
> > > ---
> > > V3: Separated on a single patch
> > > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
> > > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
> > > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
> > > goto err_destroy_mutex;
> > >
> > > dev->mtd.name = name;
> > > -
> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
> 
> > You never guaranteed that erase_size is a power of two, so this doesn't
> > necessarily mask the way you'd like...
> 
> > But also, why is this even necessary? I see that we should already have
> > errored out if this was actually significant, since we have above:
> 
> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> > pr_err("erasesize must be a divisor of device size\n");
> > goto err_free_block2mtd;
> > }
> 
> Hello Brian, and thanks for the review.
> 
> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
> 
> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.

OK let's drop this patch from the series. At best, we could just do
something like this instead:

-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size;

But that's really just an unnecessary change.

Brian
Felix Fietkau Feb. 24, 2015, 8:20 a.m. UTC | #4
On 2015-02-24 21:07, Brian Norris wrote:
> On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
>> From: "Brian Norris" <computersforpeace@gmail.com>
>> Sent: Wednesday, November 26, 2014 5:21:47 AM
>> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
>> partition size
>> 
>> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
>> > > PAGE_MASK is no longer needed with the new term.
>> 
>> > This isn't too descriptive. What you probably mean is that we assume the
>> > erase size is always larger than PAGE_SIZE.
>> 
>> > > This patch keeps the device size aligned with the erase_size.
>> > >
>> > > Signed-off-by: Felix Fietkau <nbd@openwrt.org>
>> > > Signed-off-by: Rodrigo Freire <rfreire@redhat.com>
>> > > Signed-off-by: Herton Krzesinski <herton@redhat.com>
>> > > ---
>> > > V3: Separated on a single patch
>> > > --- a/drivers/mtd/devices/block2mtd.c 2014-11-07 17:40:58.688747820 -0200
>> > > +++ b/drivers/mtd/devices/block2mtd.c 2014-11-07 17:41:28.054750893 -0200
>> > > @@ -291,8 +291,7 @@ static struct block2mtd_dev *add_device(
>> > > goto err_destroy_mutex;
>> > >
>> > > dev->mtd.name = name;
>> > > -
>> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
>> 
>> > You never guaranteed that erase_size is a power of two, so this doesn't
>> > necessarily mask the way you'd like...
>> 
>> > But also, why is this even necessary? I see that we should already have
>> > errored out if this was actually significant, since we have above:
>> 
>> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
>> > pr_err("erasesize must be a divisor of device size\n");
>> > goto err_free_block2mtd;
>> > }
>> 
>> Hello Brian, and thanks for the review.
>> 
>> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
>> 
>> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
> 
> OK let's drop this patch from the series. At best, we could just do
> something like this instead:
> 
> -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> 
> But that's really just an unnecessary change.
If I remember correctly, it was problematic to have a dev->mtd.size
value which is not a multiple of the erase size. I think that was the
reason for patch 3.

- Felix
Brian Norris Feb. 24, 2015, 8:27 a.m. UTC | #5
On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
> On 2015-02-24 21:07, Brian Norris wrote:
> > On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
> >> From: "Brian Norris" <computersforpeace@gmail.com>
> >> Sent: Wednesday, November 26, 2014 5:21:47 AM
> >> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
> >> partition size
> >> 
> >> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
> >> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> >> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
> >> 
> >> > You never guaranteed that erase_size is a power of two, so this doesn't
> >> > necessarily mask the way you'd like...
> >> 
> >> > But also, why is this even necessary? I see that we should already have
> >> > errored out if this was actually significant, since we have above:
> >> 
> >> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> >> > pr_err("erasesize must be a divisor of device size\n");
> >> > goto err_free_block2mtd;
> >> > }
> >> 
> >> Hello Brian, and thanks for the review.
> >> 
> >> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
> >> 
> >> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
> > 
> > OK let's drop this patch from the series. At best, we could just do
> > something like this instead:
> > 
> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> > 
> > But that's really just an unnecessary change.
> If I remember correctly, it was problematic to have a dev->mtd.size
> value which is not a multiple of the erase size. I think that was the
> reason for patch 3.

The what's this for?

	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
		pr_err("erasesize must be a divisor of device size\n");
		goto err_free_block2mtd;
	}

Brian
Felix Fietkau Feb. 24, 2015, 8:30 a.m. UTC | #6
On 2015-02-24 21:27, Brian Norris wrote:
> On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
>> On 2015-02-24 21:07, Brian Norris wrote:
>> > On Wed, Nov 26, 2014 at 08:19:32AM -0500, Rodrigo Freire wrote:
>> >> From: "Brian Norris" <computersforpeace@gmail.com>
>> >> Sent: Wednesday, November 26, 2014 5:21:47 AM
>> >> Subject: Re: [PATCH v3 3/3] mtd: block2mtd: Removes PAGE_MASK as a index to
>> >> partition size
>> >> 
>> >> > On Sun, Nov 09, 2014 at 07:23:12AM -0500, Rodrigo Freire wrote:
>> >> > > - dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> >> > > + dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
>> >> 
>> >> > You never guaranteed that erase_size is a power of two, so this doesn't
>> >> > necessarily mask the way you'd like...
>> >> 
>> >> > But also, why is this even necessary? I see that we should already have
>> >> > errored out if this was actually significant, since we have above:
>> >> 
>> >> > if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
>> >> > pr_err("erasesize must be a divisor of device size\n");
>> >> > goto err_free_block2mtd;
>> >> > }
>> >> 
>> >> Hello Brian, and thanks for the review.
>> >> 
>> >> Honestly, I'd leave that untouched, but Jörn pointed that it could be a issue at https://lkml.org/lkml/2014/9/9/680
>> >> 
>> >> I'd happily let it go without this patch 3, unless Jörg wants to state otherwise.
>> > 
>> > OK let's drop this patch from the series. At best, we could just do
>> > something like this instead:
>> > 
>> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
>> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
>> > 
>> > But that's really just an unnecessary change.
>> If I remember correctly, it was problematic to have a dev->mtd.size
>> value which is not a multiple of the erase size. I think that was the
>> reason for patch 3.
> 
> The what's this for?
> 
> 	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> 		pr_err("erasesize must be a divisor of device size\n");
> 		goto err_free_block2mtd;
> 	}
I think we should just trim the mtd size to a multiple of erase size and
remove this check. It is a bit impractical for many cases.

- Felix
Brian Norris Feb. 24, 2015, 8:40 a.m. UTC | #7
On Tue, Feb 24, 2015 at 09:30:21PM +1300, Felix Fietkau wrote:
> On 2015-02-24 21:27, Brian Norris wrote:
> > On Tue, Feb 24, 2015 at 09:20:31PM +1300, Felix Fietkau wrote:
> >> On 2015-02-24 21:07, Brian Norris wrote:
> >> > OK let's drop this patch from the series. At best, we could just do
> >> > something like this instead:
> >> > 
> >> > -	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
> >> > +	dev->mtd.size = dev->blkdev->bd_inode->i_size;
> >> > 
> >> > But that's really just an unnecessary change.
> >> If I remember correctly, it was problematic to have a dev->mtd.size
> >> value which is not a multiple of the erase size. I think that was the
> >> reason for patch 3.
> > 
> > The what's this for?
> > 
> > 	if ((long)dev->blkdev->bd_inode->i_size % erase_size) {
> > 		pr_err("erasesize must be a divisor of device size\n");
> > 		goto err_free_block2mtd;
> > 	}
> I think we should just trim the mtd size to a multiple of erase size and
> remove this check. It is a bit impractical for many cases.

Well that's not the subject of anything in this series, and this patch
does not stand alone well, so I'm not taking it. Feel free to send a
different patch if you have good reason to.

Brian
diff mbox

Patch

--- a/drivers/mtd/devices/block2mtd.c	2014-11-07 17:40:58.688747820 -0200
+++ b/drivers/mtd/devices/block2mtd.c	2014-11-07 17:41:28.054750893 -0200
@@ -291,8 +291,7 @@  static struct block2mtd_dev *add_device(
 		goto err_destroy_mutex;
 
 	dev->mtd.name = name;
-
-	dev->mtd.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
+	dev->mtd.size = dev->blkdev->bd_inode->i_size & ~(erase_size - 1);
 	dev->mtd.erasesize = erase_size;
 	dev->mtd.writesize = 1;
 	dev->mtd.writebufsize = PAGE_SIZE;