From patchwork Mon Apr 3 01:31:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 13197634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 396AFC76196 for ; Mon, 3 Apr 2023 01:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbjDCBbf (ORCPT ); Sun, 2 Apr 2023 21:31:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjDCBbe (ORCPT ); Sun, 2 Apr 2023 21:31:34 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 403135BB6; Sun, 2 Apr 2023 18:31:33 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 0CBBD3200976; Sun, 2 Apr 2023 21:31:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sun, 02 Apr 2023 21:31:32 -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=fm3; t=1680485491; x= 1680571891; bh=vu5M9yMpN9Ov9B/2p2OZEU1hE+55vPvtCBpGCZL8hkw=; b=A XwQBcJcmi8a0ui0niLX3jNZbn+Rvb9Kq9Nd+KvOI4zPgFi6Z1u6SaeEXvRvmcu8S uUwwDhJPU9GDjiC9IFunUuIV58opsaahkKqG2z3e7vttkwOt1oRQLZpSxjL6VL7X y2tDiGZbnxc+3UX4GsjBGla9X2eD0W7e9rWyupgRJwW19rPD9YsgbDRX+lOz2R9S 8K3nwRaJ1AhcBilXvxhsslZP1MQCiV2XBiIZXsfuOATtvKp2aw2n3pwHBnBByyCE CYVXhWCagdoCOtPG1pztL9zIPefYqmsgPYR7jcoRHLnOqAetA9IyQ6dr3f9+TC3I IgSSlDP3uy686P3UwY/pw== 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=fm2; t=1680485491; x= 1680571891; bh=vu5M9yMpN9Ov9B/2p2OZEU1hE+55vPvtCBpGCZL8hkw=; b=u IAcb+n73tC4JPUY6bdmFy8v9FmWfFMWDzd1SzpY3DoCD/zqEPx+hjZnTn2uwhM7l Nri55HZYIhsYSX5ql5URF/y20eb97QyBIglpNztsd5rTPM5WEKrokG2TC5I2jALd cN3++e8HgCgLvMjng9bvfDmscTvt0ThXYjmH9FE7+wrtED20nlgoG0TeAmSbxWhj SIJEIjZPXZP6LAtoyOGjI1kbmS/7L6N8gGQ9io1y5iXht0UaqhMSL3tx02Oj1fkO syQbGa5QpR0NylQMh8ZalXp7bM2zMlf/fADfjsJ1SNM8upqjJwW8wq47As8BiPJE CrCdUYsPf5+ewnxdtT7vg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeiiedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgoteeftdduqddtudculdduhedmnecujfgurhephf fvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrrhhkucfrvggrrhhs ohhnuceomhhpvggrrhhsohhnqdhlvghnohhvohesshhquhgvsggsrdgtrgeqnecuggftrf grthhtvghrnhepvedtlefggefgjeettddvgfekhfeugfeutdekfeefudeuuddvieeutdel jedvhfdvnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmphgvrghrshhonhdqlhgvnhhovhho sehsqhhuvggssgdrtggr X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 2 Apr 2023 21:31:30 -0400 (EDT) From: Mark Pearson To: mpearson-lenovo@squebb.ca Cc: hdegoede@redhat.com, markgross@kernel.org, W_Armin@gmx.de, mirsad.todorovac@alu.unizg.hr, linux@weissschuh.net, Mario.Limonciello@amd.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Date: Sun, 2 Apr 2023 21:31:19 -0400 Message-Id: <20230403013120.2105-1-mpearson-lenovo@squebb.ca> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org My previous commit introduced a memory leak where the item allocated from tlmi_setting was not freed. This commit also renames it to avoid confusion with the similarly name variable in the same function. Fixes: 8a02d70679fc ("platform/x86: think-lmi: Add possible_values for ThinkStation") Reported-by: Mirsad Todorovac Link: https://lore.kernel.org/lkml/df26ff45-8933-f2b3-25f4-6ee51ccda7d8@gmx.de/T/ Signed-off-by: Mark Pearson --- This patch series builds on top of the proposed patch from Armin Wolf "platform/x86: think-lmi: Fix memory leak when showing current settings" Changes in v2: None, but rebased series because of issues with second patch. drivers/platform/x86/think-lmi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index 6034df6d577d..87f832142d8d 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -1459,10 +1459,10 @@ static int tlmi_analyze(void) * name string. * Try and pull that out if it's available. */ - char *item, *optstart, *optend; + char *optitem, *optstart, *optend; - if (!tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID)) { - optstart = strstr(item, "[Optional:"); + if (!tlmi_setting(setting->index, &optitem, LENOVO_BIOS_SETTING_GUID)) { + optstart = strstr(optitem, "[Optional:"); if (optstart) { optstart += strlen("[Optional:"); optend = strstr(optstart, "]"); @@ -1471,6 +1471,7 @@ static int tlmi_analyze(void) kstrndup(optstart, optend - optstart, GFP_KERNEL); } + kfree(optitem); } } /* From patchwork Mon Apr 3 01:31:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 13197635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D149FC76196 for ; Mon, 3 Apr 2023 01:31:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229459AbjDCBbi (ORCPT ); Sun, 2 Apr 2023 21:31:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbjDCBbg (ORCPT ); Sun, 2 Apr 2023 21:31:36 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1579410F5; Sun, 2 Apr 2023 18:31:35 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 04D7B320097D; Sun, 2 Apr 2023 21:31:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 02 Apr 2023 21:31:34 -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=fm3; t=1680485493; x= 1680571893; bh=GX5wswwc9ioI6tRN/FjlVtZp/Nq/YYWiACOgX926AhU=; b=k jvI/wcSLRN6fbepGKRvkXa2+d9zF6mRgCctN8I5PvW0abPl/v99Kc7W9zmhQiQn8 htgS1BnJecx2x4I2Aef98y45xPSwT42i68dTZ8BGVqiI60tZOBQpwyqN/HhB8OhU I7B9xgCpk1p1s1yZLOBx4uaNWub6U+R/+Ns75nT5oABdbYDu+FxJZ60Xc/bYB0I/ pvOLQr9rhfDC5MCdEjopQ5TfKoZ0miaVIqR8fWRpotpte7NXCHRJk/dKw5zmsxBy 9Uj7cv0xcl5i1ZoEB2kOlO7kcNL5zHQAA1qcGed8DhtiRLnsyOSgqsjxfZ2jCnDU 17Hz7kDrdwQBr5eWQAdXA== 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=fm2; t=1680485493; x= 1680571893; bh=GX5wswwc9ioI6tRN/FjlVtZp/Nq/YYWiACOgX926AhU=; b=N eadoCMTTS1OHj+Vfzz2utLNUDfg59wMkzdp0LD1oXdzCXuSzaMd5SZvqY8StZ8Ut lCCqvzzz9YJSy8SbGlsvehd8igxbTT+SVSHDnZsf+VylLPP59xXXvYgRQ2tZEolf 5EjB4cEj/XUPtp0drfWD1/AHCyzJVaZ4B9dmNEi/f3whnSjGh+jU6x0Cmgq8lYRN 3n+owPVVWKNQU3/Tpuu1ubTkWEbs6CygJMfnYE76nAI8HlQd322IsQR48g72BSRV tuN05HHpsVypBr3wVyT16czamhjR25lTYiP5EWrVej9L4EEAScjErNhQ/rLnl668 pLGCJ1mI2rCa7ZGL96e5A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeiiedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgoteeftdduqddtudculdduhedmnecujfgurhephf fvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepofgrrhhkucfrvggrrhhs ohhnuceomhhpvggrrhhsohhnqdhlvghnohhvohesshhquhgvsggsrdgtrgeqnecuggftrf grthhtvghrnhepkeefudeutedutdegheejhfdvieehjefhleefgfevtdeivdfhleehiedu feegffeknecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmphgvrghrshhonhdqlhgvnhhovhho sehsqhhuvggssgdrtggr X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 2 Apr 2023 21:31:32 -0400 (EDT) From: Mark Pearson To: mpearson-lenovo@squebb.ca Cc: hdegoede@redhat.com, markgross@kernel.org, W_Armin@gmx.de, mirsad.todorovac@alu.unizg.hr, linux@weissschuh.net, Mario.Limonciello@amd.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] platform/x86: think-lmi: Clean up display of current_value on Thinkstation Date: Sun, 2 Apr 2023 21:31:20 -0400 Message-Id: <20230403013120.2105-2-mpearson-lenovo@squebb.ca> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230403013120.2105-1-mpearson-lenovo@squebb.ca> References: <20230403013120.2105-1-mpearson-lenovo@squebb.ca> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org On ThinkStations on retrieving the attribute value the BIOS appends the possible values to the string. Clean up the display in the current_value_show function so the options part is not displayed. Fixes: a40cd7ef22fb ("platform/x86: think-lmi: Add WMI interface support on Lenovo platforms") Reported by Mario Limoncello Link: https://github.com/fwupd/fwupd/issues/5077#issuecomment-1488730526 Signed-off-by: Mark Pearson Tested-by: Mario Limonciello Tested-by: Mirsad Goran Todorovac --- Changes in v2: For some reason v2 doesn't apply cleanly so rebased and started again. Hopefully this one works drivers/platform/x86/think-lmi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index 87f832142d8d..78dc82bda4dd 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -920,7 +920,7 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj); - char *item, *value; + char *item, *value, *p; int ret; ret = tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID); @@ -931,9 +931,12 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a value = strpbrk(item, ","); if (!value || value == item || !strlen(value + 1)) ret = -EINVAL; - else + else { + /* On Workstations remove the Options part after the value */ + p = strchrnul(value, ';'); + *p = '\0'; ret = sysfs_emit(buf, "%s\n", value + 1); - + } kfree(item); return ret;