diff options
author | Takashi Iwai <tiwai@suse.de> | 2013-12-02 09:38:18 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-12-08 21:22:32 -0500 |
commit | 14c4bae77c80bd37f19d95405d42bd0b1fd95add (patch) | |
tree | 20922f074d84715b7230d4fd1d0b6ae287c8b654 /drivers/base | |
parent | 75da02b29fd99cb2d6ac822f2864de4d6e35b9fd (diff) |
firmware: Use bit flags instead of boolean combos
More than two boolean arguments to a function are rather confusing and
error-prone for callers. Let's make the behavior bit flags instead of
triple combos.
A nice suggestion by Borislav Petkov.
Acked-by: Borislav Petkov <bp@suse.de>
Acked-by: Prarit Bhargava <prarit@redhat.com>
Acked-by: Ming Lei <ming.lei@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r-- | drivers/base/firmware_class.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 1af03648daf8..65797742c6b6 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -96,6 +96,11 @@ static inline long firmware_loading_timeout(void) | |||
96 | return loading_timeout > 0 ? loading_timeout * HZ : MAX_SCHEDULE_TIMEOUT; | 96 | return loading_timeout > 0 ? loading_timeout * HZ : MAX_SCHEDULE_TIMEOUT; |
97 | } | 97 | } |
98 | 98 | ||
99 | /* firmware behavior options */ | ||
100 | #define FW_OPT_UEVENT (1U << 0) | ||
101 | #define FW_OPT_NOWAIT (1U << 1) | ||
102 | #define FW_OPT_FALLBACK (1U << 2) | ||
103 | |||
99 | struct firmware_cache { | 104 | struct firmware_cache { |
100 | /* firmware_buf instance will be added into the below list */ | 105 | /* firmware_buf instance will be added into the below list */ |
101 | spinlock_t lock; | 106 | spinlock_t lock; |
@@ -820,7 +825,7 @@ static void firmware_class_timeout_work(struct work_struct *work) | |||
820 | 825 | ||
821 | static struct firmware_priv * | 826 | static struct firmware_priv * |
822 | fw_create_instance(struct firmware *firmware, const char *fw_name, | 827 | fw_create_instance(struct firmware *firmware, const char *fw_name, |
823 | struct device *device, bool uevent, bool nowait) | 828 | struct device *device, unsigned int opt_flags) |
824 | { | 829 | { |
825 | struct firmware_priv *fw_priv; | 830 | struct firmware_priv *fw_priv; |
826 | struct device *f_dev; | 831 | struct device *f_dev; |
@@ -832,7 +837,7 @@ fw_create_instance(struct firmware *firmware, const char *fw_name, | |||
832 | goto exit; | 837 | goto exit; |
833 | } | 838 | } |
834 | 839 | ||
835 | fw_priv->nowait = nowait; | 840 | fw_priv->nowait = !!(opt_flags & FW_OPT_NOWAIT); |
836 | fw_priv->fw = firmware; | 841 | fw_priv->fw = firmware; |
837 | INIT_DELAYED_WORK(&fw_priv->timeout_work, | 842 | INIT_DELAYED_WORK(&fw_priv->timeout_work, |
838 | firmware_class_timeout_work); | 843 | firmware_class_timeout_work); |
@@ -848,8 +853,8 @@ exit: | |||
848 | } | 853 | } |
849 | 854 | ||
850 | /* load a firmware via user helper */ | 855 | /* load a firmware via user helper */ |
851 | static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, | 856 | static int _request_firmware_load(struct firmware_priv *fw_priv, |
852 | long timeout) | 857 | unsigned int opt_flags, long timeout) |
853 | { | 858 | { |
854 | int retval = 0; | 859 | int retval = 0; |
855 | struct device *f_dev = &fw_priv->dev; | 860 | struct device *f_dev = &fw_priv->dev; |
@@ -885,7 +890,7 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, | |||
885 | goto err_del_bin_attr; | 890 | goto err_del_bin_attr; |
886 | } | 891 | } |
887 | 892 | ||
888 | if (uevent) { | 893 | if (opt_flags & FW_OPT_UEVENT) { |
889 | buf->need_uevent = true; | 894 | buf->need_uevent = true; |
890 | dev_set_uevent_suppress(f_dev, false); | 895 | dev_set_uevent_suppress(f_dev, false); |
891 | dev_dbg(f_dev, "firmware: requesting %s\n", buf->fw_id); | 896 | dev_dbg(f_dev, "firmware: requesting %s\n", buf->fw_id); |
@@ -911,16 +916,16 @@ err_put_dev: | |||
911 | 916 | ||
912 | static int fw_load_from_user_helper(struct firmware *firmware, | 917 | static int fw_load_from_user_helper(struct firmware *firmware, |
913 | const char *name, struct device *device, | 918 | const char *name, struct device *device, |
914 | bool uevent, bool nowait, long timeout) | 919 | unsigned int opt_flags, long timeout) |
915 | { | 920 | { |
916 | struct firmware_priv *fw_priv; | 921 | struct firmware_priv *fw_priv; |
917 | 922 | ||
918 | fw_priv = fw_create_instance(firmware, name, device, uevent, nowait); | 923 | fw_priv = fw_create_instance(firmware, name, device, opt_flags); |
919 | if (IS_ERR(fw_priv)) | 924 | if (IS_ERR(fw_priv)) |
920 | return PTR_ERR(fw_priv); | 925 | return PTR_ERR(fw_priv); |
921 | 926 | ||
922 | fw_priv->buf = firmware->priv; | 927 | fw_priv->buf = firmware->priv; |
923 | return _request_firmware_load(fw_priv, uevent, timeout); | 928 | return _request_firmware_load(fw_priv, opt_flags, timeout); |
924 | } | 929 | } |
925 | 930 | ||
926 | #ifdef CONFIG_PM_SLEEP | 931 | #ifdef CONFIG_PM_SLEEP |
@@ -942,7 +947,7 @@ static void kill_requests_without_uevent(void) | |||
942 | #else /* CONFIG_FW_LOADER_USER_HELPER */ | 947 | #else /* CONFIG_FW_LOADER_USER_HELPER */ |
943 | static inline int | 948 | static inline int |
944 | fw_load_from_user_helper(struct firmware *firmware, const char *name, | 949 | fw_load_from_user_helper(struct firmware *firmware, const char *name, |
945 | struct device *device, bool uevent, bool nowait, | 950 | struct device *device, unsigned int opt_flags, |
946 | long timeout) | 951 | long timeout) |
947 | { | 952 | { |
948 | return -ENOENT; | 953 | return -ENOENT; |
@@ -1023,7 +1028,7 @@ _request_firmware_prepare(struct firmware **firmware_p, const char *name, | |||
1023 | } | 1028 | } |
1024 | 1029 | ||
1025 | static int assign_firmware_buf(struct firmware *fw, struct device *device, | 1030 | static int assign_firmware_buf(struct firmware *fw, struct device *device, |
1026 | bool skip_cache) | 1031 | unsigned int opt_flags) |
1027 | { | 1032 | { |
1028 | struct firmware_buf *buf = fw->priv; | 1033 | struct firmware_buf *buf = fw->priv; |
1029 | 1034 | ||
@@ -1040,7 +1045,8 @@ static int assign_firmware_buf(struct firmware *fw, struct device *device, | |||
1040 | * device may has been deleted already, but the problem | 1045 | * device may has been deleted already, but the problem |
1041 | * should be fixed in devres or driver core. | 1046 | * should be fixed in devres or driver core. |
1042 | */ | 1047 | */ |
1043 | if (device && !skip_cache) | 1048 | /* don't cache firmware handled without uevent */ |
1049 | if (device && (opt_flags & FW_OPT_UEVENT)) | ||
1044 | fw_add_devm_name(device, buf->fw_id); | 1050 | fw_add_devm_name(device, buf->fw_id); |
1045 | 1051 | ||
1046 | /* | 1052 | /* |
@@ -1061,7 +1067,7 @@ static int assign_firmware_buf(struct firmware *fw, struct device *device, | |||
1061 | /* called from request_firmware() and request_firmware_work_func() */ | 1067 | /* called from request_firmware() and request_firmware_work_func() */ |
1062 | static int | 1068 | static int |
1063 | _request_firmware(const struct firmware **firmware_p, const char *name, | 1069 | _request_firmware(const struct firmware **firmware_p, const char *name, |
1064 | struct device *device, bool uevent, bool nowait, bool fallback) | 1070 | struct device *device, unsigned int opt_flags) |
1065 | { | 1071 | { |
1066 | struct firmware *fw; | 1072 | struct firmware *fw; |
1067 | long timeout; | 1073 | long timeout; |
@@ -1076,7 +1082,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name, | |||
1076 | 1082 | ||
1077 | ret = 0; | 1083 | ret = 0; |
1078 | timeout = firmware_loading_timeout(); | 1084 | timeout = firmware_loading_timeout(); |
1079 | if (nowait) { | 1085 | if (opt_flags & FW_OPT_NOWAIT) { |
1080 | timeout = usermodehelper_read_lock_wait(timeout); | 1086 | timeout = usermodehelper_read_lock_wait(timeout); |
1081 | if (!timeout) { | 1087 | if (!timeout) { |
1082 | dev_dbg(device, "firmware: %s loading timed out\n", | 1088 | dev_dbg(device, "firmware: %s loading timed out\n", |
@@ -1095,19 +1101,18 @@ _request_firmware(const struct firmware **firmware_p, const char *name, | |||
1095 | 1101 | ||
1096 | ret = fw_get_filesystem_firmware(device, fw->priv); | 1102 | ret = fw_get_filesystem_firmware(device, fw->priv); |
1097 | if (ret) { | 1103 | if (ret) { |
1098 | if (fallback) { | 1104 | if (opt_flags & FW_OPT_FALLBACK) { |
1099 | dev_warn(device, | 1105 | dev_warn(device, |
1100 | "Direct firmware load failed with error %d\n", | 1106 | "Direct firmware load failed with error %d\n", |
1101 | ret); | 1107 | ret); |
1102 | dev_warn(device, "Falling back to user helper\n"); | 1108 | dev_warn(device, "Falling back to user helper\n"); |
1103 | ret = fw_load_from_user_helper(fw, name, device, | 1109 | ret = fw_load_from_user_helper(fw, name, device, |
1104 | uevent, nowait, timeout); | 1110 | opt_flags, timeout); |
1105 | } | 1111 | } |
1106 | } | 1112 | } |
1107 | 1113 | ||
1108 | /* don't cache firmware handled without uevent */ | ||
1109 | if (!ret) | 1114 | if (!ret) |
1110 | ret = assign_firmware_buf(fw, device, !uevent); | 1115 | ret = assign_firmware_buf(fw, device, opt_flags); |
1111 | 1116 | ||
1112 | usermodehelper_read_unlock(); | 1117 | usermodehelper_read_unlock(); |
1113 | 1118 | ||
@@ -1149,7 +1154,8 @@ request_firmware(const struct firmware **firmware_p, const char *name, | |||
1149 | 1154 | ||
1150 | /* Need to pin this module until return */ | 1155 | /* Need to pin this module until return */ |
1151 | __module_get(THIS_MODULE); | 1156 | __module_get(THIS_MODULE); |
1152 | ret = _request_firmware(firmware_p, name, device, true, false, true); | 1157 | ret = _request_firmware(firmware_p, name, device, |
1158 | FW_OPT_UEVENT | FW_OPT_FALLBACK); | ||
1153 | module_put(THIS_MODULE); | 1159 | module_put(THIS_MODULE); |
1154 | return ret; | 1160 | return ret; |
1155 | } | 1161 | } |
@@ -1172,7 +1178,7 @@ int request_firmware_direct(const struct firmware **firmware_p, | |||
1172 | { | 1178 | { |
1173 | int ret; | 1179 | int ret; |
1174 | __module_get(THIS_MODULE); | 1180 | __module_get(THIS_MODULE); |
1175 | ret = _request_firmware(firmware_p, name, device, true, false, false); | 1181 | ret = _request_firmware(firmware_p, name, device, FW_OPT_UEVENT); |
1176 | module_put(THIS_MODULE); | 1182 | module_put(THIS_MODULE); |
1177 | return ret; | 1183 | return ret; |
1178 | } | 1184 | } |
@@ -1201,7 +1207,7 @@ struct firmware_work { | |||
1201 | struct device *device; | 1207 | struct device *device; |
1202 | void *context; | 1208 | void *context; |
1203 | void (*cont)(const struct firmware *fw, void *context); | 1209 | void (*cont)(const struct firmware *fw, void *context); |
1204 | bool uevent; | 1210 | unsigned int opt_flags; |
1205 | }; | 1211 | }; |
1206 | 1212 | ||
1207 | static void request_firmware_work_func(struct work_struct *work) | 1213 | static void request_firmware_work_func(struct work_struct *work) |
@@ -1212,7 +1218,7 @@ static void request_firmware_work_func(struct work_struct *work) | |||
1212 | fw_work = container_of(work, struct firmware_work, work); | 1218 | fw_work = container_of(work, struct firmware_work, work); |
1213 | 1219 | ||
1214 | _request_firmware(&fw, fw_work->name, fw_work->device, | 1220 | _request_firmware(&fw, fw_work->name, fw_work->device, |
1215 | fw_work->uevent, true, true); | 1221 | fw_work->opt_flags); |
1216 | fw_work->cont(fw, fw_work->context); | 1222 | fw_work->cont(fw, fw_work->context); |
1217 | put_device(fw_work->device); /* taken in request_firmware_nowait() */ | 1223 | put_device(fw_work->device); /* taken in request_firmware_nowait() */ |
1218 | 1224 | ||
@@ -1260,7 +1266,8 @@ request_firmware_nowait( | |||
1260 | fw_work->device = device; | 1266 | fw_work->device = device; |
1261 | fw_work->context = context; | 1267 | fw_work->context = context; |
1262 | fw_work->cont = cont; | 1268 | fw_work->cont = cont; |
1263 | fw_work->uevent = uevent; | 1269 | fw_work->opt_flags = FW_OPT_NOWAIT | FW_OPT_FALLBACK | |
1270 | (uevent ? FW_OPT_UEVENT : 0); | ||
1264 | 1271 | ||
1265 | if (!try_module_get(module)) { | 1272 | if (!try_module_get(module)) { |
1266 | kfree(fw_work); | 1273 | kfree(fw_work); |