From patchwork Sat Apr 1 18:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 13197187 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 8D320C6FD1D for ; Sat, 1 Apr 2023 18:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbjDASoF (ORCPT ); Sat, 1 Apr 2023 14:44:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbjDASoD (ORCPT ); Sat, 1 Apr 2023 14:44:03 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85A857694; Sat, 1 Apr 2023 11:44:02 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6DF2F3200917; Sat, 1 Apr 2023 14:43:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 01 Apr 2023 14:44:00 -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=1680374639; x= 1680461039; bh=NzdlQHPf2ubVQgJ2HZpDAwS0DtAbvUSrLwWN7up3J78=; b=K ZmKcnlKnb0ftNbtcdgOmgHNqT8d/XGAe2faoivoB1BBEy55hWKpJQuJoxH31Alm+ xoRiATcwAFyAtjHFNqkw6o88CW/qvKOeqoqmzI0Rggdr3eeh++6oR2Lao+ZXT+v+ jlv8KNKTW3/RRSd8UvNQwFmKWKo+qGoWOi04orMKzfGTCLSE0JdbElBjQBsI8LIe NwFH+tr4Wt6jCNuBzoPrlzby4MKM5Ea7GRLKpw7dK7QHsqenOKslXVXQSJQYUaGw R7JsJtLdTLssjuLgf3P+uuLfAfbRpsV3PgpUchlrhi/vp7x5pxV5VO95CmysCU4t 8oNqCNzON6rEhz3xW89MA== 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=1680374639; x= 1680461039; bh=NzdlQHPf2ubVQgJ2HZpDAwS0DtAbvUSrLwWN7up3J78=; b=t 2fNE5E2ltcsimc1VKb+onhUveuswjjEQU7FjkEr25UdU6EqTYBBELWlhJjbUWl48 zgMEFep6KmlMU2afC8NyT6NzSs+AqMi5o/EEYJ0iypvs76sIv2y4grBveVCR/Pdl 3k85sYzGmEsNsD0UB0xWmxLz1xSgOrLM8dSwzHbn5upYx8HkPiUnOJA/pE2D0VJi cyI6swUtjJLzXpQOQAqRjGvu/Y+ktHBHILX6OLVQ+UbcLaE5+Qy9qje2ILxERvfw 3Jp+dfL20i2vx/ZifgC0X3lUOuiURBdM/gBPeVnQP+zblI4T/7iGPlYrzjWrrNAH uDYIidAjq8vseVdd+a36A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeifedguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecuogetfedtuddqtdduucdludehmdenucfjughrpe fhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforghrkhcurfgvrghr shhonhcuoehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggrqeenucggtf frrghtthgvrhhnpeevtdelgfeggfejtedtvdfgkefhuefguedtkeeffeduueduvdeiuedt leejvdfhvdenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhpvggrrhhsohhnqdhlvghnohhv ohesshhquhgvsggsrdgtrg X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 1 Apr 2023 14:43:57 -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 1/2] platform/x86: think-lmi: Fix memory leaks when parsing ThinkStation WMI strings Date: Sat, 1 Apr 2023 14:43:44 -0400 Message-Id: <20230401184345.208960-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" 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 88da7bcb6ce9..ad952b49617b 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 Sat Apr 1 18:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Pearson X-Patchwork-Id: 13197186 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 05FA4C76196 for ; Sat, 1 Apr 2023 18:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229830AbjDASoE (ORCPT ); Sat, 1 Apr 2023 14:44:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbjDASoD (ORCPT ); Sat, 1 Apr 2023 14:44:03 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8612076A2; Sat, 1 Apr 2023 11:44:02 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 701673200929; Sat, 1 Apr 2023 14:44:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 01 Apr 2023 14:44:02 -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=1680374641; x= 1680461041; bh=EgK3/TiL28np4Zgt5b+Y1BW3uvD4i1QZBW4nZflddTo=; b=k QlG/2aT3s3N+UkoOxW1j7vt1fNMnAgu7Pt8zM/HOM4cWHcmGsL6SNtZKo7wQBgEU birN6Gb9kDI0bgLK31lolyhU1UZVtKouLdV6rncBByUIydGJ28EEhrWEyQTTjWz0 glxH89hQ/Cwl4/sUWScMNhoZN3CaWI8uEj8GdzwSIDIgTvQMprpmA1E2iqy82bu+ nyUNng6kcB8RjTddFOgfpgSPF8DYJkcyMXEflUHkPnsmUl+kz+dMeyalNj1xwXme q/3dW2sCNpApPzDV6BCai9PBClIsubvLiL6L/rKxq/KVhUD4LWr5ECaMU4c31xKn ybPL1YS1CYySaTlRqcR8g== 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=1680374641; x= 1680461041; bh=EgK3/TiL28np4Zgt5b+Y1BW3uvD4i1QZBW4nZflddTo=; b=M AmzMeNOTkPgjPgbXr1AbBhOg1cHpu4AsuWlsUx58XwYKNoT8ktHqrBSfY4lRLlkp K23w3XAJ2m8xBgkNxMF8/xlPPDrhTZbHe2W9JGQD7CCVD33xwnzVNslWrskX2EpB vmWM7QQqaliZhy95aVAnAejPqO+f7z2ZOO+daF5ey+MK7/y48b82o/qUG2HvIGtx OYIlcrkf7wuqCH827NsYRjxzT93Myt/0Jb1UrrOYa2JiQ7PmcR0cVXsFf+gePM0w zVD2bAKNPf9Bw5Eh2lL4BxorFxOAIrhHHGaxxbFPDqY+myFUogjPkrCaKIP6Cm89 hnpkhegBGii2sjQut5Dhg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdeifedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecuogetfedtuddqtdduucdludehmdenucfjughrpe fhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforghrkhcurfgvrghr shhonhcuoehmphgvrghrshhonhdqlhgvnhhovhhosehsqhhuvggssgdrtggrqeenucggtf frrghtthgvrhhnpeekfeduueetuddtgeehjefhvdeiheejhfelfefgvedtiedvhfelheei udefgeffkeenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhpvggrrhhsohhnqdhlvghnohhv ohesshhquhgvsggsrdgtrg X-ME-Proxy: Feedback-ID: ibe194615:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 1 Apr 2023 14:44:00 -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 2/2] platform/x86: think-lmi: Clean up display of current_value on Thinkstation Date: Sat, 1 Apr 2023 14:43:45 -0400 Message-Id: <20230401184345.208960-2-mpearson-lenovo@squebb.ca> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230401184345.208960-1-mpearson-lenovo@squebb.ca> References: <20230401184345.208960-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 --- drivers/platform/x86/think-lmi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index ad952b49617b..29e94db03238 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,11 +931,13 @@ 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 - ret = sysfs_emit(buf, "%s\n", value + 1); - + 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; }