Re: [PATCH v4 4/4] iio: ssp_sensors: reuse preallocated RX buffer for SPI transfers
From: Andy Shevchenko
Date: Thu Mar 26 2026 - 05:31:57 EST
On Thu, Mar 26, 2026 at 01:48:15PM +0530, Sanjay Chitroda wrote:
> Avoid allocating a temporary DMA buffer in the interrupt context when
> handling hub-to-AP and AP-to-hub SPI write messages.
>
> Preallocate RX buffer during probe and reuse it for SPI receive
> operations. This removes repeated kzalloc() calls from the IRQ
> path, reduces allocation overhead, and avoids potential allocation
> failures under memory pressure.
>
> The RX buffer size is tracked and allocated using devm_kzalloc(), ensuring
> proper lifetime management tied to the device.
>
> No functional change intended; this is an internal optimization and
> robustness improvement.
NAK.
...
> @@ -512,6 +512,17 @@ static int ssp_probe(struct spi_device *spi)
>
> mutex_init(&data->comm_lock);
Pzzz! The wrong use of managed vs. unmanaged resources.
> + data->rx_buf_size = SSP_DATA_PACKET_SIZE;
> + data->rx_buf = devm_kzalloc(&spi->dev,
> + data->rx_buf_size,
> + GFP_KERNEL | GFP_DMA);
There are plenty of room on the previous lines. I think I already commented on
something like this.
> +
This blank line is redundant.
> + if (!data->rx_buf) {
> + dev_err(&spi->dev,
> + "Failed to allocate memory for rx_buf\n");
Pzzz!
Have you read about error messages for -ENOMEM? Please, take your time and
study this case.
> + return -ENOMEM;
> + }
> +
> for (i = 0; i < SSP_SENSOR_MAX; ++i) {
> data->delay_buf[i] = SSP_DEFAULT_POLLING_DELAY;
> data->batch_latency_buf[i] = 0;
--
With Best Regards,
Andy Shevchenko