diff options
author | Luis R. Rodriguez <mcgrof@kernel.org> | 2018-03-10 09:14:48 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-03-20 04:28:46 -0400 |
commit | e05cb73f83918b9bde2063de08467f2261d0f5bb (patch) | |
tree | 65a79cec2f39d7d4983f2578e057fbbc901148d7 | |
parent | 5d9566b144fdbbedf64dbf0907d2933fbcfb6872 (diff) |
firmware: move loading timeout under struct firmware_fallback_config
The timeout is a fallback construct, so we can just stuff the
timeout configuration under struct firmware_fallback_config.
While at it, add a few helpers which vets the use of getting or
setting the timeout as an int. The main use of the timeout is
to set a timeout for completion, and that is used as an unsigned
long. There a few cases however where it makes sense to get or
set the timeout as an int, the helpers annotate these use cases
have been properly vetted for.
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/base/firmware_loader.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/drivers/base/firmware_loader.c b/drivers/base/firmware_loader.c index 2d819875348d..9757f9fff01e 100644 --- a/drivers/base/firmware_loader.c +++ b/drivers/base/firmware_loader.c | |||
@@ -266,21 +266,38 @@ static inline bool fw_state_is_aborted(struct fw_priv *fw_priv) | |||
266 | * | 266 | * |
267 | * @force_sysfs_fallback: force the sysfs fallback mechanism to be used | 267 | * @force_sysfs_fallback: force the sysfs fallback mechanism to be used |
268 | * as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y. | 268 | * as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y. |
269 | * @old_timeout: for internal use | ||
270 | * @loading_timeout: the timeout to wait for the fallback mechanism before | ||
271 | * giving up, in seconds. | ||
269 | */ | 272 | */ |
270 | struct firmware_fallback_config { | 273 | struct firmware_fallback_config { |
271 | bool force_sysfs_fallback; | 274 | const bool force_sysfs_fallback; |
275 | int old_timeout; | ||
276 | int loading_timeout; | ||
272 | }; | 277 | }; |
273 | 278 | ||
274 | static const struct firmware_fallback_config fw_fallback_config = { | 279 | static struct firmware_fallback_config fw_fallback_config = { |
275 | .force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK), | 280 | .force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK), |
281 | .loading_timeout = 60, | ||
282 | .old_timeout = 60, | ||
276 | }; | 283 | }; |
277 | 284 | ||
278 | static int old_timeout; | 285 | /* These getters are vetted to use int properly */ |
279 | static int loading_timeout = 60; /* In seconds */ | 286 | static inline int __firmware_loading_timeout(void) |
287 | { | ||
288 | return fw_fallback_config.loading_timeout; | ||
289 | } | ||
290 | |||
291 | /* These setters are vetted to use int properly */ | ||
292 | static void __fw_fallback_set_timeout(int timeout) | ||
293 | { | ||
294 | fw_fallback_config.loading_timeout = timeout; | ||
295 | } | ||
280 | 296 | ||
281 | static inline long firmware_loading_timeout(void) | 297 | static inline long firmware_loading_timeout(void) |
282 | { | 298 | { |
283 | return loading_timeout > 0 ? loading_timeout * HZ : MAX_JIFFY_OFFSET; | 299 | return __firmware_loading_timeout() > 0 ? |
300 | __firmware_loading_timeout() * HZ : MAX_JIFFY_OFFSET; | ||
284 | } | 301 | } |
285 | 302 | ||
286 | /* | 303 | /* |
@@ -291,14 +308,14 @@ static inline long firmware_loading_timeout(void) | |||
291 | */ | 308 | */ |
292 | static void fw_fallback_set_cache_timeout(void) | 309 | static void fw_fallback_set_cache_timeout(void) |
293 | { | 310 | { |
294 | old_timeout = loading_timeout; | 311 | fw_fallback_config.old_timeout = __firmware_loading_timeout(); |
295 | loading_timeout = 10; | 312 | __fw_fallback_set_timeout(10); |
296 | } | 313 | } |
297 | 314 | ||
298 | /* Restores the timeout to the value last configured during normal operation */ | 315 | /* Restores the timeout to the value last configured during normal operation */ |
299 | static void fw_fallback_set_default_timeout(void) | 316 | static void fw_fallback_set_default_timeout(void) |
300 | { | 317 | { |
301 | loading_timeout = old_timeout; | 318 | __fw_fallback_set_timeout(fw_fallback_config.old_timeout); |
302 | } | 319 | } |
303 | 320 | ||
304 | static inline bool fw_sysfs_done(struct fw_priv *fw_priv) | 321 | static inline bool fw_sysfs_done(struct fw_priv *fw_priv) |
@@ -677,7 +694,7 @@ static void kill_pending_fw_fallback_reqs(bool only_kill_custom) | |||
677 | static ssize_t timeout_show(struct class *class, struct class_attribute *attr, | 694 | static ssize_t timeout_show(struct class *class, struct class_attribute *attr, |
678 | char *buf) | 695 | char *buf) |
679 | { | 696 | { |
680 | return sprintf(buf, "%d\n", loading_timeout); | 697 | return sprintf(buf, "%d\n", __firmware_loading_timeout()); |
681 | } | 698 | } |
682 | 699 | ||
683 | /** | 700 | /** |
@@ -696,9 +713,12 @@ static ssize_t timeout_show(struct class *class, struct class_attribute *attr, | |||
696 | static ssize_t timeout_store(struct class *class, struct class_attribute *attr, | 713 | static ssize_t timeout_store(struct class *class, struct class_attribute *attr, |
697 | const char *buf, size_t count) | 714 | const char *buf, size_t count) |
698 | { | 715 | { |
699 | loading_timeout = simple_strtol(buf, NULL, 10); | 716 | int tmp_loading_timeout = simple_strtol(buf, NULL, 10); |
700 | if (loading_timeout < 0) | 717 | |
701 | loading_timeout = 0; | 718 | if (tmp_loading_timeout < 0) |
719 | tmp_loading_timeout = 0; | ||
720 | |||
721 | __fw_fallback_set_timeout(tmp_loading_timeout); | ||
702 | 722 | ||
703 | return count; | 723 | return count; |
704 | } | 724 | } |
@@ -721,7 +741,7 @@ static int do_firmware_uevent(struct fw_sysfs *fw_sysfs, struct kobj_uevent_env | |||
721 | { | 741 | { |
722 | if (add_uevent_var(env, "FIRMWARE=%s", fw_sysfs->fw_priv->fw_name)) | 742 | if (add_uevent_var(env, "FIRMWARE=%s", fw_sysfs->fw_priv->fw_name)) |
723 | return -ENOMEM; | 743 | return -ENOMEM; |
724 | if (add_uevent_var(env, "TIMEOUT=%i", loading_timeout)) | 744 | if (add_uevent_var(env, "TIMEOUT=%i", __firmware_loading_timeout())) |
725 | return -ENOMEM; | 745 | return -ENOMEM; |
726 | if (add_uevent_var(env, "ASYNC=%d", fw_sysfs->nowait)) | 746 | if (add_uevent_var(env, "ASYNC=%d", fw_sysfs->nowait)) |
727 | return -ENOMEM; | 747 | return -ENOMEM; |