From patchwork Fri Mar 31 21:33:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 77984 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp855591vqo; Fri, 31 Mar 2023 14:39:02 -0700 (PDT) X-Google-Smtp-Source: AKy350bRL66QU0wGgO9CLgRGl1DK1JjsVRs5mcuDkJ5YkTjUKobqJxB+QQiynp1m+kcO8UiXmX7f X-Received: by 2002:a05:6402:1115:b0:502:32b6:6e56 with SMTP id u21-20020a056402111500b0050232b66e56mr20622827edv.37.1680298742590; Fri, 31 Mar 2023 14:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680298742; cv=none; d=google.com; s=arc-20160816; b=NtEci6eT8qDke57b8bwWG7UeYzUKvCFitkX9R9Dax6Ghc1QeNUXKVXRFjA5lEDtq5K tmiLieNBTtODaoLZdL6H/NyRtbOSA7VF50ZmWVy4J5+WsOxK+zit1DUfNozCQYQQ6HjD etX7Uty7tiyWgNGjAb4UQ+VVNJA/JLldflvfKToesrAcHBQIuc1lEyh9Xc+Tb4nmdxt1 dgJig2FoUG1PdJ6oAYd23gZ4UwWMdgL+an4+HY/fqZLh06T8BFsoG/lnoYig1QEO1RyM JLtelnl8Rjgo5g5HHfSwNF4wvEzIoggCqZ6sDjjvgU7lBEu+UkZWhQbUiEDeDe2Uka9R 7J4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=SiPmV/NAJgIaOfwdtkJlsdwParobEow4900nzMjViso=; b=q7cei3kHpKoFEEUOfNDzbim4f0PgSmJAukT+d4MvLKWBC6TtxPeFwg5G03xfQ1gysN 8zgevhPj80JeS0JpCLaszyT5x0/rP0d4DC4H9OIgHaSvn02OsxA0bMvpfB3Vk412IgI6 gIpZepoMU2XzZIyXZWn1d4VsaSpE+dLSN3G+bIXjsAVwNBo4Q5o4AxUt7dHyvdCZ7SjJ 1ORrU9V+fxNoEE+domWQ8o00z5ycfaCOlCQjBVexo8hF8UdSvpwsCRQy66kIMj/mGqri MEtZtPu662OV0uv1H3UXCw4YUetQcgMLfO7TpG/Ashk0e/sFH1UXPT/Crf3yMfJ2/hjh vs9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=POPqArVS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020aa7df0f000000b00501d18f4652si2707196edy.501.2023.03.31.14.38.36; Fri, 31 Mar 2023 14:39:02 -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=@gmx.de header.s=s31663417 header.b=POPqArVS; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232891AbjCaVdj (ORCPT + 99 others); Fri, 31 Mar 2023 17:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjCaVdh (ORCPT ); Fri, 31 Mar 2023 17:33:37 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C5091BF7C; Fri, 31 Mar 2023 14:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1680298401; i=w_armin@gmx.de; bh=EBWPFpbCMT46T6rEenKWgprKQmJ4QU39rhCZdbZ7H2k=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=POPqArVSbsfbx7JzL1tW34DbQS+0zZGk7kT0FMHmyWu87oJyKOOSfuhyBhYB2Ee1M vpAKSE+Tqn3S4at6nE3A4JhLkwiMjHz5/LGvgv/51OpDwVuXb6YQetxWxxh5/XP9kM pfJkh1bUHsl331GnvOj8bK9fdRFRqjyYEzv4LC4rdJT5nc9jWt6Ed50TPzWuZyqptJ Ek0IKxWuzQbadnKr/EJ6wsiUhBJeRQdS1T4HtndczuBhq9sRuvDnRqaRmydLCV6kYH CE9noWONiaRVRhd3wX9E1kPkGku2E0EygPuJi4Op9N/5Fh/SogVehz6avuTBjqy3Yu pTPySEgRRAJ7A== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M2f9b-1pieI20msx-004AHM; Fri, 31 Mar 2023 23:33:21 +0200 From: Armin Wolf To: markpearson@lenovo.com, mirsad.todorovac@alu.unizg.hr Cc: hdegoede@redhat.com, markgross@kernel.org, thomas@t-8ch.de, gregkh@linuxfoundation.org, rafael@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] platform/x86: think-lmi: Fix memory leak when showing current settings Date: Fri, 31 Mar 2023 23:33:19 +0200 Message-Id: <20230331213319.41040-1-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Provags-ID: V03:K1:hVi4JZhY5ITHBCZ96XKgijEgPxTZgmr/KMgFg/ieta1PObiGlDn Ji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to4HSt3YLP/Fs9YQLtNzpMfd30R9mE4Y +YJs2bRrLtW7y4Hlkd2Z2A+1cUw77pdKY1iEVEzIpqZCkYnoIb3FxRPFZNXeCtzzItydZlLEx /MVuhHtd2JpYXz4Wm7mSvo8XmMM= X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761908102359129645?= X-GMAIL-MSGID: =?utf-8?q?1761920934273038560?= When retriving a item string with tlmi_setting(), the result has to be freed using kfree(). In current_value_show() however, malformed item strings are not freed, causing a memory leak. Fix this by eliminating the early return responsible for this. Reported-by: Mirsad Goran Todorovac Link: https://lore.kernel.org/platform-driver-x86/01e920bc-5882-ba0c-dd15-868bf0eca0b8@alu.unizg.hr/T/#t Tested-by: Mirsad Goran Todorovac Fixes: 0fdf10e5fc96 ("platform/x86: think-lmi: Split current_value to reflect only the value") Signed-off-by: Armin Wolf --- Changes in v3: - Fix Fixes: tag - Add Tested-by: tag Changes in v2: - Add Reported-by: and Link: tags --- drivers/platform/x86/think-lmi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.30.2 diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index cc66f7cbccf2..8cafb9d4016c 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -930,10 +930,12 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a /* validate and split from `item,value` -> `value` */ value = strpbrk(item, ","); if (!value || value == item || !strlen(value + 1)) - return -EINVAL; + ret = -EINVAL; + else + ret = sysfs_emit(buf, "%s\n", value + 1); - ret = sysfs_emit(buf, "%s\n", value + 1); kfree(item); + return ret; }