[PATCH 2/3 v3] P4080/mtd: Only make elbc nand driver detect nand flash partitions

Zang Roy-R61911 r61911 at freescale.com
Thu Sep 16 20:39:40 EST 2010



> -----Original Message-----
> From: Anton Vorontsov [mailto:cbouatmailru at gmail.com]
> Sent: Thursday, September 16, 2010 18:14 PM
> To: Zang Roy-R61911
> Cc: Wood Scott-B07421; dedekind1 at gmail.com; Lan Chunhe-B25806; linuxppc-
> dev at ozlabs.org; linux-mtd at lists.infradead.org; akpm at linux-foundation.org;
> dwmw2 at infradead.org; Gala Kumar-B11780
> Subject: Re: [PATCH 2/3 v3] P4080/mtd: Only make elbc nand driver detect nand
> flash partitions
> 
> On Thu, Sep 16, 2010 at 06:08:14PM +0800, Zang Roy-R61911 wrote:
> [...]
> > Interesting.
> > How about this?
> > #include <stdio.h>
> > #include <malloc.h>
> >
> > char *foo;
> >
> > void probe(void)
> > {
> >         char *bar = NULL;
> >
> >         if (!foo) {
> >                 bar = malloc(sizeof(*bar));
> >                 if (!bar)
> >                         return;
> >                 foo = bar;
> >         } else
> > 		   bar = foo;
> 
> This willl work of course; but I'd write it as
> 
> foo_lock();
> if (!foo)
> 	foo = alloc();
> foo_unlock();
> 
> bar = foo;
> bar->baz;
But my code has some assignment for "foo" instead of a simple
allocation, how about this way for my code:
DEFINE_MUTEX(fsl_elbc_mutex);
...
static int __devinit fsl_elbc_nand_probe(struct platform_device *dev)
{
...
        mutex_lock(&fsl_lbc_mutex);
        if (!fsl_lbc_ctrl_dev->nand) {
                elbc_fcm_ctrl = kzalloc(sizeof(*elbc_fcm_ctrl), GFP_KERNEL);
                if (!elbc_fcm_ctrl) {
                        dev_err(fsl_lbc_ctrl_dev->dev, "failed to allocate "
                                        "memory\n");
                        ret = -ENOMEM;
                        goto err;
                }

                elbc_fcm_ctrl->read_bytes = 0;
                elbc_fcm_ctrl->index = 0;
                elbc_fcm_ctrl->addr = NULL;

                spin_lock_init(&elbc_fcm_ctrl->controller.lock);
                init_waitqueue_head(&elbc_fcm_ctrl->controller.wq);
                fsl_lbc_ctrl_dev->nand = elbc_fcm_ctrl;
        } else
                elbc_fcm_ctrl = fsl_lbc_ctrl_dev->nand;
        mutex_unlock(&fsl_lbc_mutex);

        elbc_fcm_ctrl->chips[bank] = priv;
...
}

Any comment?
Thanks.
Roy





More information about the Linuxppc-dev mailing list