Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1448678rwd; Thu, 25 May 2023 12:47:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54LXHb9H8P87ptZ9AMpQ9OYl2QqboCjoG1iFNax5Fgg0kQQJfV522365zSOYbUbOFcz6ep X-Received: by 2002:a05:6a00:811:b0:64f:74d9:eb4f with SMTP id m17-20020a056a00081100b0064f74d9eb4fmr9108306pfk.32.1685044055903; Thu, 25 May 2023 12:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685044055; cv=none; d=google.com; s=arc-20160816; b=jJclH5mj/dkb7NkUuRx2V0NlL2qFcsLEjxPO/s9H5k7Kmkh4QvCljkUcLJHt8LSsTP 5XdymGV8dTIn+LNGxaer8Qz4ztVDQ3CtJHWTMDBWJTUbfqZZPnsPu/DlKj7vAmF+T/wH aFZEDsoV57S3bOnEhsy7mHHCFGoWpX95s4LCRCI+664P82/df9q40W94f+lYd2vQSvHu md5rVoLXfd+B+NSE9Lw1Z1kq3AHTfZfqCjKJ/WnWRRVmRLxe1ClCjd/I3XlSPAqumyq1 231r+fpcwXRkmScKTfBk/5AIctIHEktNELX8K+AaQimOw3gAGDKDV/l3c4L+aWNoe35o CSXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=vRdhAijcr+SqqHZKB0865doAzp+2d040yLp8Fj5LvAw=; b=tgc+2e11Bs6ZQr0KD6mzJ7pvaeo0NinMvMsADWypAwzXdFPToq3JD1ZOog1kOt+/mY /dEW9aZZ9oyxvIpy25DmI6eRxidxmNeYV9XIyTW63Fz1qWdPetZBnqm8AC8aB7zySVmb /NkpmugmpkrBLZalXnaymknTZL/Sj4E3gw9JDmz6IedMQzla8RkyRoeUJAsInXNw80u9 9Vuc23zIPZjjIph4+kEhqCQMzU7lL4s04g/YRDm1Oe4vxZZfkZgdOiK7z5uiigA/VU8I ZGkq1zUZ4NvVIBvpHhUZjUZiMt+f5g2hmcR1giBzXVZCoHpMCfYrBqPUVy6sW45KTh11 04Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@squebb.ca header.s=fm2 header.b=K4p2qByt; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=AyaksA8v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020a637045000000b0053094305b52si1674284pgn.475.2023.05.25.12.47.21; Thu, 25 May 2023 12:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@squebb.ca header.s=fm2 header.b=K4p2qByt; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=AyaksA8v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241735AbjEYTff (ORCPT + 99 others); Thu, 25 May 2023 15:35:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241981AbjEYTfa (ORCPT ); Thu, 25 May 2023 15:35:30 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19539E4B; Thu, 25 May 2023 12:34:58 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C6B885C0084; Thu, 25 May 2023 15:31:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 25 May 2023 15:31:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=squebb.ca; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1685043098; x= 1685129498; bh=vRdhAijcr+SqqHZKB0865doAzp+2d040yLp8Fj5LvAw=; b=K 4p2qBytCnfrw9jS/FittH63a+5p7qQwL1tWyxf02Dg14PwIexBVaY/tiXdzRvKng owhxti7tNgDDgtJsKeZwzQgRUF2YRiNDrJ0AbYagLjMaGFwABu+LNq7p4O8ve65w IA2jwvzYR0hsZwdYsdTr8xIHVtQYeaKEacqafKqk1qHhq3JSnmKiYg+0MYcP7lsC cVrjg4/kXiK0EGmjXzw1X/TZTKgpo+X6JORtgwuOwzEn8SVTkY/kPMnop6gd5uGZ DaZ2p0BDpl++n2y9PAu+7XSKCo7D5BT5or8Abi7/SfY0KukMf+8lMLR9YJo3ceQb m1vlOFPxGjQqpjpU5mYLQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1685043098; x= 1685129498; bh=vRdhAijcr+SqqHZKB0865doAzp+2d040yLp8Fj5LvAw=; b=A yaksA8veTA8EfyiyF7jlwflHdz1QAFH/7EV4oM7ipG4cLNjE+Q4nFZR0yylo7e7F rNeD41gf9qZYfary7fUVjsMXgmaYHBc/jmqBJ1ZIoNCP//cOyGd1OV2J2QyvZMiO 6rFIHVOuBAGkFalIwpN6H0s9KdBvbPpuzqP2plb6A1hToFMNQvBOXrO/Cxw96FMv fQxXE0LFJY5SHXtIVlzJ+PzTK1zfIvhU8rk9Et7AgeTPpJke7/LcXyui5wX5V9cL NZ9ZPQG3iKDXhoFqe+cSciy46LwUP2FqHCHwnl8j4DY9F+/qoGDjqGXlk19kJv+d IYF6x0ikk4uK04Q5igWoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejjedgudefjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecuogetfedtuddqtdduucdludehmdenucfjughrpe fhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforghrkhcurfgvrghr shhonhcuoehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggrqeenucggtf frrghtthgvrhhnpeeftddvjeefleffvefhgfejjeehudetteeigeeugfekhffhgeejudeu teehgfdvffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggr X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 25 May 2023 15:31:38 -0400 (EDT) From: Mark Pearson To: mpearson-lenovo@squebb.ca Cc: hdegoede@redhat.com, markgross@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] platform/x86: think-lmi: mutex protection around multiple WMI calls Date: Thu, 25 May 2023 15:31:32 -0400 Message-Id: <20230525193132.3727-5-mpearson-lenovo@squebb.ca> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230525193132.3727-1-mpearson-lenovo@squebb.ca> References: <20230525193132.3727-1-mpearson-lenovo@squebb.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add mutex protection around cases where an operation needs multiple WMI calls - e.g. setting password. Signed-off-by: Mark Pearson --- Changes in V2: New commit added after review of other patches in series. drivers/platform/x86/think-lmi.c | 46 ++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index 64cd453d6e7d..f3e1e4dacba2 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -195,6 +196,7 @@ static const char * const level_options[] = { }; static struct think_lmi tlmi_priv; static struct class *fw_attr_class; +static DEFINE_MUTEX(tlmi_mutex); /* ------ Utility functions ------------*/ /* Strip out CR if one is present */ @@ -463,23 +465,32 @@ static ssize_t new_password_store(struct kobject *kobj, sprintf(pwd_type, "%s", setting->pwd_type); } + mutex_lock(&tlmi_mutex); ret = tlmi_opcode_setting("WmiOpcodePasswordType", pwd_type); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; - + } if (tlmi_priv.pwd_admin->valid) { ret = tlmi_opcode_setting("WmiOpcodePasswordAdmin", tlmi_priv.pwd_admin->password); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; + } } ret = tlmi_opcode_setting("WmiOpcodePasswordCurrent01", setting->password); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; + } ret = tlmi_opcode_setting("WmiOpcodePasswordNew01", new_pwd); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; + } ret = tlmi_simple_call(LENOVO_OPCODE_IF_GUID, "WmiOpcodePasswordSetUpdate;"); + mutex_unlock(&tlmi_mutex); } else { /* Format: 'PasswordType,CurrentPw,NewPw,Encoding,KbdLang;' */ auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s,%s,%s;", @@ -1000,11 +1011,16 @@ static ssize_t current_value_store(struct kobject *kobj, goto out; } + mutex_lock(&tlmi_mutex); ret = tlmi_simple_call(LENOVO_SET_BIOS_SETTING_CERT_GUID, set_str); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; + } ret = tlmi_simple_call(LENOVO_SAVE_BIOS_SETTING_CERT_GUID, tlmi_priv.pwd_admin->save_signature); + + mutex_unlock(&tlmi_mutex); if (ret) goto out; } else if (tlmi_priv.opcode_support) { @@ -1021,18 +1037,23 @@ static ssize_t current_value_store(struct kobject *kobj, goto out; } + mutex_lock(&tlmi_mutex); ret = tlmi_simple_call(LENOVO_SET_BIOS_SETTINGS_GUID, set_str); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; + } if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) { ret = tlmi_opcode_setting("WmiOpcodePasswordAdmin", tlmi_priv.pwd_admin->password); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; + } } - ret = tlmi_save_bios_settings(""); + mutex_unlock(&tlmi_mutex); } else { /* old non opcode based authentication method (deprecated)*/ if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0]) { auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;", @@ -1056,14 +1077,17 @@ static ssize_t current_value_store(struct kobject *kobj, goto out; } + mutex_lock(&tlmi_mutex); ret = tlmi_simple_call(LENOVO_SET_BIOS_SETTINGS_GUID, set_str); - if (ret) + if (ret) { + mutex_unlock(&tlmi_mutex); goto out; - + } if (auth_str) ret = tlmi_save_bios_settings(auth_str); else ret = tlmi_save_bios_settings(""); + mutex_unlock(&tlmi_mutex); } if (!ret && !tlmi_priv.pending_changes) { tlmi_priv.pending_changes = true; -- 2.40.1