summaryrefslogtreecommitdiff
path: root/drivers/hwmon/max1111.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2011-07-25 23:46:10 +0400
committerJean Delvare <khali@endymion.delvare>2011-07-25 23:46:10 +0400
commitd737c09cfb78424276e3eb45d1e7af578a451fd4 (patch)
treeb8c9430670ce30c9d2100c87def3720bbe24f66f /drivers/hwmon/max1111.c
parent3d30f9e69f152d8667b3b13ac6f566e6e76ef7b9 (diff)
downloadlinux-d737c09cfb78424276e3eb45d1e7af578a451fd4.tar.xz
hwmon: (max1111) Avoid extra memory allocations
We can allocate the tx and rx buffers as part of our data structure. Doing so is faster and spares memory. Signed-off-by: Jean Delvare <khali@linux-fr.org> Tested-by: Stanislav Brabec <utx@penguin.cz>
Diffstat (limited to 'drivers/hwmon/max1111.c')
-rw-r--r--drivers/hwmon/max1111.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/drivers/hwmon/max1111.c b/drivers/hwmon/max1111.c
index 14335bbc9bdc..c97b78ef9116 100644
--- a/drivers/hwmon/max1111.c
+++ b/drivers/hwmon/max1111.c
@@ -38,8 +38,8 @@ struct max1111_data {
struct device *hwmon_dev;
struct spi_message msg;
struct spi_transfer xfer[2];
- uint8_t *tx_buf;
- uint8_t *rx_buf;
+ uint8_t tx_buf[MAX1111_TX_BUF_SIZE];
+ uint8_t rx_buf[MAX1111_RX_BUF_SIZE];
struct mutex drvdata_lock;
/* protect msg, xfer and buffers from multiple access */
};
@@ -131,33 +131,23 @@ static const struct attribute_group max1111_attr_group = {
.attrs = max1111_attributes,
};
-static int setup_transfer(struct max1111_data *data)
+static int __devinit setup_transfer(struct max1111_data *data)
{
struct spi_message *m;
struct spi_transfer *x;
- data->tx_buf = kmalloc(MAX1111_TX_BUF_SIZE, GFP_KERNEL);
- if (!data->tx_buf)
- return -ENOMEM;
-
- data->rx_buf = kmalloc(MAX1111_RX_BUF_SIZE, GFP_KERNEL);
- if (!data->rx_buf) {
- kfree(data->tx_buf);
- return -ENOMEM;
- }
-
m = &data->msg;
x = &data->xfer[0];
spi_message_init(m);
x->tx_buf = &data->tx_buf[0];
- x->len = 1;
+ x->len = MAX1111_TX_BUF_SIZE;
spi_message_add_tail(x, m);
x++;
x->rx_buf = &data->rx_buf[0];
- x->len = 2;
+ x->len = MAX1111_RX_BUF_SIZE;
spi_message_add_tail(x, m);
return 0;
@@ -192,7 +182,7 @@ static int __devinit max1111_probe(struct spi_device *spi)
err = sysfs_create_group(&spi->dev.kobj, &max1111_attr_group);
if (err) {
dev_err(&spi->dev, "failed to create attribute group\n");
- goto err_free_all;
+ goto err_free_data;
}
data->hwmon_dev = hwmon_device_register(&spi->dev);
@@ -209,9 +199,6 @@ static int __devinit max1111_probe(struct spi_device *spi)
err_remove:
sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
-err_free_all:
- kfree(data->rx_buf);
- kfree(data->tx_buf);
err_free_data:
kfree(data);
return err;
@@ -224,8 +211,6 @@ static int __devexit max1111_remove(struct spi_device *spi)
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group);
mutex_destroy(&data->drvdata_lock);
- kfree(data->rx_buf);
- kfree(data->tx_buf);
kfree(data);
return 0;
}