firmware: Unify the paged buffer release helper

Use a common helper to release the paged buffer resources.
This is rather a preparation for the upcoming decompression support.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Takashi Iwai 2019-05-20 11:26:44 +02:00 committed by Greg Kroah-Hartman
parent ddaf29fd9b
commit 8f58570b98
3 changed files with 25 additions and 16 deletions

View File

@ -259,7 +259,6 @@ static ssize_t firmware_loading_store(struct device *dev,
struct fw_priv *fw_priv;
ssize_t written = count;
int loading = simple_strtol(buf, NULL, 10);
int i;
mutex_lock(&fw_lock);
fw_priv = fw_sysfs->fw_priv;
@ -270,12 +269,7 @@ static ssize_t firmware_loading_store(struct device *dev,
case 1:
/* discarding any previous partial load */
if (!fw_sysfs_done(fw_priv)) {
for (i = 0; i < fw_priv->nr_pages; i++)
__free_page(fw_priv->pages[i]);
vfree(fw_priv->pages);
fw_priv->pages = NULL;
fw_priv->page_array_size = 0;
fw_priv->nr_pages = 0;
fw_free_paged_buf(fw_priv);
fw_state_start(fw_priv);
}
break;

View File

@ -133,4 +133,10 @@ static inline void fw_state_done(struct fw_priv *fw_priv)
int assign_fw(struct firmware *fw, struct device *device,
enum fw_opt opt_flags);
#ifdef CONFIG_FW_LOADER_USER_HELPER
void fw_free_paged_buf(struct fw_priv *fw_priv);
#else
static inline void fw_free_paged_buf(struct fw_priv *fw_priv) {}
#endif
#endif /* __FIRMWARE_LOADER_H */

View File

@ -251,15 +251,7 @@ static void __free_fw_priv(struct kref *ref)
list_del(&fw_priv->list);
spin_unlock(&fwc->lock);
#ifdef CONFIG_FW_LOADER_USER_HELPER
if (fw_priv->pages) {
/* free leftover pages */
int i;
for (i = 0; i < fw_priv->nr_pages; i++)
__free_page(fw_priv->pages[i]);
vfree(fw_priv->pages);
}
#endif
fw_free_paged_buf(fw_priv); /* free leftover pages */
if (!fw_priv->allocated_size)
vfree(fw_priv->data);
kfree_const(fw_priv->fw_name);
@ -274,6 +266,23 @@ static void free_fw_priv(struct fw_priv *fw_priv)
spin_unlock(&fwc->lock);
}
#ifdef CONFIG_FW_LOADER_USER_HELPER
void fw_free_paged_buf(struct fw_priv *fw_priv)
{
int i;
if (!fw_priv->pages)
return;
for (i = 0; i < fw_priv->nr_pages; i++)
__free_page(fw_priv->pages[i]);
vfree(fw_priv->pages);
fw_priv->pages = NULL;
fw_priv->page_array_size = 0;
fw_priv->nr_pages = 0;
}
#endif
/* direct firmware loading support */
static char fw_path_para[256];
static const char * const fw_path[] = {