diff options
author | Jean Delvare <khali@linux-fr.org> | 2011-07-25 15:46:10 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-07-25 15:46:10 -0400 |
commit | d737c09cfb78424276e3eb45d1e7af578a451fd4 (patch) | |
tree | b8c9430670ce30c9d2100c87def3720bbe24f66f /drivers/hwmon/max1111.c | |
parent | 3d30f9e69f152d8667b3b13ac6f566e6e76ef7b9 (diff) |
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.c | 27 |
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 { | |||
38 | struct device *hwmon_dev; | 38 | struct device *hwmon_dev; |
39 | struct spi_message msg; | 39 | struct spi_message msg; |
40 | struct spi_transfer xfer[2]; | 40 | struct spi_transfer xfer[2]; |
41 | uint8_t *tx_buf; | 41 | uint8_t tx_buf[MAX1111_TX_BUF_SIZE]; |
42 | uint8_t *rx_buf; | 42 | uint8_t rx_buf[MAX1111_RX_BUF_SIZE]; |
43 | struct mutex drvdata_lock; | 43 | struct mutex drvdata_lock; |
44 | /* protect msg, xfer and buffers from multiple access */ | 44 | /* protect msg, xfer and buffers from multiple access */ |
45 | }; | 45 | }; |
@@ -131,33 +131,23 @@ static const struct attribute_group max1111_attr_group = { | |||
131 | .attrs = max1111_attributes, | 131 | .attrs = max1111_attributes, |
132 | }; | 132 | }; |
133 | 133 | ||
134 | static int setup_transfer(struct max1111_data *data) | 134 | static int __devinit setup_transfer(struct max1111_data *data) |
135 | { | 135 | { |
136 | struct spi_message *m; | 136 | struct spi_message *m; |
137 | struct spi_transfer *x; | 137 | struct spi_transfer *x; |
138 | 138 | ||
139 | data->tx_buf = kmalloc(MAX1111_TX_BUF_SIZE, GFP_KERNEL); | ||
140 | if (!data->tx_buf) | ||
141 | return -ENOMEM; | ||
142 | |||
143 | data->rx_buf = kmalloc(MAX1111_RX_BUF_SIZE, GFP_KERNEL); | ||
144 | if (!data->rx_buf) { | ||
145 | kfree(data->tx_buf); | ||
146 | return -ENOMEM; | ||
147 | } | ||
148 | |||
149 | m = &data->msg; | 139 | m = &data->msg; |
150 | x = &data->xfer[0]; | 140 | x = &data->xfer[0]; |
151 | 141 | ||
152 | spi_message_init(m); | 142 | spi_message_init(m); |
153 | 143 | ||
154 | x->tx_buf = &data->tx_buf[0]; | 144 | x->tx_buf = &data->tx_buf[0]; |
155 | x->len = 1; | 145 | x->len = MAX1111_TX_BUF_SIZE; |
156 | spi_message_add_tail(x, m); | 146 | spi_message_add_tail(x, m); |
157 | 147 | ||
158 | x++; | 148 | x++; |
159 | x->rx_buf = &data->rx_buf[0]; | 149 | x->rx_buf = &data->rx_buf[0]; |
160 | x->len = 2; | 150 | x->len = MAX1111_RX_BUF_SIZE; |
161 | spi_message_add_tail(x, m); | 151 | spi_message_add_tail(x, m); |
162 | 152 | ||
163 | return 0; | 153 | return 0; |
@@ -192,7 +182,7 @@ static int __devinit max1111_probe(struct spi_device *spi) | |||
192 | err = sysfs_create_group(&spi->dev.kobj, &max1111_attr_group); | 182 | err = sysfs_create_group(&spi->dev.kobj, &max1111_attr_group); |
193 | if (err) { | 183 | if (err) { |
194 | dev_err(&spi->dev, "failed to create attribute group\n"); | 184 | dev_err(&spi->dev, "failed to create attribute group\n"); |
195 | goto err_free_all; | 185 | goto err_free_data; |
196 | } | 186 | } |
197 | 187 | ||
198 | data->hwmon_dev = hwmon_device_register(&spi->dev); | 188 | data->hwmon_dev = hwmon_device_register(&spi->dev); |
@@ -209,9 +199,6 @@ static int __devinit max1111_probe(struct spi_device *spi) | |||
209 | 199 | ||
210 | err_remove: | 200 | err_remove: |
211 | sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); | 201 | sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); |
212 | err_free_all: | ||
213 | kfree(data->rx_buf); | ||
214 | kfree(data->tx_buf); | ||
215 | err_free_data: | 202 | err_free_data: |
216 | kfree(data); | 203 | kfree(data); |
217 | return err; | 204 | return err; |
@@ -224,8 +211,6 @@ static int __devexit max1111_remove(struct spi_device *spi) | |||
224 | hwmon_device_unregister(data->hwmon_dev); | 211 | hwmon_device_unregister(data->hwmon_dev); |
225 | sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); | 212 | sysfs_remove_group(&spi->dev.kobj, &max1111_attr_group); |
226 | mutex_destroy(&data->drvdata_lock); | 213 | mutex_destroy(&data->drvdata_lock); |
227 | kfree(data->rx_buf); | ||
228 | kfree(data->tx_buf); | ||
229 | kfree(data); | 214 | kfree(data); |
230 | return 0; | 215 | return 0; |
231 | } | 216 | } |