Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: light: adjd_s311: move buffer on adjd_s311_data object

This change moves the entire buffer on the private adjd_s311_data type.
Since the device has 4 channels, it's not a big waste to just allocate the
maximum possible buffer and use only what's needed.

This is in contrast with free-ing and re-allocating the buffer on the
update_scan_mode hook.

Since the driver pushes buffer data with
iio_push_to_buffers_with_timestamp(), the buffer must also include a
64-bit buffer for the timestamp, for each sample-set.

With this change, the adjd_s311_update_scan_mode() is no longer needed.

Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210705071456.649659-1-aardelean@deviqon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
2427a7e9 7786da3b

+6 -19
+6 -19
drivers/iio/light/adjd_s311.c
··· 54 54 55 55 struct adjd_s311_data { 56 56 struct i2c_client *client; 57 - u16 *buffer; 57 + struct { 58 + s16 chans[4]; 59 + s64 ts __aligned(8); 60 + } scan; 58 61 }; 59 62 60 63 enum adjd_s311_channel_idx { ··· 132 129 if (ret < 0) 133 130 goto done; 134 131 135 - data->buffer[j++] = ret & ADJD_S311_DATA_MASK; 132 + data->scan.chans[j++] = ret & ADJD_S311_DATA_MASK; 136 133 } 137 134 138 - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, time_ns); 135 + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, time_ns); 139 136 140 137 done: 141 138 iio_trigger_notify_done(indio_dev->trig); ··· 228 225 return -EINVAL; 229 226 } 230 227 231 - static int adjd_s311_update_scan_mode(struct iio_dev *indio_dev, 232 - const unsigned long *scan_mask) 233 - { 234 - struct adjd_s311_data *data = iio_priv(indio_dev); 235 - 236 - kfree(data->buffer); 237 - data->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 238 - if (data->buffer == NULL) 239 - return -ENOMEM; 240 - 241 - return 0; 242 - } 243 - 244 228 static const struct iio_info adjd_s311_info = { 245 229 .read_raw = adjd_s311_read_raw, 246 230 .write_raw = adjd_s311_write_raw, 247 - .update_scan_mode = adjd_s311_update_scan_mode, 248 231 }; 249 232 250 233 static int adjd_s311_probe(struct i2c_client *client, ··· 275 286 static int adjd_s311_remove(struct i2c_client *client) 276 287 { 277 288 struct iio_dev *indio_dev = i2c_get_clientdata(client); 278 - struct adjd_s311_data *data = iio_priv(indio_dev); 279 289 280 290 iio_device_unregister(indio_dev); 281 291 iio_triggered_buffer_cleanup(indio_dev); 282 - kfree(data->buffer); 283 292 284 293 return 0; 285 294 }