public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] mtd: pxa3xx_nand: Correct allocation and init bug
Date: Fri, 23 Oct 2015 13:20:29 -0500	[thread overview]
Message-ID: <1445624429.701.184.camel@freescale.com> (raw)
In-Reply-To: <1445622596-18764-1-git-send-email-kevin.smith@elecsyscorp.com>

On Fri, 2015-10-23 at 17:49 +0000, Kevin Smith wrote:
> Correct a null pointer dereference in board_nand_init().  Zeroed
> memory was allocated, then immediately dereferenced, which is a
> null dereference.  The dereference is completely removed, since
> this pointer is later initialized in alloc_nand_resources.
> 
> The allocation size is reduced from what was introduced from the
> Linux kernel, as U-boot uses the statically allocated nand_info
> instead of needing to dynamically allocate an mtd_info instance.
> 
> Also, some pointer math was corrected in the initialization of
> the nand_chip pointer.
> 
> Signed-off-by: Kevin Smith <kevin.smith@elecsyscorp.com>
> Cc: Stefan Roese <sr@denx.de>
> Cc: Luka Perkov <luka.perkov@sartura.hr>
> Cc: Scott Wood <scottwood@freescale.com>
> ---
>  drivers/mtd/nand/pxa3xx_nand.c | 17 +++++------------
>  1 file changed, 5 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
> index 1565a9a..e5ea5c2 100644
> --- a/drivers/mtd/nand/pxa3xx_nand.c
> +++ b/drivers/mtd/nand/pxa3xx_nand.c
> @@ -1486,8 +1486,8 @@ static int alloc_nand_resource(struct 
> pxa3xx_nand_info *info)
>       info->variant = pxa3xx_nand_get_variant();
>       for (cs = 0; cs < pdata->num_cs; cs++) {
>               mtd = &nand_info[cs];
> -             chip = (struct nand_chip *)info +
> -                     sizeof(struct pxa3xx_nand_host);
> +             chip = (struct nand_chip *)
> +                     ((u8 *)&info[1] + sizeof(*host) * cs);

Yuck.  Could you please rework this driver to not play games with pointers 
and one giant allocation?  Why can't this function allocate each region it 
needs separately?

-Scott

  reply	other threads:[~2015-10-23 18:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23 17:49 [U-Boot] [PATCH] mtd: pxa3xx_nand: Correct allocation and init bug Kevin Smith
2015-10-23 18:20 ` Scott Wood [this message]
2015-10-23 19:56   ` Kevin Smith
2015-10-23 20:34     ` Scott Wood
2015-10-23 20:57       ` Kevin Smith
2015-10-23 21:14         ` Scott Wood
2015-10-23 21:18           ` Kevin Smith

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=1445624429.701.184.camel@freescale.com \
    --to=scottwood@freescale.com \
    --cc=u-boot@lists.denx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox