mirror of
https://xff.cz/git/u-boot/
synced 2025-10-26 16:13:55 +01:00
imx: i2c: Zap unnecessary malloc() calls
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@denx.de> Cc: Igor Grinberg <grinberg@compulab.co.il> Cc: Nikita Kiryanov <nikita@compulab.co.il> Cc: Sean Cross <xobs@kosagi.com> Cc: Simon Glass <sjg@chromium.org> Cc: Stefano Babic <sbabic@denx.de> Cc: Tim Harvey <tharvey@gateworks.com> Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
This commit is contained in:
committed by
Stefano Babic
parent
c86efd85e9
commit
cd3c5896b6
@@ -73,26 +73,21 @@ static void * const i2c_bases[] = {
|
|||||||
int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
|
int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
|
||||||
struct i2c_pads_info *p)
|
struct i2c_pads_info *p)
|
||||||
{
|
{
|
||||||
char *name1, *name2;
|
char name[9];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (i2c_index >= ARRAY_SIZE(i2c_bases))
|
if (i2c_index >= ARRAY_SIZE(i2c_bases))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
name1 = malloc(9);
|
snprintf(name, sizeof(name), "i2c_sda%01d", i2c_index);
|
||||||
name2 = malloc(9);
|
ret = gpio_request(p->sda.gp, name);
|
||||||
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);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_req1;
|
return ret;
|
||||||
|
|
||||||
ret = gpio_request(p->scl.gp, name2);
|
snprintf(name, sizeof(name), "i2c_scl%01d", i2c_index);
|
||||||
|
ret = gpio_request(p->scl.gp, name);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_req2;
|
goto err_req;
|
||||||
|
|
||||||
/* Enable i2c clock */
|
/* Enable i2c clock */
|
||||||
ret = enable_i2c_clk(1, i2c_index);
|
ret = enable_i2c_clk(1, i2c_index);
|
||||||
@@ -112,11 +107,8 @@ int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
|
|||||||
err_idle:
|
err_idle:
|
||||||
err_clk:
|
err_clk:
|
||||||
gpio_free(p->scl.gp);
|
gpio_free(p->scl.gp);
|
||||||
err_req2:
|
err_req:
|
||||||
gpio_free(p->sda.gp);
|
gpio_free(p->sda.gp);
|
||||||
err_req1:
|
|
||||||
free(name1);
|
|
||||||
free(name2);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user