Re: [PATCH 1/2] staging: iio replaced kmalloc with local variables.

From: Geert Uytterhoeven
Date: Mon Jun 06 2011 - 15:13:34 EST


On Mon, Jun 6, 2011 at 21:07, anish <anish198519851985@xxxxxxxxx> wrote:
> From: anish kumar <anish198519851985@xxxxxxxxx>
>
> Replace kmalloc with local variables as it was un-necessary and

Is it really unnecessary?
Or is this hardware that cannot transfer buffers on the stack?
IIRC there have been similar problems with SCSI command buffers on the stack.

> also removed the redudant code after this change.
>
> Signed-off-by: anish kumar <anish198519851985@xxxxxxxxx>
> ---
> Âdrivers/staging/iio/accel/kxsd9.c   Â|  19 +++----------------
> Âdrivers/staging/iio/adc/max1363_core.c | Â Â3 +--
> Â2 files changed, 4 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/staging/iio/accel/kxsd9.c b/drivers/staging/iio/accel/kxsd9.c
> index 431aa0f..7f6e6e5 100644
> --- a/drivers/staging/iio/accel/kxsd9.c
> +++ b/drivers/staging/iio/accel/kxsd9.c
> @@ -255,7 +255,10 @@ static const struct attribute_group kxsd9_attribute_group = {
>
> Âstatic int __devinit kxsd9_power_up(struct spi_device *spi)
> Â{
> + Â Â Â struct spi_message msg;
> Â Â Â Âint ret;
> + Â Â Â u8 tx[2], tx2[2];
> +
> Â Â Â Âstruct spi_transfer xfers[2] = {
> Â Â Â Â Â Â Â Â{
> Â Â Â Â Â Â Â Â Â Â Â Â.bits_per_word = 8,
> @@ -267,19 +270,7 @@ static int __devinit kxsd9_power_up(struct spi_device *spi)
> Â Â Â Â Â Â Â Â Â Â Â Â.cs_change = 1,
> Â Â Â Â Â Â Â Â},
> Â Â Â Â};
> - Â Â Â struct spi_message msg;
> - Â Â Â u8 *tx2;
> - Â Â Â u8 *tx = kmalloc(2, GFP_KERNEL);
>
> - Â Â Â if (tx == NULL) {
> - Â Â Â Â Â Â Â ret = -ENOMEM;
> - Â Â Â Â Â Â Â goto error_ret;
> - Â Â Â }
> - Â Â Â tx2 = kmalloc(2, GFP_KERNEL);
> - Â Â Â if (tx2 == NULL) {
> - Â Â Â Â Â Â Â ret = -ENOMEM;
> - Â Â Â Â Â Â Â goto error_free_tx;
> - Â Â Â }
> Â Â Â Âtx[0] = 0x0d;
> Â Â Â Âtx[1] = 0x40;
>
> @@ -293,10 +284,6 @@ static int __devinit kxsd9_power_up(struct spi_device *spi)
> Â Â Â Âspi_message_add_tail(&xfers[1], &msg);
> Â Â Â Âret = spi_sync(spi, &msg);
>
> - Â Â Â kfree(tx2);
> -error_free_tx:
> - Â Â Â kfree(tx);
> -error_ret:
> Â Â Â Âreturn ret;
>
> Â};
> diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c
> index 1037087..0026242 100644
> --- a/drivers/staging/iio/adc/max1363_core.c
> +++ b/drivers/staging/iio/adc/max1363_core.c
> @@ -207,7 +207,7 @@ static int max1363_write_basic_config(struct i2c_client *client,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âunsigned char d2)
> Â{
> Â Â Â Âint ret;
> - Â Â Â u8 *tx_buf = kmalloc(2, GFP_KERNEL);
> + Â Â Â u8 tx_buf[2];
>
> Â Â Â Âif (!tx_buf)
> Â Â Â Â Â Â Â Âreturn -ENOMEM;
> @@ -215,7 +215,6 @@ static int max1363_write_basic_config(struct i2c_client *client,
> Â Â Â Âtx_buf[1] = d2;
>
> Â Â Â Âret = i2c_master_send(client, tx_buf, 2);
> - Â Â Â kfree(tx_buf);
>
> Â Â Â Âreturn (ret > 0) ? 0 : ret;
> Â}
> --
> 1.7.0.4

Gr{oetje,eeting}s,

            Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
             Â Â -- Linus Torvalds
--
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/