mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: "Luis R . Rodriguez" <mcgrof@kernel.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Bjorn Andersson" <bjorn.andersson@linaro.org>,
	"Daniel Wagner" <wagi@monom.org>,
	"David Woodhouse" <dwmw2@infradead.org>,
	"Arend van Spriel" <arend.vanspriel@broadcom.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	yi1.li@linux.intel.com, atull@kernel.org,
	"Moritz Fischer" <moritz.fischer@ettus.com>,
	pmladek@suse.com, "Johannes Berg" <johannes.berg@intel.com>,
	emmanuel.grumbach@intel.com, luciano.coelho@intel.com,
	"Kalle Valo" <kvalo@codeaurora.org>,
	luto@kernel.org, "Linus Torvalds" <torvalds@linux-foundation.org>,
	"Kees Cook" <keescook@chromium.org>,
	"AKASHI Takahiro" <takahiro.akashi@linaro.org>,
	"David Howells" <dhowells@redhat.com>,
	pjones@redhat.com, "Hans de Goede" <hdegoede@redhat.com>,
	alan@linux.intel.com, tytso@mit.edu,
	lkml <linux-kernel@vger.kernel.org>,
	"Franky Lin" <franky.lin@broadcom.com>,
	"Hante Meuleman" <hante.meuleman@broadcom.com>,
	"Chi-Hsien Lin" <chi-hsien.lin@cypress.com>,
	"Wright Feng" <wright.feng@cypress.com>,
	"Pieter-Paul Giesberts" <pieter-paul.giesberts@broadcom.com>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: Re: [PATCH V5 1/2] firmware: add more flexible request_firmware_async function
Date: Wed, 2 Aug 2017 23:30:10 +0200	[thread overview]
Message-ID: <20170802213010.GM18884@wotan.suse.de> (raw)
In-Reply-To: <20170731150945.8925-1-zajec5@gmail.com>

On Mon, Jul 31, 2017 at 05:09:44PM +0200, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> So far we got only one function for loading firmware asynchronously:
> request_firmware_nowait. It didn't allow much customization of firmware
> loading process - there is only one bool uevent argument. Moreover this
> bool also controls user helper in an unclear way.

