Received: by 10.223.185.116 with SMTP id b49csp5536573wrg; Tue, 27 Feb 2018 15:22:40 -0800 (PST) X-Google-Smtp-Source: AG47ELsV5fndJOLLp3wq0iVEfw0Y4xJpJg2IaMumIzawH1ASHTrxPsDO1QKaYE0eV2llDzcwe53X X-Received: by 2002:a17:902:7290:: with SMTP id d16-v6mr13739214pll.31.1519773760694; Tue, 27 Feb 2018 15:22:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519773760; cv=none; d=google.com; s=arc-20160816; b=u6o97EPpr6ZhCn/Gj1wKXUUCakHTmhCEAdpezmnIFLJRtwTiArKFx/CB+YiH+qGaDG hihfJah5XYq/DVemp1uPKaGuNSq4RuFddNA9mSJyZP2ThHj7/LuOIkkzRrfdyF1QlXJM ndo62dfmyEemwS2JpDHeeII5fpaz+YphjzAnkG6lC5T1V1WQLPqJO6CRcgYE3LY/JnUq lHPO4MhDVtiSG/ZH5h9JCW4wy/T+XXRDP+xjhmz3UMaRgxba3qnWt8t0L9v0IRngNyCN 2WyhK2+iU/aLSv40LrDskWBHqNuKI8HcLnmjR3XIwjHKbdH0IfA1QjZuI6cRoQXfE5o0 JhcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=3RdfTT0amCvM3dUUgFKv5Cy0oZtGWGG9SFiXUlMMigw=; b=Gvyuysan0t4xBWpcyKwKjg/HqeeJ8OegR2quUsIAmLBolgxXJcLwkYNpsSkf4CFmF8 ZvndKc6DhRE6uiA/8QxPwVLnymWYCwlCJVMlrbJ05y4gJU57dS3xCkj4JbHe6wUkiui6 4e0v+WJAh3v6fvde/eM5yw97qrzEh9UU+SdQj9zfRN4Xy0WmqJUGxGcvybw8FmpsArkO t2YyN65KB/S475QJgOQnJxOoayNDscTpMVr5imVRvXEHpNALXw7BZJdQ5CJtVLpfgAxh bmxevg2OmBs1ENrWtrSlM8XT7PPmslC9IDKWWq3ejVrxysk2ksh4dCt7B5iOYfntwrEi w9Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=cPeheTA1; dkim=fail header.i=@chromium.org header.s=google header.b=neN/Z0FH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si200254plp.678.2018.02.27.15.22.25; Tue, 27 Feb 2018 15:22:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=cPeheTA1; dkim=fail header.i=@chromium.org header.s=google header.b=neN/Z0FH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752244AbeB0XVZ (ORCPT + 99 others); Tue, 27 Feb 2018 18:21:25 -0500 Received: from mail-vk0-f66.google.com ([209.85.213.66]:35444 "EHLO mail-vk0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752220AbeB0XVV (ORCPT ); Tue, 27 Feb 2018 18:21:21 -0500 Received: by mail-vk0-f66.google.com with SMTP id b65so369249vka.2 for ; Tue, 27 Feb 2018 15:21:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=3RdfTT0amCvM3dUUgFKv5Cy0oZtGWGG9SFiXUlMMigw=; b=cPeheTA1pGHOJTyooxfyIMHQSD5BqRfL4pb9puAVvQU5oVaev49XZz9x8ZMTgHOHXu 7oFAOj8QzMRxKC1brpmRoMxyWpUcrOQG9fkePZ5SS04kj/7i2JZT8dKfPZD0OtKyu/0x ++wOlhOiMRcIe3mzrMMbsJRNrLPZdAwqMjrhQDG3Q+iGEub7SGx2VIi1xJd8ldfgWpQF ibvk4/Zo3MKTx86foSjFWjYTxS/cCHZfm0Vz6sn8A0x1SMQKTfSVX8741zwoooW8psHT iMZDZ+kd3zJK1DhgfdhyfQlknSDCR58f+y1qRbINF63gZvIopqPkWnTW6dvNcae/HNP0 5aMA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=3RdfTT0amCvM3dUUgFKv5Cy0oZtGWGG9SFiXUlMMigw=; b=neN/Z0FHZp+AUkMn+i2Nvl9l9WO3shWKGyYaYN71kU1skxEDtMKCRQE3jxKfbJl/b+ PCoVpow8SsD13Su/ieeBcw/GTKdpVGrM1hZcQhAq0QKEr6drRcWdRs9uORsPzicD/gna 5RP7bH8wJW56hw9OAQc4Ra0iIaZd+O/1VByUs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=3RdfTT0amCvM3dUUgFKv5Cy0oZtGWGG9SFiXUlMMigw=; b=H0jJ7eU5lNrefIz1vgyG3XBAJC3JncSTuQdNDn9lHEeaVpH1/4qsggswRdO/bR55bO IY4tPKrUoTnfsqSa065YH3rcmWMaYNvyiNigQMCAgGLzy3SNCqNt1Eohf+8Q/+ubnloU CsIgUIRo7IlvSlLl0swIGdBMQI5RKdQ9qaFpqxZ0j4h1LYktCnbQFxOXREZ/eFrOcEIK nXwQ7Ky9yIXV9sC5g5j1/bfkfvM8CCQlTkNGif9hql4SdAYcqChLMQlQvptmQXhJqM9n v5QeiLv8ZlA2YRHJXNXKzMcD1WRhRZ5+LNRIJVhNGwptpZxbtCJaWA2HxTDh1W5YULu9 jAFg== X-Gm-Message-State: APf1xPD8Tiaf0fKzaMZLVA0D7AoMn1QLcIjq4ehDeoKXH9EBqMUb7Sy6 fs5wNBBCtdMCwy17RPFA9h2LDFz8sVV6tHYqPwQMaA== X-Received: by 10.31.152.139 with SMTP id a133mr12599661vke.96.1519773679968; Tue, 27 Feb 2018 15:21:19 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.242.140 with HTTP; Tue, 27 Feb 2018 15:21:19 -0800 (PST) In-Reply-To: <20180224024613.24078-7-mcgrof@kernel.org> References: <20180224024613.24078-1-mcgrof@kernel.org> <20180224024613.24078-7-mcgrof@kernel.org> From: Kees Cook Date: Tue, 27 Feb 2018 15:21:19 -0800 X-Google-Sender-Auth: ziddqQ88V5-aQCBQ3qP0_9iAENA Message-ID: Subject: Re: [PATCH v2 06/11] firmware: move loading timeout under struct firmware_fallback_config To: "Luis R. Rodriguez" Cc: Greg KH , Andrew Morton , Shuah Khan , Martin Fuzzey , Mimi Zohar , David Howells , pali.rohar@gmail.com, Takashi Iwai , arend.vanspriel@broadcom.com, =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , nbroeking@me.com, Vikram Mulukutla , stephen.boyd@linaro.org, Mark Brown , Dmitry Torokhov , David Woodhouse , Linus Torvalds , Abhay_Salunke@dell.com, bjorn.andersson@linaro.org, jewalt@lgsinnovations.com, LKML , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 23, 2018 at 6:46 PM, Luis R. Rodriguez wrote: > 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. > > Signed-off-by: Luis R. Rodriguez Acked-by: Kees Cook -Kees > --- > drivers/base/firmware_loader.c | 46 ++++++++++++++++++++++++++++++------------ > 1 file 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) > * > * @force_sysfs_fallback: force the sysfs fallback mechanism to be used > * as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y. > + * @old_timeout: for internal use > + * @loading_timeout: the timeout to wait for the fallback mechanism before > + * giving up, in seconds. > */ > struct firmware_fallback_config { > - bool force_sysfs_fallback; > + const bool force_sysfs_fallback; > + int old_timeout; > + int loading_timeout; > }; > > -static const struct firmware_fallback_config fw_fallback_config = { > +static struct firmware_fallback_config fw_fallback_config = { > .force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK), > + .loading_timeout = 60, > + .old_timeout = 60, > }; > > -static int old_timeout; > -static int loading_timeout = 60; /* In seconds */ > +/* These getters are vetted to use int properly */ > +static inline int __firmware_loading_timeout(void) > +{ > + return fw_fallback_config.loading_timeout; > +} > + > +/* These setters are vetted to use int properly */ > +static void __fw_fallback_set_timeout(int timeout) > +{ > + fw_fallback_config.loading_timeout = timeout; > +} > > static inline long firmware_loading_timeout(void) > { > - return loading_timeout > 0 ? loading_timeout * HZ : MAX_JIFFY_OFFSET; > + return __firmware_loading_timeout() > 0 ? > + __firmware_loading_timeout() * HZ : MAX_JIFFY_OFFSET; > } > > /* > @@ -291,14 +308,14 @@ static inline long firmware_loading_timeout(void) > */ > static void fw_fallback_set_cache_timeout(void) > { > - old_timeout = loading_timeout; > - loading_timeout = 10; > + fw_fallback_config.old_timeout = __firmware_loading_timeout(); > + __fw_fallback_set_timeout(10); > } > > /* Restores the timeout to the value last configured during normal operation */ > static void fw_fallback_set_default_timeout(void) > { > - loading_timeout = old_timeout; > + __fw_fallback_set_timeout(fw_fallback_config.old_timeout); > } > > 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) > static ssize_t timeout_show(struct class *class, struct class_attribute *attr, > char *buf) > { > - return sprintf(buf, "%d\n", loading_timeout); > + return sprintf(buf, "%d\n", __firmware_loading_timeout()); > } > > /** > @@ -696,9 +713,12 @@ static ssize_t timeout_show(struct class *class, struct class_attribute *attr, > static ssize_t timeout_store(struct class *class, struct class_attribute *attr, > const char *buf, size_t count) > { > - loading_timeout = simple_strtol(buf, NULL, 10); > - if (loading_timeout < 0) > - loading_timeout = 0; > + int tmp_loading_timeout = simple_strtol(buf, NULL, 10); > + > + if (tmp_loading_timeout < 0) > + tmp_loading_timeout = 0; > + > + __fw_fallback_set_timeout(tmp_loading_timeout); > > return count; > } > @@ -721,7 +741,7 @@ static int do_firmware_uevent(struct fw_sysfs *fw_sysfs, struct kobj_uevent_env > { > if (add_uevent_var(env, "FIRMWARE=%s", fw_sysfs->fw_priv->fw_name)) > return -ENOMEM; > - if (add_uevent_var(env, "TIMEOUT=%i", loading_timeout)) > + if (add_uevent_var(env, "TIMEOUT=%i", __firmware_loading_timeout())) > return -ENOMEM; > if (add_uevent_var(env, "ASYNC=%d", fw_sysfs->nowait)) > return -ENOMEM; > -- > 2.16.2 > -- Kees Cook Pixel Security