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

Configure Feed

Select the types of activity you want to include in your feed.

iio: proximity: sx9500: use stack allocated struct for scan data

Use a stack-allocated struct in sx9500_trigger_handler() to hold the
IIO buffer scan data. Since the scan buffer isn't used outside of this
function, it doesn't need to be in struct sx9500_data.

By always allocating enough space for the maximum number of channels,
we can avoid having to reallocate the buffer each time buffered reads
are enabled.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250722-iio-use-more-iio_declare_buffer_with_ts-4-v2-1-9e566f3a4c6a@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
5335f93d b76c739c

+6 -21
+6 -21
drivers/iio/proximity/sx9500.c
··· 88 88 bool prox_stat[SX9500_NUM_CHANNELS]; 89 89 bool event_enabled[SX9500_NUM_CHANNELS]; 90 90 bool trigger_enabled; 91 - u16 *buffer; 92 91 /* Remember enabled channels and sample rate during suspend. */ 93 92 unsigned int suspend_ctrl0; 94 93 struct completion completion; ··· 577 578 return ret; 578 579 } 579 580 580 - static int sx9500_update_scan_mode(struct iio_dev *indio_dev, 581 - const unsigned long *scan_mask) 582 - { 583 - struct sx9500_data *data = iio_priv(indio_dev); 584 - 585 - mutex_lock(&data->mutex); 586 - kfree(data->buffer); 587 - data->buffer = kzalloc(indio_dev->scan_bytes, GFP_KERNEL); 588 - mutex_unlock(&data->mutex); 589 - 590 - if (data->buffer == NULL) 591 - return -ENOMEM; 592 - 593 - return 0; 594 - } 595 - 596 581 static IIO_CONST_ATTR_SAMP_FREQ_AVAIL( 597 582 "2.500000 3.333333 5 6.666666 8.333333 11.111111 16.666666 33.333333"); 598 583 ··· 595 612 .write_raw = &sx9500_write_raw, 596 613 .read_event_config = &sx9500_read_event_config, 597 614 .write_event_config = &sx9500_write_event_config, 598 - .update_scan_mode = &sx9500_update_scan_mode, 599 615 }; 600 616 601 617 static int sx9500_set_trigger_state(struct iio_trigger *trig, ··· 631 649 struct iio_dev *indio_dev = pf->indio_dev; 632 650 struct sx9500_data *data = iio_priv(indio_dev); 633 651 int val, bit, ret, i = 0; 652 + struct { 653 + u16 chan[SX9500_NUM_CHANNELS]; 654 + aligned_s64 timestamp; 655 + } scan = { }; 634 656 635 657 mutex_lock(&data->mutex); 636 658 ··· 644 658 if (ret < 0) 645 659 goto out; 646 660 647 - data->buffer[i++] = val; 661 + scan.chan[i++] = val; 648 662 } 649 663 650 - iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 664 + iio_push_to_buffers_with_timestamp(indio_dev, &scan, 651 665 iio_get_time_ns(indio_dev)); 652 666 653 667 out: ··· 970 984 iio_triggered_buffer_cleanup(indio_dev); 971 985 if (client->irq > 0) 972 986 iio_trigger_unregister(data->trig); 973 - kfree(data->buffer); 974 987 } 975 988 976 989 static int sx9500_suspend(struct device *dev)