public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Cássio Gabriel Monteiro Pires" <cassiogabrielcontato@gmail.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
	Russ Weight <russ.weight@linux.dev>,
	Danilo Krummrich <dakr@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Takashi Iwai <tiwai@suse.com>,
	Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
	Baojun Xu <baojun.xu@ti.com>, Jaroslav Kysela <perex@perex.cz>,
	driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-sound@vger.kernel.org
Subject: Re: [PATCH v3 1/2] firmware_loader: Add cancel helper for async requests
Date: Mon, 4 May 2026 19:40:17 -0300	[thread overview]
Message-ID: <0b52cd6d-8845-4591-9b5b-0e3b97221c80@gmail.com> (raw)
In-Reply-To: <871pfrxkmj.wl-tiwai@suse.de>


[-- Attachment #1.1: Type: text/plain, Size: 2329 bytes --]

On 5/4/26 12:25, Takashi Iwai wrote:
> On Fri, 01 May 2026 12:22:12 +0200,
> Cássio Gabriel wrote:
>> +static void firmware_work_free(struct firmware_work *fw_work)
>> +{
>> +	put_device(fw_work->device); /* taken in request_firmware_nowait() */
>> +	module_put(fw_work->module);
>> +	kfree_const(fw_work->name);
>> +}
>> +
>>  static void request_firmware_work_func(struct work_struct *work)
>>  {
>>  	struct firmware_work *fw_work;
>>  	const struct firmware *fw;
>> +	unsigned long flags;
>>  
>>  	fw_work = container_of(work, struct firmware_work, work);
>>  
>>  	_request_firmware(&fw, fw_work->name, fw_work->device, NULL, 0, 0,
>>  			  fw_work->opt_flags);
>>  	fw_work->cont(fw, fw_work->context);
>> -	put_device(fw_work->device); /* taken in request_firmware_nowait() */
>>  
>> -	module_put(fw_work->module);
>> -	kfree_const(fw_work->name);
>> -	kfree(fw_work);
>> +	spin_lock_irqsave(&firmware_work_lock, flags);
> 
> This is a sleepable context, so you can use spin_lock_irq().

Thanks, I'll fold those in v4.

> 
>> +	if (!list_empty(&fw_work->list)) {
>> +		list_del_init(&fw_work->list);
>> +		spin_unlock_irqrestore(&firmware_work_lock, flags);
>> +		firmware_work_free(fw_work);
>> +		kfree(fw_work);
> 
> Can kfree(fw_work) be in firmware_work_free(), too?  All callers free
> it in anyway.

The worker and cancel paths are both sleepable contexts, so we can switch those
two sites from spin_lock_irqsave() to spin_lock_irq().

I think we need to keep irqsave in _request_firmware_nowait(), since that path
still supports GFP_ATOMIC callers and should not assume IRQs are enabled.

> 
> (snip)
>> +void request_firmware_nowait_cancel(struct device *device, void *context,
>> +				    void (*cont)(const struct firmware *fw,
>> +						 void *context))
>> +{
>> +	struct firmware_work *fw_work = NULL;
>> +	struct firmware_work *tmp;
>> +	unsigned long flags;
>> +
>> +	spin_lock_irqsave(&firmware_work_lock, flags);
> 
> Here you can use spin_lock_irq() as well.

Thanks, I'll change it in v4.

We can also move kfree(fw_work) into firmware_work_free(), since the successful
completion and cancel paths both free the object after releasing the device,
module and firmware-name references.
 
> thanks,
> 
> Takashi

Thanks,
Cássio

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

  reply	other threads:[~2026-05-04 22:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-01 10:22 [PATCH v3 0/2] firmware_loader/ALSA: Fix TAS2781 async firmware teardown Cássio Gabriel
2026-05-01 10:22 ` [PATCH v3 1/2] firmware_loader: Add cancel helper for async requests Cássio Gabriel
2026-05-04 15:25   ` Takashi Iwai
2026-05-04 22:40     ` Cássio Gabriel Monteiro Pires [this message]
2026-05-01 10:22 ` [PATCH v3 2/2] ALSA: hda/tas2781: Cancel async firmware request at unbind Cássio Gabriel

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=0b52cd6d-8845-4591-9b5b-0e3b97221c80@gmail.com \
    --to=cassiogabrielcontato@gmail.com \
    --cc=baojun.xu@ti.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=kevin-lu@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=perex@perex.cz \
    --cc=rafael@kernel.org \
    --cc=russ.weight@linux.dev \
    --cc=shenghao-ding@ti.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    /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