firmware: wrap FW_OPT_* into an enum

This should let us associate enum kdoc to these values.
While at it, kdocify the fw_opt.

Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Acked-by: Luis R. Rodriguez <mcgrof@kernel.org>
[mcgrof: coding style fixes, merge kdoc with enum move]
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Andres Rodriguez 2018-05-10 13:08:37 -07:00 committed by Greg Kroah-Hartman
parent 84d0c27d62
commit eb33eb0492
4 changed files with 42 additions and 19 deletions

View File

@ -512,7 +512,7 @@ static const struct attribute_group *fw_dev_attr_groups[] = {
static struct fw_sysfs *
fw_create_instance(struct firmware *firmware, const char *fw_name,
struct device *device, unsigned int opt_flags)
struct device *device, enum fw_opt opt_flags)
{
struct fw_sysfs *fw_sysfs;
struct device *f_dev;
@ -545,7 +545,7 @@ exit:
* In charge of constructing a sysfs fallback interface for firmware loading.
**/
static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs,
unsigned int opt_flags, long timeout)
enum fw_opt opt_flags, long timeout)
{
int retval = 0;
struct device *f_dev = &fw_sysfs->dev;
@ -599,7 +599,7 @@ err_put_dev:
static int fw_load_from_user_helper(struct firmware *firmware,
const char *name, struct device *device,
unsigned int opt_flags)
enum fw_opt opt_flags)
{
struct fw_sysfs *fw_sysfs;
long timeout;
@ -640,7 +640,7 @@ out_unlock:
return ret;
}
static bool fw_force_sysfs_fallback(unsigned int opt_flags)
static bool fw_force_sysfs_fallback(enum fw_opt opt_flags)
{
if (fw_fallback_config.force_sysfs_fallback)
return true;
@ -649,7 +649,7 @@ static bool fw_force_sysfs_fallback(unsigned int opt_flags)
return true;
}
static bool fw_run_sysfs_fallback(unsigned int opt_flags)
static bool fw_run_sysfs_fallback(enum fw_opt opt_flags)
{
if (fw_fallback_config.ignore_sysfs_fallback) {
pr_info_once("Ignoring firmware sysfs fallback due to sysctl knob\n");
@ -664,7 +664,7 @@ static bool fw_run_sysfs_fallback(unsigned int opt_flags)
int fw_sysfs_fallback(struct firmware *fw, const char *name,
struct device *device,
unsigned int opt_flags,
enum fw_opt opt_flags,
int ret)
{
if (!fw_run_sysfs_fallback(opt_flags))

View File

@ -5,6 +5,8 @@
#include <linux/firmware.h>
#include <linux/device.h>
#include "firmware.h"
/**
* struct firmware_fallback_config - firmware fallback configuration settings
*
@ -31,7 +33,7 @@ struct firmware_fallback_config {
#ifdef CONFIG_FW_LOADER_USER_HELPER
int fw_sysfs_fallback(struct firmware *fw, const char *name,
struct device *device,
unsigned int opt_flags,
enum fw_opt opt_flags,
int ret);
void kill_pending_fw_fallback_reqs(bool only_kill_custom);
@ -43,7 +45,7 @@ void unregister_sysfs_loader(void);
#else /* CONFIG_FW_LOADER_USER_HELPER */
static inline int fw_sysfs_fallback(struct firmware *fw, const char *name,
struct device *device,
unsigned int opt_flags,
enum fw_opt opt_flags,
int ret)
{
/* Keep carrying over the same error */

View File

@ -2,6 +2,7 @@
#ifndef __FIRMWARE_LOADER_H
#define __FIRMWARE_LOADER_H
#include <linux/bitops.h>
#include <linux/firmware.h>
#include <linux/types.h>
#include <linux/kref.h>
@ -10,13 +11,33 @@
#include <generated/utsrelease.h>
/* firmware behavior options */
#define FW_OPT_UEVENT (1U << 0)
#define FW_OPT_NOWAIT (1U << 1)
#define FW_OPT_USERHELPER (1U << 2)
#define FW_OPT_NO_WARN (1U << 3)
#define FW_OPT_NOCACHE (1U << 4)
#define FW_OPT_NOFALLBACK (1U << 5)
/**
* enum fw_opt - options to control firmware loading behaviour
*
* @FW_OPT_UEVENT: Enables the fallback mechanism to send a kobject uevent
* when the firmware is not found. Userspace is in charge to load the
* firmware using the sysfs loading facility.
* @FW_OPT_NOWAIT: Used to describe the firmware request is asynchronous.
* @FW_OPT_USERHELPER: Enable the fallback mechanism, in case the direct
* filesystem lookup fails at finding the firmware. For details refer to
* fw_sysfs_fallback().
* @FW_OPT_NO_WARN: Quiet, avoid printing warning messages.
* @FW_OPT_NOCACHE: Disables firmware caching. Firmware caching is used to
* cache the firmware upon suspend, so that upon resume races against the
* firmware file lookup on storage is avoided. Used for calls where the
* file may be too big, or where the driver takes charge of its own
* firmware caching mechanism.
* @FW_OPT_NOFALLBACK: Disable the fallback mechanism. Takes precedence over
* &FW_OPT_UEVENT and &FW_OPT_USERHELPER.
*/
enum fw_opt {
FW_OPT_UEVENT = BIT(0),
FW_OPT_NOWAIT = BIT(1),
FW_OPT_USERHELPER = BIT(2),
FW_OPT_NO_WARN = BIT(3),
FW_OPT_NOCACHE = BIT(4),
FW_OPT_NOFALLBACK = BIT(5),
};
enum fw_status {
FW_STATUS_UNKNOWN,
@ -110,6 +131,6 @@ static inline void fw_state_done(struct fw_priv *fw_priv)
}
int assign_fw(struct firmware *fw, struct device *device,
unsigned int opt_flags);
enum fw_opt opt_flags);
#endif /* __FIRMWARE_LOADER_H */

View File

@ -443,7 +443,7 @@ static int fw_add_devm_name(struct device *dev, const char *name)
#endif
int assign_fw(struct firmware *fw, struct device *device,
unsigned int opt_flags)
enum fw_opt opt_flags)
{
struct fw_priv *fw_priv = fw->priv;
int ret;
@ -558,7 +558,7 @@ static void fw_abort_batch_reqs(struct firmware *fw)
static int
_request_firmware(const struct firmware **firmware_p, const char *name,
struct device *device, void *buf, size_t size,
unsigned int opt_flags)
enum fw_opt opt_flags)
{
struct firmware *fw = NULL;
int ret;
@ -734,7 +734,7 @@ struct firmware_work {
struct device *device;
void *context;
void (*cont)(const struct firmware *fw, void *context);
unsigned int opt_flags;
enum fw_opt opt_flags;
};
static void request_firmware_work_func(struct work_struct *work)