From: Sanjay Chitroda <sanjayembeddedse@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
andy@kernel.org, kees@kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 4/4] iio: ssp_sensors: reuse preallocated RX buffer for SPI transfers
Date: Sat, 28 Mar 2026 10:32:56 +0530 [thread overview]
Message-ID: <31B44DC6-FE3E-441D-94E2-DFADDAE7FA69@gmail.com> (raw)
In-Reply-To: <acT7ndQKmAUajb_b@ashevche-desk.local>
On 26 March 2026 2:55:49 pm IST, Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
>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;
>
>
Thanks Andy for the review.
I have addressed the comments related to this change and updated the allocation as follows:
data->rx_buf_size = SSP_DATA_PACKET_SIZE;
data->rx_buf = devm_kzalloc(&spi->dev, data->rx_buf_size, GFP_KERNEL);
if (!data->rx_buf)
return -ENOMEM;
Regarding the managed vs unmanaged resource comment — since "struct ssp_data" is allocated using "devm_kzalloc()", I aligned "rx_buf" with the same lifetime.
For the IRQ handling and other resource management aspects, I will address those separately to keep this change focused.
Please let me know if you would prefer those fixes to be included as part of this patch.
I will include these updates in the next revision.
next prev parent reply other threads:[~2026-03-28 5:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 8:18 [PATCH v4 0/4] iio: ssp_sensors: improve resource cleanup with cleanup.h Sanjay Chitroda
2026-03-26 8:18 ` [PATCH v4 1/4] iio: ssp_sensors: cleanup codestyle warning Sanjay Chitroda
2026-03-26 8:18 ` [PATCH v4 2/4] iio: ssp_sensors: cleanup codestyle check Sanjay Chitroda
2026-03-26 8:18 ` [PATCH v4 3/4] iio: ssp_sensors: ssp_spi: use guard() to release mutexes Sanjay Chitroda
2026-03-26 9:22 ` Andy Shevchenko
2026-03-28 6:54 ` Sanjay Chitroda
2026-03-29 11:44 ` Andy Shevchenko
2026-03-30 16:17 ` Sanjay Chitroda
2026-04-01 3:19 ` Sanjay Chitroda
2026-03-26 8:18 ` [PATCH v4 4/4] iio: ssp_sensors: reuse preallocated RX buffer for SPI transfers Sanjay Chitroda
2026-03-26 9:25 ` Andy Shevchenko
2026-03-28 5:02 ` Sanjay Chitroda [this message]
2026-03-28 8:08 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31B44DC6-FE3E-441D-94E2-DFADDAE7FA69@gmail.com \
--to=sanjayembeddedse@gmail.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=kees@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome