[U-Boot] [PATCH 1/8] imx: i2c: Zap unnecessary malloc() calls

Marek Vasut marex at denx.de
Tue Dec 16 18:00:27 CET 2014


On Tuesday, December 16, 2014 at 05:27:53 PM, Simon Glass wrote:
> Hi Marek,
> 
> On 16 December 2014 at 06:09, Marek Vasut <marex at denx.de> wrote:
> > The malloc() calls are unnecessary, just allocate the stuff on stack.
> > While at it, reorder the code a little, so that only one variable is
> > used for the text, use snprintf() instead of sprintf() and use %01d
> > as a formatting string to avoid any possible overflows.
> > 
> > Signed-off-by: Marek Vasut <marex at denx.de>
> > Cc: Igor Grinberg <grinberg at compulab.co.il>
> > Cc: Nikita Kiryanov <nikita at compulab.co.il>
> > Cc: Sean Cross <xobs at kosagi.com>
> > Cc: Simon Glass <sjg at chromium.org>
> > Cc: Stefano Babic <sbabic at denx.de>
> > Cc: Tim Harvey <tharvey at gateworks.com>
> > ---
> > 
> >  arch/arm/imx-common/i2c-mxv7.c | 24 ++++++++----------------
> >  1 file changed, 8 insertions(+), 16 deletions(-)
> > 
> > diff --git a/arch/arm/imx-common/i2c-mxv7.c
> > b/arch/arm/imx-common/i2c-mxv7.c index 34f5387..1a632e7 100644
> > --- a/arch/arm/imx-common/i2c-mxv7.c
> > +++ b/arch/arm/imx-common/i2c-mxv7.c
> > @@ -73,26 +73,21 @@ static void * const i2c_bases[] = {
> > 
> >  int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
> >  
> >               struct i2c_pads_info *p)
> >  
> >  {
> > 
> > -       char *name1, *name2;
> > +       char name[9];
> > 
> >         int ret;
> >         
> >         if (i2c_index >= ARRAY_SIZE(i2c_bases))
> >         
> >                 return -EINVAL;
> > 
> > -       name1 = malloc(9);
> > -       name2 = malloc(9);
> > -       if (!name1 || !name2)
> > -               return -ENOMEM;
> > -
> > -       sprintf(name1, "i2c_sda%d", i2c_index);
> > -       sprintf(name2, "i2c_scl%d", i2c_index);
> > -       ret = gpio_request(p->sda.gp, name1);
> > +       snprintf(name, sizeof(name), "i2c_sda%01d", i2c_index);
> > +       ret = gpio_request(p->sda.gp, name);
> 
> Does this board use driver model? If not it should be easy to convert
> since one MX6 board supports it. With driver model there is
> gpio_requestf("i2c_sda%01d", i2c_index);

No, not yet, but it's in the pipeline. I am already keeping an eye on a few
conversion patches to get this done.


More information about the U-Boot mailing list