]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/base/firmware_class.c
firmware loader: fix another compile warning with PM_SLEEP unset
[karo-tx-linux.git] / drivers / base / firmware_class.c
index 47e3a228072ddc7324a4b5f281230ae34aa8e7f0..a439602ea9194f409286147d4e33b39cc1114cda 100644 (file)
@@ -218,18 +218,6 @@ static int fw_lookup_and_allocate_buf(const char *fw_name,
        return tmp ? 0 : -ENOMEM;
 }
 
-static struct firmware_buf *fw_lookup_buf(const char *fw_name)
-{
-       struct firmware_buf *tmp;
-       struct firmware_cache *fwc = &fw_cache;
-
-       spin_lock(&fwc->lock);
-       tmp = __fw_lookup_buf(fw_name);
-       spin_unlock(&fwc->lock);
-
-       return tmp;
-}
-
 static void __fw_free_buf(struct kref *ref)
 {
        struct firmware_buf *buf = to_fwbuf(ref);
@@ -452,13 +440,30 @@ static struct firmware_priv *to_firmware_priv(struct device *dev)
        return container_of(dev, struct firmware_priv, dev);
 }
 
-static void fw_load_abort(struct firmware_buf *buf)
+static void __fw_load_abort(struct firmware_buf *buf)
 {
+       /*
+        * There is a small window in which user can write to 'loading'
+        * between loading done and disappearance of 'loading'
+        */
+       if (test_bit(FW_STATUS_DONE, &buf->status))
+               return;
+
        list_del_init(&buf->pending_list);
        set_bit(FW_STATUS_ABORT, &buf->status);
        complete_all(&buf->completion);
 }
 
+static void fw_load_abort(struct firmware_priv *fw_priv)
+{
+       struct firmware_buf *buf = fw_priv->buf;
+
+       __fw_load_abort(buf);
+
+       /* avoid user action after loading abort */
+       fw_priv->buf = NULL;
+}
+
 #define is_fw_load_aborted(buf)        \
        test_bit(FW_STATUS_ABORT, &(buf)->status)
 
