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 3/4] mtd: atmel_nand: alloc memory instead of use static array for pmecc data
Date: Fri, 14 Jun 2013 15:29:39 -0500	[thread overview]
Message-ID: <1371241779.2996.8@snotra> (raw)
In-Reply-To: <1371208842-28909-4-git-send-email-josh.wu@atmel.com> (from josh.wu@atmel.com on Fri Jun 14 06:20:41 2013)

On 06/14/2013 06:20:41 AM, Josh Wu wrote:
> +static int pmecc_data_alloc(struct atmel_nand_host *host)
> +{
> +	const int cap = host->pmecc_corr_cap;
> +	int size;
> +
> +	size = (2 * cap + 1) * sizeof(int16_t);
> +	host->pmecc_partial_syn = (int16_t *)malloc(size);
> +	host->pmecc_si = (int16_t *)malloc(size);
> +	host->pmecc_lmu = (int16_t *)malloc((cap + 1) *  
> sizeof(int16_t));
> +	host->pmecc_smu = (int16_t *)
> +		malloc((cap + 2) * size);
> +
> +	size = (cap + 1) * sizeof(int);
> +	host->pmecc_mu = (int *)malloc(size);
> +	host->pmecc_dmu = (int *)malloc(size);
> +	host->pmecc_delta = (int *)malloc(size);

Don't cast malloc's return value.  Checkpatch would catch this, except  
that it hasn't been updated to deal with U-Boot using plain "malloc"  
rather than kmalloc and friends.

> +	if (!host->pmecc_partial_syn ||
> +		!host->pmecc_si ||
> +		!host->pmecc_lmu ||
> +		!host->pmecc_smu ||
> +		!host->pmecc_mu ||
> +		!host->pmecc_dmu ||
> +		!host->pmecc_delta)
> +		return -ENOMEM;

Don't line up continuation lines with the body of the "if".  It makes  
it harder to see where the condition ends and the body begins.

Please free any of the allocations that did succeed before returning  
-ENOMEM.

>  static void pmecc_gen_syndrome(struct mtd_info *mtd, int sector)
>  {
>  	struct nand_chip *nand_chip = mtd->priv;
> @@ -710,6 +751,13 @@ static int atmel_pmecc_nand_init_params(struct  
> nand_chip *nand,
>  		return 0;
>  	}
> 
> +	/* Allocate data for PMECC computation */
> +	if (pmecc_data_alloc(host)) {
> +		printk(KERN_ERR "Cannot allocate memory for PMECC  
> computation!\n");
> +		pmecc_data_free(host);
> +		return -ENOMEM;
> +	}

In the Linux driver this is dev_err, so why printk(KERN_ERR here?  Just  
use printf -- or move the dev_err compatibility out of the USB code so  
the rest of U-Boot can use it.

-Scott

  reply	other threads:[~2013-06-14 20:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-14 11:20 [U-Boot] [PATCH 0/4] ARM: at91: atmel_nand: check ONFI ecc minimum requirement Josh Wu
2013-06-14 11:20 ` [U-Boot] [PATCH 1/4] ARM: at91: atmel_nand: pmecc driver will select the galois table by sector size Josh Wu
2013-06-14 11:20 ` [U-Boot] [PATCH 2/4] ARM: at91: sama5d3: remove unused definition about PMECC alpha table offset Josh Wu
2013-06-14 11:20 ` [U-Boot] [PATCH 3/4] mtd: atmel_nand: alloc memory instead of use static array for pmecc data Josh Wu
2013-06-14 20:29   ` Scott Wood [this message]
2013-06-14 11:20 ` [U-Boot] [PATCH 4/4] ARM: at91: atmel_nand: add code to check the ONFI parameter ECC requirement Josh Wu
2013-06-14 20:38   ` Scott Wood

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=1371241779.2996.8@snotra \
    --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