diff mbox

mtdoops: fix the oops_page_used array size

Message ID 1322563758-26317-1-git-send-email-roman.tereshonkov@nokia.com
State Accepted
Commit 556f063580db2953a7e53cd46b47724246320f60
Headers show

Commit Message

Roman Tereshonkov Nov. 29, 2011, 10:49 a.m. UTC
The array of unsigned long pointed by oops_page_used is allocated
by vmalloc which requires the size to be in bytes.

Signed-off-by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
---
 drivers/mtd/mtdoops.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Artem Bityutskiy Dec. 4, 2011, 1:44 p.m. UTC | #1
On Tue, 2011-11-29 at 12:49 +0200, Roman Tereshonkov wrote:
> The array of unsigned long pointed by oops_page_used is allocated
> by vmalloc which requires the size to be in bytes.
> 
> Signed-off-by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
> ---
>  drivers/mtd/mtdoops.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> index 1e2fa62..0782b31 100644
> --- a/drivers/mtd/mtdoops.c
> +++ b/drivers/mtd/mtdoops.c
> @@ -369,7 +369,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
>  
>  	/* oops_page_used is a bit field */
>  	cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages,
> -			BITS_PER_LONG));
> +			BITS_PER_LONG) * sizeof(unsigned long));

But it is already in bytes. I do not understand which problem this patch
fixes - it looks incorrect to me.
Roman Tereshonkov Dec. 7, 2011, 3:25 p.m. UTC | #2
On Sun, Dec 04, 2011 at 03:44:57PM +0200, Artem Bityutskiy wrote:
> On Tue, 2011-11-29 at 12:49 +0200, Roman Tereshonkov wrote:
> > The array of unsigned long pointed by oops_page_used is allocated
> > by vmalloc which requires the size to be in bytes.
> > 
> > Signed-off-by: Roman Tereshonkov <roman.tereshonkov at nokia.com>
> > ---
> >  drivers/mtd/mtdoops.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
> > index 1e2fa62..0782b31 100644
> > --- a/drivers/mtd/mtdoops.c
> > +++ b/drivers/mtd/mtdoops.c
> > @@ -369,7 +369,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
> >  
> >  	/* oops_page_used is a bit field */
> >  	cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages,
> > -			BITS_PER_LONG));
> > +			BITS_PER_LONG) * sizeof(unsigned long));
> 
> But it is already in bytes. I do not understand which problem this patch
> fixes - it looks incorrect to me.

BITS_PER_LONG is equal to 32.
If we want to allocate memory for 32 pages with one bit per page then
32 / BITS_PER_LONG  is equal to 1 byte that is 8 bits.
To fix it we need to multiply the result by sizeof(unsigned long) equal to 4.



Regards
Roman Tereshonkov
> 
> -- 
> Best Regards,
> Artem Bityutskiy
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: signature.asc
> Type: application/pgp-signature
> Size: 836 bytes
> Desc: This is a digitally signed message part
> URL: <http://lists.infradead.org/pipermail/linux-mtd/attachments/20111204/a96b926e/attachment.sig>
Artem Bityutskiy Dec. 8, 2011, 9:58 p.m. UTC | #3
On Wed, 2011-12-07 at 17:25 +0200, Roman Tereshonkov wrote:
> BITS_PER_LONG is equal to 32.
> If we want to allocate memory for 32 pages with one bit per page then
> 32 / BITS_PER_LONG  is equal to 1 byte that is 8 bits.
> To fix it we need to multiply the result by sizeof(unsigned long)
> equal to 4.

Ah, you are right. This should also go to the stable tree, I've
added Cc: stable@kernel.org

Pushed to l2-mtd-2.6.git thanks.

Artem.
diff mbox

Patch

diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 1e2fa62..0782b31 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -369,7 +369,7 @@  static void mtdoops_notify_add(struct mtd_info *mtd)
 
 	/* oops_page_used is a bit field */
 	cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages,
-			BITS_PER_LONG));
+			BITS_PER_LONG) * sizeof(unsigned long));
 	if (!cxt->oops_page_used) {
 		printk(KERN_ERR "mtdoops: could not allocate page array\n");
 		return;