This patch is removing the buffer allocation at each buffer enable.
We just allocate enough memory in the main structure during probe
to cover maximum size needed (that anyway is pretty small) [16bytes].
Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
{
- struct st_sensor_data *adata = iio_priv(indio_dev);
int err;
- adata->buffer_data = kmalloc(indio_dev->scan_bytes,
- GFP_DMA | GFP_KERNEL);
- if (!adata->buffer_data)
- return -ENOMEM;
-
err = iio_triggered_buffer_postenable(indio_dev);
if (err < 0)
- goto st_accel_free_buffer;
+ return err;
err = st_sensors_set_axis_enable(indio_dev,
(u8)indio_dev->active_scan_mask[0]);
st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
st_accel_buffer_predisable:
iio_triggered_buffer_predisable(indio_dev);
-st_accel_free_buffer:
- kfree(adata->buffer_data);
return err;
}
static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
{
- struct st_sensor_data *adata = iio_priv(indio_dev);
int err, err2;
err = st_sensors_set_enable(indio_dev, false);
if (!err)
err = err2;
- kfree(adata->buffer_data);
return err;
}
static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
{
- struct st_sensor_data *gdata = iio_priv(indio_dev);
int err;
- gdata->buffer_data = kmalloc(indio_dev->scan_bytes,
- GFP_DMA | GFP_KERNEL);
- if (!gdata->buffer_data)
- return -ENOMEM;
-
err = iio_triggered_buffer_postenable(indio_dev);
if (err < 0)
- goto st_gyro_free_buffer;
+ return err;
err = st_sensors_set_axis_enable(indio_dev,
(u8)indio_dev->active_scan_mask[0]);
st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
st_gyro_buffer_predisable:
iio_triggered_buffer_predisable(indio_dev);
-st_gyro_free_buffer:
- kfree(gdata->buffer_data);
return err;
}
static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
{
int err, err2;
- struct st_sensor_data *gdata = iio_priv(indio_dev);
err = st_sensors_set_enable(indio_dev, false);
if (err < 0)
if (!err)
err = err2;
- kfree(gdata->buffer_data);
return err;
}
static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
{
- struct st_sensor_data *mdata = iio_priv(indio_dev);
int err;
- mdata->buffer_data = kmalloc(indio_dev->scan_bytes,
- GFP_DMA | GFP_KERNEL);
- if (!mdata->buffer_data)
- return -ENOMEM;
-
err = iio_triggered_buffer_postenable(indio_dev);
if (err < 0)
- goto st_magn_free_buffer;
+ return err;
err = st_sensors_set_enable(indio_dev, true);
if (err < 0)
st_magn_buffer_predisable:
iio_triggered_buffer_predisable(indio_dev);
-st_magn_free_buffer:
- kfree(mdata->buffer_data);
return err;
}
static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
{
- struct st_sensor_data *mdata = iio_priv(indio_dev);
int err, err2;
err = st_sensors_set_enable(indio_dev, false);
if (!err)
err = err2;
- kfree(mdata->buffer_data);
return err;
}
static int st_press_buffer_postenable(struct iio_dev *indio_dev)
{
- struct st_sensor_data *press_data = iio_priv(indio_dev);
int err;
- press_data->buffer_data = kmalloc(indio_dev->scan_bytes,
- GFP_DMA | GFP_KERNEL);
- if (!press_data->buffer_data)
- return -ENOMEM;
-
err = iio_triggered_buffer_postenable(indio_dev);
if (err < 0)
- goto st_press_free_buffer;
+ return err;
err = st_sensors_set_enable(indio_dev, true);
if (err < 0)
st_press_buffer_predisable:
iio_triggered_buffer_predisable(indio_dev);
-st_press_free_buffer:
- kfree(press_data->buffer_data);
return err;
}
static int st_press_buffer_predisable(struct iio_dev *indio_dev)
{
- struct st_sensor_data *press_data = iio_priv(indio_dev);
int err, err2;
err = st_sensors_set_enable(indio_dev, false);
if (!err)
err = err2;
- kfree(press_data->buffer_data);
return err;
}
#include <linux/platform_data/st_sensors_pdata.h>
-#define ST_SENSORS_TX_MAX_LENGTH 2
-#define ST_SENSORS_RX_MAX_LENGTH 6
+/*
+ * Buffer size max case: 2bytes per channel, 3 channels in total +
+ * 8bytes timestamp channel (s64)
+ */
+#define ST_SENSORS_MAX_BUFFER_SIZE (ALIGN(2 * 3, sizeof(s64)) + \
+ sizeof(s64))
#define ST_SENSORS_ODR_LIST_MAX 10
#define ST_SENSORS_FULLSCALE_AVL_MAX 10
* @vdd_io: Pointer to sensor's Vdd-IO power supply
* @regmap: Pointer to specific sensor regmap configuration.
* @enabled: Status of the sensor (false->off, true->on).
- * @buffer_data: Data used by buffer part.
* @odr: Output data rate of the sensor [Hz].
* num_data_channels: Number of data channels used in buffer.
* @drdy_int_pin: Redirect DRDY on pin 1 (1) or pin 2 (2).
* @edge_irq: the IRQ triggers on edges and need special handling.
* @hw_irq_trigger: if we're using the hardware interrupt on the sensor.
* @hw_timestamp: Latest timestamp from the interrupt handler, when in use.
+ * @buffer_data: Data used by buffer part.
*/
struct st_sensor_data {
struct device *dev;
bool enabled;
- char *buffer_data;
-
unsigned int odr;
unsigned int num_data_channels;
bool edge_irq;
bool hw_irq_trigger;
s64 hw_timestamp;
+
+ char buffer_data[ST_SENSORS_MAX_BUFFER_SIZE] ____cacheline_aligned;
};
#ifdef CONFIG_IIO_BUFFER