Skip to contentSkip to conversation

NAND buffer allocation fails

DISCUSSION Tony Prisk 1 participant 2 messages Jun 7, 2013 Memory technology devices (MTD)

lore
Share & tools
lore

Tony Prisk

author
#0 lore raw

Could someone explain why the following situation might occur:

In drivers/mtd/nand/nand_base.c, we have:

int nand_scan_tail(struct mtd_info *mtd)

{
    int i;
    struct nand_chip *chip = mtd->priv;

    /* New bad blocks should be marked in OOB, flash-based BBT, or both */
    BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
            !(chip->bbt_options & NAND_BBT_USE_FLASH));

    if (!(chip->options & NAND_OWN_BUFFERS))
        chip->buffers = kmalloc(sizeof(*chip->buffers), GFP_KERNEL);
    if (!chip->buffers)
        return -ENOMEM;

...

For some reason, the kmalloc always fails on my configuration/hardware (arch-vt8500: WonderMedia/VIA APC8750).

The strange thing is that if I add the NAND_OWN_BUFFERS option, and allocate my own buffers in the driver probe everything is fine. Driver probe code below:

    priv->nand.buffers = devm_kzalloc(priv->dev, 
sizeof(*priv->nand.buffers), GFP_KERNEL);
    if (!priv->nand.buffers) {
        dev_err(priv->dev, "failed to allocate NAND buffers\n");
        return -ENOMEM;
    }

The devm_kzalloc does occur earlier than the nand_scan_tail alloc would have, but there doesn't appear to be a shortage of memory on the platform so I don't think it's failing for a memory shortage.

Is there any real difference between using kmalloc and devm_kzalloc to allocate the buffer (other than the obvious 0'ing of the buffer)? Why would one call fail and the other succeed?

Regards
Tony Prisk

author
#1 lore raw
Quoted 38 lines · Tony Prisk

Could someone explain why the following situation might occur:

In drivers/mtd/nand/nand_base.c, we have:

int nand_scan_tail(struct mtd_info *mtd)

{
    int i;
    struct nand_chip *chip = mtd->priv;

    /* New bad blocks should be marked in OOB, flash-based BBT, or 
both */
    BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
            !(chip->bbt_options & NAND_BBT_USE_FLASH));

    if (!(chip->options & NAND_OWN_BUFFERS))
        chip->buffers = kmalloc(sizeof(*chip->buffers), GFP_KERNEL);
    if (!chip->buffers)
        return -ENOMEM;

...

For some reason, the kmalloc always fails on my configuration/hardware (arch-vt8500: WonderMedia/VIA APC8750).

The strange thing is that if I add the NAND_OWN_BUFFERS option, and allocate my own buffers in the driver probe everything is fine. Driver probe code below:

    priv->nand.buffers = devm_kzalloc(priv->dev, 
sizeof(*priv->nand.buffers), GFP_KERNEL);
    if (!priv->nand.buffers) {
        dev_err(priv->dev, "failed to allocate NAND buffers\n");
        return -ENOMEM;
    }

The devm_kzalloc does occur earlier than the nand_scan_tail alloc would have, but there doesn't appear to be a shortage of memory on the platform so I don't think it's failing for a memory shortage.

Quoted 6 lines

Is there any real difference between using kmalloc and devm_kzalloc to allocate the buffer (other than the obvious 0'ing of the buffer)? Why would one call fail and the other succeed?

Regards
Tony Prisk

Resend to correct the linux-arm-kernel mailing list address.

Tony P