Re: s3c24xx nand: add command line partition table parsing support (resend)

From: Russell King - ARM Linux
Date: Thu Sep 18 2008 - 07:27:26 EST


On Thu, Sep 18, 2008 at 09:13:01AM +0800, Conke Hu wrote:
> @@ -875,7 +890,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev,
>
> /* allocate our information */
>
> - size = nr_sets * sizeof(*info->mtds);
> + size = nr_sets * (sizeof(*info->mtds) + S3C_NAND_NAME_LEN);

Why not make the 'name' part of struct s3c2410_nand_mtd? IOW:

struct s3c2410_nand_mtd {
struct mtd_info mtd;
struct nand_chip chip;
struct s3c2410_nand_set *set;
struct s3c2410_nand_info *info;
int scan_res;
+ char name[S3C_NAND_NAME_LEN];
};

That way you can avoid...

> info->mtds = kmalloc(size, GFP_KERNEL);
> if (info->mtds == NULL) {
> dev_err(&pdev->dev, "failed to allocate mtd storage\n");
> @@ -888,10 +903,15 @@ static int s3c24xx_nand_probe(struct
> platform_device *pdev,
> /* initialise all possible chips */
>
> nmtd = info->mtds;
> + name = (char *)(info->mtds + nr_sets);

This pointer arithmetic.

>
> for (setno = 0; setno < nr_sets; setno++, nmtd++) {
> pr_debug("initialising set %d (%p, info %p)\n", setno,
> nmtd, info);
>
> + sprintf(name, "s3c_nand%d", setno);
> + nmtd->mtd.name = name;
> + name += S3C_NAND_NAME_LEN;
> +

And this can become the more safe:

snprintf(nmtd->name, sizeof(nmtd->name), "s3c_nand%d", setno);
nmtd->mtd.name = nmtd->name;

> s3c2410_nand_init_chip(info, nmtd, sets);
>
> nmtd->scan_res = nand_scan_ident(&nmtd->mtd,
>
> -------------------------------------------------------------------
> List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm-kernel
> FAQ: http://www.arm.linux.org.uk/mailinglists/faq.php
> Etiquette: http://www.arm.linux.org.uk/mailinglists/etiquette.php
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/