Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: Praveen Talari <praveen.talari@oss.qualcomm.com>,
	Mark Brown <broonie@kernel.org>,
	linux-arm-msm@vger.kernel.org, linux-spi@vger.kernel.org,
	linux-kernel@vger.kernel.org, bjorn.andersson@oss.qualcomm.com,
	dmitry.baryshkov@oss.qualcomm.com
Cc: prasad.sodagudi@oss.qualcomm.com,
	mukesh.savaliya@oss.qualcomm.com, quic_vtanuku@quicinc.com,
	aniket.randive@oss.qualcomm.com,
	chandana.chiluveru@oss.qualcomm.com,
	jyothi.seerapu@oss.qualcomm.com
Subject: Re: [PATCH v1 1/3] spi: geni-qcom: Improve target mode allocation by using proper allocation functions
Date: Thu, 29 Jan 2026 12:42:25 +0100	[thread overview]
Message-ID: <d9fc3b0c-7fe7-4845-b55d-ce6d0053f48d@oss.qualcomm.com> (raw)
In-Reply-To: <bece7d32-5f62-4ed8-8dd1-0de9102648cb@oss.qualcomm.com>

On 1/28/26 5:32 PM, Praveen Talari wrote:
> Hi Konrad
> 
> On 1/27/2026 6:45 PM, Konrad Dybcio wrote:
>> On 1/22/26 4:10 PM, Praveen Talari wrote:
>>> The current implementation always allocates a host controller and sets the
>>> target flag later when the "spi-slave" device tree property is present.
>>> This approach is suboptimal as it doesn't utilize the dedicated allocation
>>> functions designed for target mode.
>>>
>>> Use devm_spi_alloc_target() when "spi-slave" device tree property is
>>> present, otherwise use devm_spi_alloc_host(). This replaces the previous
>>> approach of always allocating a host controller and setting target flag
>>> later.
>>>
>>> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
>>> ---
>>>   drivers/spi/spi-geni-qcom.c | 15 ++++++++-------
>>>   1 file changed, 8 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
>>> index 0e5fd9df1a8f..f5d05025b196 100644
>>> --- a/drivers/spi/spi-geni-qcom.c
>>> +++ b/drivers/spi/spi-geni-qcom.c
>>> @@ -1017,6 +1017,14 @@ static int spi_geni_probe(struct platform_device *pdev)
>>>       struct clk *clk;
>>>       struct device *dev = &pdev->dev;
>>>   +    if (device_property_read_bool(dev, "spi-slave"))
>>> +        spi = devm_spi_alloc_target(dev, sizeof(*mas));
>>> +    else
>>> +        spi = devm_spi_alloc_host(dev, sizeof(*mas));
>>> +
>>> +    if (!spi)
>>> +        return -ENOMEM;
>>> +
>>>       irq = platform_get_irq(pdev, 0);
>>>       if (irq < 0)
>>>           return irq;
>>> @@ -1033,10 +1041,6 @@ static int spi_geni_probe(struct platform_device *pdev)
>>>       if (IS_ERR(clk))
>>>           return PTR_ERR(clk);
>>>   -    spi = devm_spi_alloc_host(dev, sizeof(*mas));
>>> -    if (!spi)
>>> -        return -ENOMEM;
>>
>> Is there a reason you're moving this code to the top of the function?
> 
> When CONFIG_SPI_SLAVE is disabled, the call returns NULL; therefore, I placed this check at the start of the probe() function.
> 
> ref:
> static inline struct spi_controller *devm_spi_alloc_target(struct device *dev, unsigned int size)
> {
>     if (!IS_ENABLED(CONFIG_SPI_SLAVE))
>         return NULL;
> 
>     return __devm_spi_alloc_controller(dev, size, true);
> }

That doesn't really matter since spi is not accessed beforehand
and it'd return a NULL if it failed to allocate either way

I'm not sure this is a concern nowadays with fw_devlink and
friends, but today the allocation happens after we get a clock
reference, which could throw an eprobe_defer, which I think would
cause the memory to be de-allocated again, wasting cycles

Konrad

  reply	other threads:[~2026-01-29 11:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-22 15:10 [PATCH v1 0/3] Improve SPI target mode support and error handling Praveen Talari
2026-01-22 15:10 ` [PATCH v1 1/3] spi: geni-qcom: Improve target mode allocation by using proper allocation functions Praveen Talari
2026-01-27 13:15   ` Konrad Dybcio
2026-01-28 16:32     ` Praveen Talari
2026-01-29 11:42       ` Konrad Dybcio [this message]
2026-01-29 15:45         ` Praveen Talari
2026-01-30 11:22           ` Konrad Dybcio
2026-01-22 15:10 ` [PATCH v1 2/3] spi: geni-qcom: Fix abort sequence execution for serial engine errors Praveen Talari
2026-01-27 13:17   ` Konrad Dybcio
2026-01-28 16:22     ` Praveen Talari
2026-01-29 11:48       ` Konrad Dybcio
2026-01-29 15:49         ` Praveen Talari
2026-01-29 15:10   ` [PATCH " Markus Elfring
2026-01-22 15:10 ` [PATCH v1 3/3] spi: geni-qcom: Add target abort support Praveen Talari
2026-01-27 13:21   ` Konrad Dybcio
2026-01-28 16:28     ` Praveen Talari
2026-01-29 11:42       ` Konrad Dybcio
2026-01-29 15:50         ` Praveen Talari

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=d9fc3b0c-7fe7-4845-b55d-ce6d0053f48d@oss.qualcomm.com \
    --to=konrad.dybcio@oss.qualcomm.com \
    --cc=aniket.randive@oss.qualcomm.com \
    --cc=bjorn.andersson@oss.qualcomm.com \
    --cc=broonie@kernel.org \
    --cc=chandana.chiluveru@oss.qualcomm.com \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=jyothi.seerapu@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mukesh.savaliya@oss.qualcomm.com \
    --cc=prasad.sodagudi@oss.qualcomm.com \
    --cc=praveen.talari@oss.qualcomm.com \
    --cc=quic_vtanuku@quicinc.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