@@ -470,7 +475,7 @@ static int fw_shutdown_notify(struct notifier_block *unused1,
 {
        mutex_lock(&fw_lock);
        while (!list_empty(&pending_fw_head))
-               fw_load_abort(list_first_entry(&pending_fw_head,
+               __fw_load_abort(list_first_entry(&pending_fw_head,
                                               struct firmware_buf,
                                               pending_list));
        mutex_unlock(&fw_lock);
@@ -523,8 +528,6 @@ static void fw_dev_release(struct device *dev)
        struct firmware_priv *fw_priv = to_firmware_priv(dev);
 
        kfree(fw_priv);
-
-       module_put(THIS_MODULE);
 }
 
 static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
@@ -552,7 +555,12 @@ static ssize_t firmware_loading_show(struct device *dev,
                                     struct device_attribute *attr, char *buf)
 {
        struct firmware_priv *fw_priv = to_firmware_priv(dev);
-       int loading = test_bit(FW_STATUS_LOADING, &fw_priv->buf->status);
+       int loading = 0;
+
+       mutex_lock(&fw_lock);
+       if (fw_priv->buf)
+               loading = test_bit(FW_STATUS_LOADING, &fw_priv->buf->status);
+       mutex_unlock(&fw_lock);
 
        return sprintf(buf, "%d\n", loading);
 }
@@ -594,12 +602,12 @@ static ssize_t firmware_loading_store(struct device *dev,
                                      const char *buf, size_t count)
 {
        struct firmware_priv *fw_priv = to_firmware_priv(dev);
-       struct firmware_buf *fw_buf = fw_priv->buf;
+       struct firmware_buf *fw_buf;
        int loading = simple_strtol(buf, NULL, 10);
        int i;
 
        mutex_lock(&fw_lock);
-
+       fw_buf = fw_priv->buf;
        if (!fw_buf)
                goto out;
 
@@ -637,7 +645,7 @@ static ssize_t firmware_loading_store(struct device *dev,
                dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading);
                /* fallthrough */
        case -1:
-               fw_load_abort(fw_buf);
+               fw_load_abort(fw_priv);
                break;
        }
 out:
@@ -705,7 +713,7 @@ static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
                new_pages = kmalloc(new_array_size * sizeof(void *),
                                    GFP_KERNEL);
                if (!new_pages) {
-                       fw_load_abort(buf);
+                       fw_load_abort(fw_priv);
                        return -ENOMEM;
                }
                memcpy(new_pages, buf->pages,
@@ -722,7 +730,7 @@ static int fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
                        alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
 
                if (!buf->pages[buf->nr_pages]) {
-                       fw_load_abort(buf);
+                       fw_load_abort(fw_priv);
                        return -ENOMEM;
                }
                buf->nr_pages++;
@@ -802,11 +810,7 @@ static void firmware_class_timeout_work(struct work_struct *work)
                        struct firmware_priv, timeout_work.work);
 
        mutex_lock(&fw_lock);
-       if (test_bit(FW_STATUS_DONE, &(fw_priv->buf->status))) {
-               mutex_unlock(&fw_lock);
-               return;
-       }
-       fw_load_abort(fw_priv->buf);
+       fw_load_abort(fw_priv);
        mutex_unlock(&fw_lock);
 }
 
@@ -852,9 +856,6 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent,
 
        dev_set_uevent_suppress(f_dev, true);
 
-       /* Need to pin this module until class device is destroyed */
-       __module_get(THIS_MODULE);
-
        retval = device_add(f_dev);
        if (retval) {
                dev_err(f_dev, "%s: device_register failed\n", __func__);
@@ -891,8 +892,6 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent,
 
        cancel_delayed_work_sync(&fw_priv->timeout_work);
 
-       fw_priv->buf = NULL;
-
        device_remove_file(f_dev, &dev_attr_loading);
 err_del_bin_attr:
        device_remove_bin_file(f_dev, &firmware_attr_data);
@@ -927,7 +926,7 @@ static void kill_requests_without_uevent(void)
        mutex_lock(&fw_lock);
        list_for_each_entry_safe(buf, next, &pending_fw_head, pending_list) {
                if (!buf->need_uevent)
-                        fw_load_abort(buf);
+                        __fw_load_abort(buf);
        }
        mutex_unlock(&fw_lock);
 }
@@ -1131,7 +1130,13 @@ int
 request_firmware(const struct firmware **firmware_p, const char *name,
                  struct device *device)
 {
-       return _request_firmware(firmware_p, name, device, true, false);
+       int ret;
+
+       /* Need to pin this module until return */
+       __module_get(THIS_MODULE);
+       ret = _request_firmware(firmware_p, name, device, true, false);
+       module_put(THIS_MODULE);
+       return ret;
 }
 EXPORT_SYMBOL(request_firmware);
 
@@ -1230,6 +1235,9 @@ request_firmware_nowait(
 }
 EXPORT_SYMBOL(request_firmware_nowait);
 
+#ifdef CONFIG_PM_SLEEP
+static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain);
+
 /**
  * cache_firmware - cache one firmware image in kernel memory space
  * @fw_name: the firmware image name
@@ -1244,7 +1252,7 @@ EXPORT_SYMBOL(request_firmware_nowait);
  * Return !0 otherwise
  *
  */
-int cache_firmware(const char *fw_name)
+static int cache_firmware(const char *fw_name)
 {
        int ret;
        const struct firmware *fw;
@@ -1259,7 +1267,18 @@ int cache_firmware(const char *fw_name)
 
        return ret;
 }
-EXPORT_SYMBOL_GPL(cache_firmware);
+
+static struct firmware_buf *fw_lookup_buf(const char *fw_name)
+{
+       struct firmware_buf *tmp;
+       struct firmware_cache *fwc = &fw_cache;
+
+       spin_lock(&fwc->lock);
+       tmp = __fw_lookup_buf(fw_name);
+       spin_unlock(&fwc->lock);
+
+       return tmp;
+}
 
 /**
  * uncache_firmware - remove one cached firmware image
@@ -1272,7 +1291,7 @@ EXPORT_SYMBOL_GPL(cache_firmware);
  * Return !0 otherwise
  *
  */
-int uncache_firmware(const char *fw_name)
+static int uncache_firmware(const char *fw_name)
 {
        struct firmware_buf *buf;
        struct firmware fw;
@@ -1290,10 +1309,6 @@ int uncache_firmware(const char *fw_name)
 
        return -EINVAL;
 }
-EXPORT_SYMBOL_GPL(uncache_firmware);
-
-#ifdef CONFIG_PM_SLEEP
-static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain);
 
 static struct fw_cache_entry *alloc_fw_cache_entry(const char *name)
 {