> Some drivers need more flexible helper providing more options. This
> includes control over uevent or warning for the missing firmware. Of
> course this list may grow up in the future.
> 
> To handle this easily this patch adds a generic request_firmware_async
> function. It takes struct with options as an argument which will allow
> extending it in the future without massive changes.
> 
> This is a really cheap change (no new independent API) which works
> nicely with the existing code. The old request_firmware_nowait is kept
> as a simple helper calling new helper.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
> V3: Don't expose all FW_OPT_* flags.
>     As Luis noted we want a struct so add struct firmware_opts for real
>     flexibility.
>     Thank you Luis for your review!
> V5: Rebase, update commit message, resend after drvdata discussion
> ---
>  drivers/base/firmware_class.c | 43 ++++++++++++++++++++++++++++++++++---------
>  include/linux/firmware.h      | 15 ++++++++++++++-
>  2 files changed, 48 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index b9f907eedbf7..cde85b05e4cb 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -1375,7 +1375,7 @@ static void request_firmware_work_func(struct work_struct *work)
>  	_request_firmware(&fw, fw_work->name, fw_work->device, NULL, 0,
>  			  fw_work->opt_flags);
>  	fw_work->cont(fw, fw_work->context);
> -	put_device(fw_work->device); /* taken in request_firmware_nowait() */
> +	put_device(fw_work->device); /* taken in __request_firmware_nowait() */
>  
>  	module_put(fw_work->module);
>  	kfree_const(fw_work->name);
> @@ -1383,10 +1383,9 @@ static void request_firmware_work_func(struct work_struct *work)
>  }
>  
>  /**
> - * request_firmware_nowait - asynchronous version of request_firmware
> + * __request_firmware_nowait - asynchronous version of request_firmware
>   * @module: module requesting the firmware
> - * @uevent: sends uevent to copy the firmware image if this flag
> - *	is non-zero else the firmware copy must be done manually.
> + * @opt_flags: flags that control firmware loading process, see FW_OPT_*
>   * @name: name of firmware file
>   * @device: device for which firmware is being loaded
>   * @gfp: allocation flags
> @@ -1405,9 +1404,9 @@ static void request_firmware_work_func(struct work_struct *work)
>   *
>   *		- can't sleep at all if @gfp is GFP_ATOMIC.
>   **/
> -int
> -request_firmware_nowait(
> -	struct module *module, bool uevent,
> +static int
> +__request_firmware_nowait(
> +	struct module *module, unsigned int opt_flags,
>  	const char *name, struct device *device, gfp_t gfp, void *context,
>  	void (*cont)(const struct firmware *fw, void *context))
>  {
> @@ -1426,8 +1425,7 @@ request_firmware_nowait(
>  	fw_work->device = device;
>  	fw_work->context = context;
>  	fw_work->cont = cont;
> -	fw_work->opt_flags = FW_OPT_NOWAIT | FW_OPT_FALLBACK |
> -		(uevent ? FW_OPT_UEVENT : FW_OPT_USERHELPER);
> +	fw_work->opt_flags = FW_OPT_NOWAIT | opt_flags;
>  
>  	if (!try_module_get(module)) {
>  		kfree_const(fw_work->name);
> @@ -1440,8 +1438,35 @@ request_firmware_nowait(
>  	schedule_work(&fw_work->work);
>  	return 0;
>  }
> +
> +int request_firmware_nowait(struct module *module, bool uevent,
> +			    const char *name, struct device *device, gfp_t gfp,
> +			    void *context,
> +			    void (*cont)(const struct firmware *fw, void *context))
> +{
> +	unsigned int opt_flags = FW_OPT_FALLBACK |
> +		(uevent ? FW_OPT_UEVENT : FW_OPT_USERHELPER);
> +
> +	return __request_firmware_nowait(module, opt_flags, name, device, gfp,
> +					 context, cont);
> +}
>  EXPORT_SYMBOL(request_firmware_nowait);
>  
> +int __request_firmware_async(struct module *module, const char *name,
> +			     struct firmware_opts *fw_opts, struct device *dev,
> +			     void *context,
> +			     void (*cont)(const struct firmware *fw, void *context))
> +{
> +	unsigned int opt_flags = FW_OPT_UEVENT;

This exposes a long issue. Think -- why do we want this enabled by default? Its
actually because even though the fallback stuff is optional and can be, the uevent
internal flag *also* provides caching support as a side consequence only. We
don't want to add a new API without first cleaning up that mess.

This is a slipery slope and best to clean that up before adding any new API.

That and also Greg recently stated he would like to see at least 3 users of
a feature before adding it. Although I think that's pretty arbitrary, and
considering that request_firmware_into_buf() only has *one* user -- its what
he wishes.

  Luis

  parent reply	other threads:[~2017-08-02 21:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-31 15:09 Rafał Miłecki
2017-07-31 15:09 ` [PATCH V5 2/2] brcmfmac: don't warn user about NVRAM if fallback to the platform one succeeds Rafał Miłecki
2017-08-01 21:20   ` Arend van Spriel
2017-07-31 23:01 ` [PATCH V5 1/2] firmware: add more flexible request_firmware_async function kbuild test robot
2017-08-02 21:30 ` Luis R. Rodriguez [this message]
2017-08-03  5:23   ` Kalle Valo
2017-08-03  5:55     ` Coelho, Luciano
2017-08-03 16:31       ` Luis R. Rodriguez
2017-08-10 17:07       ` Luis R. Rodriguez
2017-08-10 17:05     ` Luis R. Rodriguez

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=20170802213010.GM18884@wotan.suse.de \
    --to=mcgrof@kernel.org \
    --cc=alan@linux.intel.com \
    --cc=arend.vanspriel@broadcom.com \
    --cc=atull@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=chi-hsien.lin@cypress.com \
    --cc=dhowells@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=emmanuel.grumbach@intel.com \
    --cc=franky.lin@broadcom.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hante.meuleman@broadcom.com \
    --cc=hdegoede@redhat.com \
    --cc=johannes.berg@intel.com \
    --cc=keescook@chromium.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    --cc=luto@kernel.org \
    --cc=moritz.fischer@ettus.com \
    --cc=netdev@vger.kernel.org \
    --cc=pieter-paul.giesberts@broadcom.com \
    --cc=pjones@redhat.com \
    --cc=pmladek@suse.com \
    --cc=rafal@milecki.pl \
    --cc=rjw@rjwysocki.net \
    --cc=takahiro.akashi@linaro.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=wagi@monom.org \
    --cc=wright.feng@cypress.com \
    --cc=yi1.li@linux.intel.com \
    --cc=zajec5@gmail.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

all inboxes | Powered by JetHome®