From 9b877aa2b16945f201ab7db97e2a1eda756aafa3 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 19 Dec 2024 12:27:51 +0100 Subject: [PATCH] systemd: Clean up availableMitigations() caching Don't put the cache onto the function object, that confuses the type checker. Make it an internal global variable instead. Fixes > pkg/systemd/hwinfo.jsx(133,39): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. (There is another instance of this error which the next commit will address). --- pkg/systemd/hwinfo.jsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/systemd/hwinfo.jsx b/pkg/systemd/hwinfo.jsx index 30196f0dc3d1..c32437ba5f42 100644 --- a/pkg/systemd/hwinfo.jsx +++ b/pkg/systemd/hwinfo.jsx @@ -125,9 +125,11 @@ const SystemInfo = ({ info, onSecurityClick }) => { ); }; +let cachedMitigations; + function availableMitigations() { - if (availableMitigations.cachedMitigations !== undefined) - return Promise.resolve(availableMitigations.cachedMitigations); + if (cachedMitigations !== undefined) + return Promise.resolve(cachedMitigations); /* nosmt */ const promises = [cockpit.spawn(["lscpu"], { environ: ["LC_ALL=C.UTF-8"], }), cockpit.file("/proc/cmdline").read()]; return Promise.all(promises).then(values => { @@ -146,12 +148,12 @@ function availableMitigations() { const nosmt_available = threads_per_core > 1 && (values[1].indexOf("nosmt=") === -1 || values[1].indexOf("nosmt=force") !== -1); const mitigations_match = values[1].match(/\bmitigations=(\S*)\b/); - availableMitigations.cachedMitigations = { + cachedMitigations = { available: nosmt_available, nosmt_enabled, mitigations_arg: mitigations_match ? mitigations_match[1] : undefined, }; - return availableMitigations.cachedMitigations; + return cachedMitigations; }); } @@ -172,7 +174,7 @@ const CPUSecurityMitigationsDialog = () => { options = ['set', 'nosmt']; } else { // this may either be an argument of its own, or part of mitigations= - const ma = availableMitigations.cachedMitigations.mitigations_arg; + const ma = cachedMitigations.mitigations_arg; if (ma && ma.indexOf("nosmt") >= 0) { const new_args = ma.split(',').filter(opt => opt != 'nosmt'); options = ['set', 'mitigations=' + new_args.join(',')];