From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Stephen Boyd <sboyd@codeaurora.org>
Cc: linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Saravana Kannan <skannan@codeaurora.org>,
Kay Sievers <kay.sievers@vrfy.org>,
Greg KH <gregkh@linuxfoundation.org>,
Christian Lamparter <chunkeey@googlemail.com>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
alan@lxorguk.ukuu.org.uk,
Linux PM mailing list <linux-pm@vger.kernel.org>
Subject: Re: [PATCH 1/2] firmware_class: Reorganize fw_create_instance()
Date: Tue, 27 Mar 2012 23:47:06 +0200 [thread overview]
Message-ID: <201203272347.06621.rjw@sisk.pl> (raw)
In-Reply-To: <1332883710-7486-1-git-send-email-sboyd@codeaurora.org>
On Tuesday, March 27, 2012, Stephen Boyd wrote:
> Recent patches to split up the three phases of request_firmware()
> lead to a casting away of const in fw_create_instance(). We can
> avoid this cast by splitting up fw_create_instance() a bit.
>
> Make _request_firmware_setup() return a struct fw_priv and use
> that struct instead of passing struct firmware to
> _request_firmware(). Move the uevent and device file creation
> bits to the loading phase and rename the function to
> _request_firmware_load() to better reflect its purpose.
>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Looks good to me.
Greg, if that's fine with you, I'll add this patch (and the next one)
to my firmware_class series you've looked at recently.
Thanks,
Rafael
> ---
> drivers/base/firmware_class.c | 135 +++++++++++++++++++----------------------
> 1 file changed, 62 insertions(+), 73 deletions(-)
>
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index 72c644b..ae00a2f 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -440,21 +440,19 @@ static void firmware_class_timeout(u_long data)
> }
>
> static struct firmware_priv *
> -fw_create_instance(const struct firmware *firmware, const char *fw_name,
> +fw_create_instance(struct firmware *firmware, const char *fw_name,
> struct device *device, bool uevent, bool nowait)
> {
> struct firmware_priv *fw_priv;
> struct device *f_dev;
> - int error;
>
> fw_priv = kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL);
> if (!fw_priv) {
> dev_err(device, "%s: kmalloc failed\n", __func__);
> - error = -ENOMEM;
> - goto err_out;
> + return ERR_PTR(-ENOMEM);
> }
>
> - fw_priv->fw = (struct firmware *)firmware;
> + fw_priv->fw = firmware;
> fw_priv->nowait = nowait;
> strcpy(fw_priv->fw_id, fw_name);
> init_completion(&fw_priv->completion);
> @@ -468,74 +466,37 @@ fw_create_instance(const struct firmware *firmware, const char *fw_name,
> f_dev->parent = device;
> f_dev->class = &firmware_class;
>
> - dev_set_uevent_suppress(f_dev, true);
> -
> - /* Need to pin this module until class device is destroyed */
> - __module_get(THIS_MODULE);
> -
> - error = device_add(f_dev);
> - if (error) {
> - dev_err(device, "%s: device_register failed\n", __func__);
> - goto err_put_dev;
> - }
> -
> - error = device_create_bin_file(f_dev, &firmware_attr_data);
> - if (error) {
> - dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
> - goto err_del_dev;
> - }
> -
> - error = device_create_file(f_dev, &dev_attr_loading);
> - if (error) {
> - dev_err(device, "%s: device_create_file failed\n", __func__);
> - goto err_del_bin_attr;
> - }
> -
> - if (uevent)
> - dev_set_uevent_suppress(f_dev, false);
> -
> return fw_priv;
> -
> -err_del_bin_attr:
> - device_remove_bin_file(f_dev, &firmware_attr_data);
> -err_del_dev:
> - device_del(f_dev);
> -err_put_dev:
> - put_device(f_dev);
> -err_out:
> - return ERR_PTR(error);
> -}
> -
> -static void fw_destroy_instance(struct firmware_priv *fw_priv)
> -{
> - struct device *f_dev = &fw_priv->dev;
> -
> - device_remove_file(f_dev, &dev_attr_loading);
> - device_remove_bin_file(f_dev, &firmware_attr_data);
> - device_unregister(f_dev);
> }
>
> -static int _request_firmware_prepare(const struct firmware **firmware_p,
> - const char *name, struct device *device)
> +static struct firmware_priv *
> +_request_firmware_prepare(const struct firmware **firmware_p, const char *name,
> + struct device *device, bool uevent, bool nowait)
> {
> struct firmware *firmware;
> + struct firmware_priv *fw_priv;
>
> if (!firmware_p)
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
>
> *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
> if (!firmware) {
> dev_err(device, "%s: kmalloc(struct firmware) failed\n",
> __func__);
> - return -ENOMEM;
> + return ERR_PTR(-ENOMEM);
> }
>
> if (fw_get_builtin_firmware(firmware, name)) {
> dev_dbg(device, "firmware: using built-in firmware %s\n", name);
> - return 0;
> + return NULL;
> }
>
> - return 1;
> + fw_priv = fw_create_instance(firmware, name, device, uevent, nowait);
> + if (IS_ERR(fw_priv)) {
> + release_firmware(firmware);
> + *firmware_p = NULL;
> + }
> + return fw_priv;
> }
>
> static void _request_firmware_cleanup(const struct firmware **firmware_p)
> @@ -544,21 +505,38 @@ static void _request_firmware_cleanup(const struct firmware **firmware_p)
> *firmware_p = NULL;
> }
>
> -static int _request_firmware(const struct firmware *firmware,
> - const char *name, struct device *device,
> - bool uevent, bool nowait, long timeout)
> +static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent,
> + long timeout)
> {
> - struct firmware_priv *fw_priv;
> int retval = 0;
> + struct device *f_dev = &fw_priv->dev;
> +
> + dev_set_uevent_suppress(f_dev, true);
>
> - if (uevent)
> - dev_dbg(device, "firmware: requesting %s\n", name);
> + /* Need to pin this module until class device is destroyed */
> + __module_get(THIS_MODULE);
>
> - fw_priv = fw_create_instance(firmware, name, device, uevent, nowait);
> - if (IS_ERR(fw_priv))
> - return PTR_ERR(fw_priv);
> + retval = device_add(f_dev);
> + if (retval) {
> + dev_err(f_dev, "%s: device_register failed\n", __func__);
> + goto err_put_dev;
> + }
> +
> + retval = device_create_bin_file(f_dev, &firmware_attr_data);
> + if (retval) {
> + dev_err(f_dev, "%s: sysfs_create_bin_file failed\n", __func__);
> + goto err_del_dev;
> + }
> +
> + retval = device_create_file(f_dev, &dev_attr_loading);
> + if (retval) {
> + dev_err(f_dev, "%s: device_create_file failed\n", __func__);
> + goto err_del_bin_attr;
> + }
>
> if (uevent) {
> + dev_set_uevent_suppress(f_dev, false);
> + dev_dbg(f_dev, "firmware: requesting %s\n", fw_priv->fw_id);
> if (timeout != MAX_SCHEDULE_TIMEOUT)
> mod_timer(&fw_priv->timeout,
> round_jiffies_up(jiffies + timeout));
> @@ -577,7 +555,13 @@ static int _request_firmware(const struct firmware *firmware,
> fw_priv->fw = NULL;
> mutex_unlock(&fw_lock);
>
> - fw_destroy_instance(fw_priv);
> + device_remove_file(f_dev, &dev_attr_loading);
> +err_del_bin_attr:
> + device_remove_bin_file(f_dev, &firmware_attr_data);
> +err_del_dev:
> + device_del(f_dev);
> +err_put_dev:
> + put_device(f_dev);
> return retval;
> }
>
> @@ -600,17 +584,19 @@ int
> request_firmware(const struct firmware **firmware_p, const char *name,
> struct device *device)
> {
> + struct firmware_priv *fw_priv;
> int ret;
>
> - ret = _request_firmware_prepare(firmware_p, name, device);
> - if (ret <= 0)
> - return ret;
> + fw_priv = _request_firmware_prepare(firmware_p, name, device, true,
> + false);
> + if (IS_ERR_OR_NULL(fw_priv))
> + return PTR_RET(fw_priv);
>
> ret = usermodehelper_read_trylock();
> if (WARN_ON(ret)) {
> dev_err(device, "firmware: %s will not be loaded\n", name);
> } else {
> - ret = _request_firmware(*firmware_p, name, device, true, false,
> + ret = _request_firmware_load(fw_priv, true,
> firmware_loading_timeout());
> usermodehelper_read_unlock();
> }
> @@ -648,6 +634,7 @@ static int request_firmware_work_func(void *arg)
> {
> struct firmware_work *fw_work = arg;
> const struct firmware *fw;
> + struct firmware_priv *fw_priv;
> long timeout;
> int ret;
>
> @@ -656,14 +643,16 @@ static int request_firmware_work_func(void *arg)
> return 0;
> }
>
> - ret = _request_firmware_prepare(&fw, fw_work->name, fw_work->device);
> - if (ret <= 0)
> + fw_priv = _request_firmware_prepare(&fw, fw_work->name, fw_work->device,
> + fw_work->uevent, true);
> + if (IS_ERR_OR_NULL(fw_priv)) {
> + ret = PTR_RET(fw_priv);
> goto out;
> + }
>
> timeout = usermodehelper_read_lock_wait(firmware_loading_timeout());
> if (timeout) {
> - ret = _request_firmware(fw, fw_work->name, fw_work->device,
> - fw_work->uevent, true, timeout);
> + ret = _request_firmware_load(fw_priv, fw_work->uevent, timeout);
> usermodehelper_read_unlock();
> } else {
> dev_dbg(fw_work->device, "firmware: %s loading timed out\n",
>
next prev parent reply other threads:[~2012-03-27 21:42 UTC|newest]
Thread overview: 111+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-03 20:22 [RFC] firmware loader: retry _nowait requests when userhelper is not yet available Christian Lamparter
2012-03-03 23:57 ` Alan Cox
2012-03-04 1:50 ` Christian Lamparter
2012-03-05 20:12 ` Srivatsa S. Bhat
2012-03-09 22:30 ` [PATCH] firmware loader: don't cancel _nowait requests when helper " Christian Lamparter
2012-03-09 23:36 ` Greg KH
2012-03-10 0:52 ` Christian Lamparter
2012-03-11 11:56 ` Kay Sievers
2012-03-13 9:37 ` Saravana Kannan
2012-03-13 9:43 ` Saravana Kannan
2012-03-13 20:14 ` Rafael J. Wysocki
2012-03-14 19:21 ` Stephen Boyd
2012-03-14 23:04 ` Rafael J. Wysocki
2012-03-14 23:13 ` Rafael J. Wysocki
2012-03-14 23:17 ` Stephen Boyd
2012-03-14 23:34 ` Rafael J. Wysocki
2012-03-14 23:38 ` Stephen Boyd
2012-03-15 0:11 ` Rafael J. Wysocki
2012-03-15 19:50 ` [PATCH] firmware_class: Move request_firmware_nowait() to workqueues Stephen Boyd
2012-03-15 20:07 ` Christian Lamparter
2012-03-15 20:12 ` Stephen Boyd
2012-03-15 22:31 ` Rafael J. Wysocki
2012-03-16 1:39 ` Stephen Boyd
2012-03-16 20:19 ` Rafael J. Wysocki
2012-03-16 20:26 ` Stephen Boyd
2012-03-16 21:45 ` Rafael J. Wysocki
2012-03-16 22:18 ` Christian Lamparter
2012-03-16 22:35 ` Rafael J. Wysocki
2012-03-17 2:47 ` [PATCH] firmware loader: don't cancel _nowait requests when helper is not yet available Stephen Boyd
2012-03-17 5:51 ` Linus Torvalds
2012-03-17 20:06 ` Rafael J. Wysocki
2012-03-18 8:26 ` Stephen Boyd
2012-03-18 12:01 ` Rafael J. Wysocki
2012-03-19 6:32 ` Stephen Boyd
2012-03-19 11:24 ` Rafael J. Wysocki
2012-03-19 23:00 ` Rafael J. Wysocki
2012-03-25 22:00 ` [PATCH 0/6] firmware_class: Fix problems with usermodehelper test Rafael J. Wysocki
2012-03-25 22:01 ` [PATCH 1/6] firmware_class: Rework usermodehelper check Rafael J. Wysocki
2012-03-25 22:01 ` [PATCH 2/6] firmware_class: Split _request_firmware() into three functions Rafael J. Wysocki
2012-03-26 18:15 ` Stephen Boyd
2012-03-26 18:21 ` Stephen Boyd
2012-03-26 20:12 ` Rafael J. Wysocki
2012-03-26 20:31 ` Stephen Boyd
2012-03-26 20:36 ` Rafael J. Wysocki
2012-03-27 21:35 ` Stephen Boyd
2012-03-27 21:51 ` Rafael J. Wysocki
2012-03-25 22:02 ` [PATCH 3/6] firmware_class: Do not warn that system is not ready from async loads Rafael J. Wysocki
2012-03-25 22:03 ` [PATCH 4/6] PM / Hibernate: Disable usermode helpers right before freezing tasks Rafael J. Wysocki
2012-03-25 22:03 ` [PATCH 5/6] PM / Sleep: Move disabling of usermode helpers to the freezer Rafael J. Wysocki
2012-03-25 22:04 ` [PATCH 6/6] PM / Sleep: Mitigate race between the freezer and request_firmware() Rafael J. Wysocki
2012-03-26 18:16 ` Stephen Boyd
2012-03-26 20:06 ` Rafael J. Wysocki
2012-03-27 21:25 ` Stephen Boyd
2012-03-27 21:37 ` Rafael J. Wysocki
2012-03-26 18:42 ` [PATCH 0/6] firmware_class: Fix problems with usermodehelper test Greg KH
2012-03-26 20:37 ` Rafael J. Wysocki
2012-03-27 21:28 ` [PATCH 1/2] firmware_class: Reorganize fw_create_instance() Stephen Boyd
2012-03-27 21:47 ` Rafael J. Wysocki [this message]
2012-03-27 21:49 ` Greg KH
2012-03-27 21:56 ` Rafael J. Wysocki
2012-03-27 21:28 ` [PATCH 2/2] firmware_class: Move request_firmware_nowait() to workqueues Stephen Boyd
2012-03-27 21:49 ` Rafael J. Wysocki
2012-03-27 22:01 ` Tejun Heo
2012-03-27 22:21 ` Rafael J. Wysocki
2012-03-27 22:48 ` Tejun Heo
2012-03-27 22:55 ` Rafael J. Wysocki
2012-03-27 23:02 ` Stephen Boyd
2012-03-27 23:05 ` Stephen Boyd
2012-03-28 21:19 ` [PATCH v2 0/8] firmware_class: Fix problems with usermodehelper test Rafael J. Wysocki
2012-03-28 21:20 ` [PATCH v2 1/8] firmware_class: Rework usermodehelper check Rafael J. Wysocki
2012-03-28 21:21 ` [PATCH v2 2/8] firmware_class: Split _request_firmware() into three functions, v2 Rafael J. Wysocki
2012-03-28 21:22 ` [PATCH v3 3/8] firmware_class: Do not warn that system is not ready from async loads Rafael J. Wysocki
2012-03-28 21:23 ` [PATCH v2 4/8] PM / Hibernate: Disable usermode helpers right before freezing tasks Rafael J. Wysocki
2012-03-28 21:23 ` [PATCH v2 5/8] PM / Sleep: Move disabling of usermode helpers to the freezer Rafael J. Wysocki
2012-03-28 21:24 ` [PATCH v2 6/8] PM / Sleep: Mitigate race between the freezer and request_firmware() Rafael J. Wysocki
2012-03-28 21:25 ` [PATCH v2 7/8] firmware_class: Reorganize fw_create_instance() Rafael J. Wysocki
2012-03-28 21:26 ` [PATCH v2 8/8] firmware_class: Move request_firmware_nowait() to workqueues Rafael J. Wysocki
2012-03-14 23:19 ` [PATCH] firmware loader: don't cancel _nowait requests when helper is not yet available Rafael J. Wysocki
2012-03-13 19:42 ` Rafael J. Wysocki
2012-03-13 23:25 ` Kay Sievers
2012-03-14 0:10 ` Rafael J. Wysocki
2012-03-14 0:14 ` Kay Sievers
2012-03-14 0:54 ` Linus Torvalds
2012-03-14 1:43 ` Kay Sievers
2012-03-14 1:51 ` Linus Torvalds
2012-03-14 1:55 ` Kay Sievers
2012-03-14 2:00 ` Kay Sievers
2012-03-14 2:21 ` Linus Torvalds
2012-03-14 15:07 ` Srivatsa S. Bhat
2012-03-14 22:54 ` Rafael J. Wysocki
2012-03-16 7:14 ` Srivatsa S. Bhat
2012-03-16 20:23 ` Rafael J. Wysocki
2012-03-16 21:14 ` Christian Lamparter
2012-03-16 21:19 ` Linus Torvalds
2012-03-19 7:06 ` Srivatsa S. Bhat
2012-03-16 22:19 ` [RFC] firmware loader: retry _nowait requests when userhelper " Rafael J. Wysocki
2012-03-16 22:25 ` Christian Lamparter
2012-03-16 22:57 ` Rafael J. Wysocki
2012-03-16 23:35 ` Christian Lamparter
2012-03-16 23:37 ` Linus Torvalds
2012-03-17 0:23 ` Rafael J. Wysocki
2012-03-17 0:33 ` Linus Torvalds
2012-03-18 0:29 ` Rafael J. Wysocki
2012-03-18 2:21 ` Linus Torvalds
2012-03-18 12:21 ` Rafael J. Wysocki
2012-03-18 12:43 ` Christian Lamparter
2012-03-18 23:15 ` [PATCH 0/3] firmware_class: Fix problem with async requests (was: Re: [RFC] firmware loader: retry ...) Rafael J. Wysocki
2012-03-18 23:17 ` [PATCH 1/3] firmware_class: Rework usermodehelper check Rafael J. Wysocki
2012-03-18 23:18 ` [PATCH 2/3] firmware_class: Split _request_firmware() into three functions Rafael J. Wysocki
2012-03-18 23:21 ` [PATCH 3/3] firmware_class: Do not warn that system is not ready for async loads Rafael J. Wysocki
2012-03-19 12:41 ` [RFC] firmware loader: retry _nowait requests when userhelper is not yet available James Courtier-Dutton
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=201203272347.06621.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=chunkeey@googlemail.com \
--cc=gregkh@linuxfoundation.org \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sboyd@codeaurora.org \
--cc=skannan@codeaurora.org \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.org \
/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®