* [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory allocations
@ 2011-07-12 9:01 Jean Delvare
2011-07-12 16:40 ` [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory Guenter Roeck
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jean Delvare @ 2011-07-12 9:01 UTC (permalink / raw)
To: lm-sensors
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>
---
Can anyone with a MAX1111 device try and report please?
drivers/hwmon/max1111.c | 27 ++++++---------------------
1 file changed, 6 insertions(+), 21 deletions(-)
--- linux-3.0-rc6.orig/drivers/hwmon/max1111.c 2011-07-12 08:50:02.000000000 +0200
+++ linux-3.0-rc6/drivers/hwmon/max1111.c 2011-07-12 09:36:51.000000000 +0200
@@ -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 max1
.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(struc
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(struc
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(stru
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;
}
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory
2011-07-12 9:01 [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory allocations Jean Delvare
@ 2011-07-12 16:40 ` Guenter Roeck
2011-07-12 16:45 ` Jean Delvare
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2011-07-12 16:40 UTC (permalink / raw)
To: lm-sensors
On Tue, Jul 12, 2011 at 05:01:52AM -0400, Jean Delvare wrote:
> 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>
> ---
> Can anyone with a MAX1111 device try and report please?
>
Reason for using allocated buffers may have been to ensure (word/cache line) alignment.
Not really sure if that is a valid argument with 1/2 byte buffers, though.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory
2011-07-12 9:01 [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory allocations Jean Delvare
2011-07-12 16:40 ` [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory Guenter Roeck
@ 2011-07-12 16:45 ` Jean Delvare
2011-07-12 17:20 ` Guenter Roeck
2011-07-12 20:43 ` Stanislav Brabec
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2011-07-12 16:45 UTC (permalink / raw)
To: lm-sensors
On Tue, 12 Jul 2011 09:40:33 -0700, Guenter Roeck wrote:
> On Tue, Jul 12, 2011 at 05:01:52AM -0400, Jean Delvare wrote:
> > 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>
> > ---
> > Can anyone with a MAX1111 device try and report please?
> >
> Reason for using allocated buffers may have been to ensure (word/cache line) alignment.
> Not really sure if that is a valid argument with 1/2 byte buffers, though.
And such an alignment would belong to the bus driver rather than the
SPI device driver. At least this is the way we do it for I2C...
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory
2011-07-12 9:01 [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory allocations Jean Delvare
2011-07-12 16:40 ` [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory Guenter Roeck
2011-07-12 16:45 ` Jean Delvare
@ 2011-07-12 17:20 ` Guenter Roeck
2011-07-12 20:43 ` Stanislav Brabec
3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2011-07-12 17:20 UTC (permalink / raw)
To: lm-sensors
On Tue, Jul 12, 2011 at 12:45:22PM -0400, Jean Delvare wrote:
> On Tue, 12 Jul 2011 09:40:33 -0700, Guenter Roeck wrote:
> > On Tue, Jul 12, 2011 at 05:01:52AM -0400, Jean Delvare wrote:
> > > 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>
> > > ---
> > > Can anyone with a MAX1111 device try and report please?
> > >
> > Reason for using allocated buffers may have been to ensure (word/cache line) alignment.
> > Not really sure if that is a valid argument with 1/2 byte buffers, though.
>
> And such an alignment would belong to the bus driver rather than the
> SPI device driver. At least this is the way we do it for I2C...
>
Possibly, and makes sense (how does the device driver know ?), but for USB
they had me do it in the I2C master driver ... I ensured alignment by placing
the buffers at the beginning of the allocated memory.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory
2011-07-12 9:01 [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory allocations Jean Delvare
` (2 preceding siblings ...)
2011-07-12 17:20 ` Guenter Roeck
@ 2011-07-12 20:43 ` Stanislav Brabec
3 siblings, 0 replies; 5+ messages in thread
From: Stanislav Brabec @ 2011-07-12 20:43 UTC (permalink / raw)
To: lm-sensors
Jean Delvare wrote:
> Can anyone with a MAX1111 device try and report please?
MAX1111 on spitz seems to work properly.
Tested-by: Stanislav Brabec <utx@penguin.cz>
--
Stanislav Brabec
http://www.penguin.cz/~utx
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-12 20:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-12 9:01 [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory allocations Jean Delvare
2011-07-12 16:40 ` [lm-sensors] [PATCH] hwmon: (max1111) Avoid extra memory Guenter Roeck
2011-07-12 16:45 ` Jean Delvare
2011-07-12 17:20 ` Guenter Roeck
2011-07-12 20:43 ` Stanislav Brabec
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.