From patchwork Mon Sep 25 14:28:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 144438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6359:6f87:b0:13f:353d:d1ed with SMTP id tl7csp1141717rwb; Mon, 25 Sep 2023 07:29:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaD+LCka3kss/D7M2qpoiguURRQyDOwKvL3F84D4mwHFvI/1LvIk1gS0jArqPaT5zRfZN5 X-Received: by 2002:a05:6a20:1448:b0:15e:707c:904 with SMTP id a8-20020a056a20144800b0015e707c0904mr4223765pzi.24.1695652138403; Mon, 25 Sep 2023 07:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695652138; cv=none; d=google.com; s=arc-20160816; b=spVPAVpvKgOdsDo/+mgoqcq6cooKtGXuFYtVA5zmUzHyav0ArdY98qtRnDnDlJ3qkb UFlDOGg9duq3Qwbkh3qYG+9uEMW19LqkFmHwmUDOzHkqnAY/JPebb8+DD7irOFKEmtk3 Eo8eRWC7vjyUy7FIwJtvChfPnVzHZucpynA88pZ2gaBqgPYDEtQR8UqjvC0MuoXZ/OV7 iPjjWn2Dp/uBkGi3cngTNj/nvZ+U9y76L32RbiqZQBbpatecPxNOE4FUnIq+nddujvpH B1NHetFcnzv02zTD6FVkmsqFhVr5v6f3ifpBKl1pCI84vKcWvWayEXjZ2zbr5HKirp92 PoQg== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9l5gvj2nE/UBYa0ZDlDsGhQ5t4iNJvDpin3dIkZqYBY=; fh=JUqgqE2sM0crfy+ZSl9xW59lCsTd2U6P1z7TM85l0wU=; b=zvgEMy762XaggAkARvB8rPGtwpa4hg1Zu8CIbtZVgque0QPnERu81Vw9JF3JsvudQ4 QGmoGfTV1ZLca5j1QWuWvJ3rfl7U/3LFsxvsAgV5fTUv0oYwTyE2S5UzdKHqhfpZw3mw HSt2z4QmGxGZ9esxRvjg0zciZ8ljvVQkcRYq2+iqm++95tiEkAHSfFy3TmtPORUbJIPy 0auTr/LmHGNrMY2Mv6AGWDKgQk69ukwHWMzlRIVtD5h735nHNmD7//OYjh1uDlex7W1d BUpt1PUHAWEBn4waaMMZRZD4ewKovGhRpiS099GxB/Eaw8bLMPyFI4ISbtyNULUO41U/ tXmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=jAhHtiLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q17-20020a637511000000b005779c97fae5si9982079pgc.480.2023.09.25.07.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 07:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=jAhHtiLe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 705DF81BECA5; Mon, 25 Sep 2023 07:28:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232354AbjIYO2x (ORCPT + 29 others); Mon, 25 Sep 2023 10:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232313AbjIYO2t (ORCPT ); Mon, 25 Sep 2023 10:28:49 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82369103; Mon, 25 Sep 2023 07:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695652105; x=1696256905; i=w_armin@gmx.de; bh=071gcdDLNBkCgiGL7swJLhOyDt5nxBTUzKca3uuN28I=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=jAhHtiLe0mXfe5UVvmsdPX9jfFWA1024EWDUdqqkw0pSUm8yjVOOCieVqQ0bVbpeCQxWXfh/wWD vJWW34+3v+huqyI6lr/SBmbXI4BqkylgPon3Yom3mheZN9CfV/hgKneP2SGrH6Sc/JRtXh7fcyV+2 MWMQBvnX64jVx3qbRqrhFRYZR3l7P0qNUWQHTTJjkVoy/CzAjLbeJpRyGE05wVZtKAZuUzX8R4gsa BUdb1qMSkJpBViOHTb7xvzfA3J5KxwTOsjkptpzU3RYSJ6v7QUnuLW0znml5oZlLIbyiDZoRCgpIB owkVmghaLFmTo58iZItYH63l++lY+HGRHagw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MDQiS-1qvGyF0ntG-00AVWy; Mon, 25 Sep 2023 16:28:25 +0200 From: Armin Wolf To: markpearson@lenovo.com, jorge.lopez2@hp.com Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] platform/x86: think-lmi: Fix reference leak Date: Mon, 25 Sep 2023 16:28:18 +0200 Message-Id: <20230925142819.74525-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925142819.74525-1-W_Armin@gmx.de> References: <20230925142819.74525-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xLW589ADbeBLaSbObW/IkKlsPjnKinoeWFHFlYP2yKvjOxeMix8 tdH0CEbnJayZjjm/mr1pbvi56B/IKWGdkBL5BFEnC/AXdXRYPJ+5RD/3ZOPl6yL6zBSoH8j /gaxh0qorTWzE4tcIPq0vFxexNWee0VdCBZxXZRqLZH4ZFehyciEgNXHtKuPnvVJOIvi1Xb rVLF8F0sHGINhq1/tWQ3g== UI-OutboundReport: notjunk:1;M01:P0:DBTTDir0fBc=;/3Xslu3UF0jR4+NVqaPx8Dqb8zZ dM/LHUyK+XDNJArl7D4LGGWhQSMPK5fmlnyOLvKebr5bB5RYYwAMPnwj3WWmYqt8eo2aptPdv OADuvWhgiPfJMrFkEM5kPGVFH+c3NGL1l5ZeDqdgCfgvfPY7J2sd2RtgEttKUBj/u9Av6rvRC PI//uiEe+L6noLQKtQrHoBUKEDLa0iNoWLX9ifU9nAXWUNpH353gfZg0LC/pTn3NZIyxz7iI1 GI4S2cQYzGBGvQg98V/HafMm+eKApFAU6JEZ1ZesBofM3rPTSF/5I+8r4DQR0i0VW6FdqAHP2 NoC5VY1iqNc+Qa2oR0N3zQi4waUlo6FirvH+srgYFSTdftDKqEZcwyOZKkZ8omOCeILHAFaNc N7gTp0TKtkg4TGB54RTZ+ADaRAJLFt1hTNjOR65qPBooOVSE0BaLHXqOL1rOhKC7Kle16hM13 rZDdwG+/oHr7XB70qSR976vLJDzNyeblZSuU98ZDBOz3EmMLIGw2N+Qo4J8as+QW5XXLQZjpZ usfk3s/QTaakbceoHgVMyAcl0CZS9F0zM5HxCBqXl5Gq+G6G+QLNEsi/PIFCI9QJZu8b0oTUW Aj2pEnpCS3jM9i1Lg4BzPH35veaAu8d0y9dJOnMF3bhE9vtiJYbVy9Tu9DHGICfOa9CjC94/S DoELJVzVirWfGz0SPYJpZllU08Q5G0c0YAvj3IIfnOrldFI9GLoMzgzo2eSuJ9Haric2+XpgD oFwVU09j3VX/B/7jp3p8c5mrGWUw82Gt0MYGZj3MUKi8v+jArQ40cURDmZgSylIprD5JNU9Aw GCvso72kenBUUCH86+hAk1carRvmtqJ+GKNWsPHhsiBaKy58QfUUDHDLRTvo1ko46tDXtjmfd m/NaysBnRVlII3X2qnjMwbQJZfG6a48QSnqBrtjvYEaNFdzVI3xtTToDG9S3oXm+Z5mc/xN7K XpF/lZpW0HeWYgQOuJkozTQ50rg= X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 07:28:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778020136635866163 X-GMAIL-MSGID: 1778020136635866163 If a duplicate attribute is found using kset_find_obj(), a reference to that attribute is returned which needs to be disposed accordingly using kobject_put(). Move the setting name validation into a separate function to allow for this change without having to duplicate the cleanup code for this setting. As a side note, a very similar bug was fixed in commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"), so it seems that the bug was copied from that driver. Compile-tested only. Fixes: 1bcad8e510b2 ("platform/x86: think-lmi: Fix issues with duplicate attributes") Reviewed-by: Mark Pearson Reviewed-by: Ilpo Järvinen Signed-off-by: Armin Wolf --- Changes in v4: - add another Reviewed-by Changes in v3: - add Reviewed-by Changes in v2: - no changes --- drivers/platform/x86/think-lmi.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c index 4be6f28d4600..3a396b763c49 100644 --- a/drivers/platform/x86/think-lmi.c +++ b/drivers/platform/x86/think-lmi.c @@ -1344,6 +1344,24 @@ static void tlmi_release_attr(void) kset_unregister(tlmi_priv.authentication_kset); } +static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name) +{ + struct kobject *duplicate; + + if (!strcmp(name, "Reserved")) + return -EINVAL; + + duplicate = kset_find_obj(attribute_kset, name); + if (duplicate) { + pr_debug("Duplicate attribute name found - %s\n", name); + /* kset_find_obj() returns a reference */ + kobject_put(duplicate); + return -EBUSY; + } + + return 0; +} + static int tlmi_sysfs_init(void) { int i, ret; @@ -1372,10 +1390,8 @@ static int tlmi_sysfs_init(void) continue; /* check for duplicate or reserved values */ - if (kset_find_obj(tlmi_priv.attribute_kset, tlmi_priv.setting[i]->display_name) || - !strcmp(tlmi_priv.setting[i]->display_name, "Reserved")) { - pr_debug("duplicate or reserved attribute name found - %s\n", - tlmi_priv.setting[i]->display_name); + if (tlmi_validate_setting_name(tlmi_priv.attribute_kset, + tlmi_priv.setting[i]->display_name) < 0) { kfree(tlmi_priv.setting[i]->possible_values); kfree(tlmi_priv.setting[i]); tlmi_priv.setting[i] = NULL; From patchwork Mon Sep 25 14:28:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 144446 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6359:6f87:b0:13f:353d:d1ed with SMTP id tl7csp1146423rwb; Mon, 25 Sep 2023 07:37:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQk++6UWN9ZBLyvVEd4yMTJ8ZYe84Q0ZBq2ZRNfW6d55gImR/lt+pHhaaVZahT1r9Y5eFV X-Received: by 2002:a17:902:e986:b0:1c6:1611:e540 with SMTP id f6-20020a170902e98600b001c61611e540mr3871926plb.25.1695652621554; Mon, 25 Sep 2023 07:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695652621; cv=none; d=google.com; s=arc-20160816; b=ugjHV7R43nIIbUPPOacgRR/NLEIlm3EKEQnt1C0WccTMWK7KGhtx8PJJNV72AC6yuC VvJlIbep4iKI0P52lDofshBwVJgEbiefIUj642uQF0TlHGravVDznVEzjlM70J0UOgoQ uWRncIh1P32J3hY8LEeyyM1eNVBVMx6rE+2H2zpIFOZzFNwTCTl1KROf4ZB/yH4NUWay 6u6Ue/48jHppDMdB7OGCTU2d30ad3KtDqzWSrK7It8iLb4BEU4BiBvylQi+yxBWF8Is0 HBr3Bp8PkGD9or0kcG0FU4SuNdQzCBUXSzOq2XXC/+lu9hteRsEJQJjDxMa4QZXue1/Y 7Fvw== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HoYq0bBomrl1ixvA0HHG8QwzeIfjYvkYDAC22J2uzWY=; fh=JUqgqE2sM0crfy+ZSl9xW59lCsTd2U6P1z7TM85l0wU=; b=vHqiHWy1oBlBis1EcPghXo65vJwdrBpXpZgEy16yxiSsjtLcwwP8vipPCu29CYHIeI 3Vl2l35buYUS4bQ/j0ka11Ctl8rH2pz5SD/epWTUXD2m37druOJAuMXscjOviyKA89W1 zW5TsmhfYh0pjdTNTkaAQTm2KkcrTqoxzzzoxYTtpGm9FjrVBi90I1XQLfn6TkL+vDNB W2TQmVqQvzNe9JZ6lGddtCQMZd2CY+X8HNCE/0JGh0oWSm8H1NiRSb3huzrP3h64sSw2 8jq71/MthWetlFhtUvwOWwwFL//CUPMYMpXzYahuqhYT6n4rXMacWOzcATWxNHft23TT IFjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=PneQQp95; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id u11-20020a170902e20b00b001c5bb1f0cccsi4850157plb.275.2023.09.25.07.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 07:37:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=PneQQp95; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id B9D0481BEC9F; Mon, 25 Sep 2023 07:29:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbjIYO24 (ORCPT + 29 others); Mon, 25 Sep 2023 10:28:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbjIYO2x (ORCPT ); Mon, 25 Sep 2023 10:28:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1864F115; Mon, 25 Sep 2023 07:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1695652108; x=1696256908; i=w_armin@gmx.de; bh=BSN1lAPim3C7cFgrpEJfQYsSVYTrivCGYVKBfhFk7K4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=PneQQp95etoJT0cI/lUkkdbdDS2YbbaG1CO9D7QV0IU4nO1BCrDhkP2O9AeU33OvgVzE5yyxwi8 1bwg/xrYFERdwtV7EZfpJJYDN5vEpR0lnBsX0OOf8a6CfWSErdgQSiClVwx2vcgt3wnNQo8goQ863 ZETctxIA3qNLjE3CXe0hFSY0Ouo8/+M/ietCGIR8s+A/6bSd3H7Bm+jRSc282HYz7UTSj2RLl0zvl q5zmFe850NJ8VCY7QEw0LQTAeLQbMZtoOnv3DvupJkoRAxwZxvr2iGoF7wn2OZUtb2I+jh2wGaEE8 3jClp/1av/tOUdef9Bp7Y4Elt+wxFQciQ7ig== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from mx-amd-b650.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N0G1n-1rYTU43x4B-00xLCm; Mon, 25 Sep 2023 16:28:28 +0200 From: Armin Wolf To: markpearson@lenovo.com, jorge.lopez2@hp.com Cc: hdegoede@redhat.com, markgross@kernel.org, ilpo.jarvinen@linux.intel.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] platform/x86: hp-bioscfg: Fix reference leak Date: Mon, 25 Sep 2023 16:28:19 +0200 Message-Id: <20230925142819.74525-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925142819.74525-1-W_Armin@gmx.de> References: <20230925142819.74525-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:QdZMaBWIEMhEI+i7SEL5ArqLK9URNCHAxIOTsXjqOlzpvSUz9km vbaY8ghXMed0iu5rxDL9ouEOMM/DLstv5fHVcBzhX99DFG8zQ8htGneYUeDh3wX30qDOfld 6SNS2P0BTwEySdtXy5x1JBGwCiuP5+qnjJh2Tc1sl/CBCmP3z/lo1HFGiVjIQfkc/CLx5ko D+W7QkBzPnX4hbEJshnOw== UI-OutboundReport: notjunk:1;M01:P0:fI+oM7hxZKA=;5hnQkW9m/NydIG2Vt70g4KBQKkv FyLbbdAuhWVox7ScpJWKA1qxOztjSJdp/rJJ35LdJNdmmNDM8nLBmIMoWfWr+weCoW+GY/S4m iN66ACs/WFF1Cl6aky+d4znv85uLnngAT3daGUdt1wlqK2RjLQNUtAPSKssrnR4ko3JEx8Qu1 fPyWkFgp5imCLCufw+UEsXjNc3U8SCB9TLKKmZ1LDBi52rgWGtHd1Q9DRV0Bj6ZiFlRujH+we ZZy3oVY3fO5ZmjP+A9KB93IL72a2Um9VuKP36Avs19c5HJlq/4iz6OkqS7yo5Wz0/CZGdIN4F BvnrZgzt4oJ0bVGtL6VmVAM4mV4VS0x+nhfWI+X29HOnaJrcfu26te8A3mYE1SL9Fzt575S/h 5ay65zostYwEUAwZqql6B6EZiBW4R1bsxMgqW3uDNssVnWsa4Cn/Fxz4PRAcIysUbw9cN0y60 vm9pulmIm6dLh1kX2her98qnNzXsLjssfT0TY37WVsbFUfsPD85LgpV37mMUKd7QnNpvHVMlF 2peef/UzrDs22ADUmbirADBmyOJrZHvKbHp0XBYU1idHE/zB545l6Kz8bALKnM/dbaBzVbDn0 tUZHaFo1q3lf3+MXuqwhrjX4si/yDtwZOGW7KCmZH9bqwKwXz8wNKziKAZj4XsudhlUZG2ZnG 0F95VyqhWFcU1d0e4hm1tBivz5+m69hRZ7+rfiWur9lgOin2e2fNWBOYAvrlX4RBczTfeEzjn ISa4PU6i4chLtQIu5t/ggviOLo/9qJFsF7ana2KbooAZQt4UXH5N8W8OCf9wC2jX+P402MdVW aSE3f3DTbTqJ0WzZvig+Zml8X5CVXD3OYRUxYCO6tieLonQVbSYZT9Qw1JP317crf77h+ijxt V5FpHxozIjLtXLYKhnbFJ6DBmn0dZvOLBv6rKJ9VSJ8RQeGyA7y48tiYc5oc4rqINEecY/U31 wsfviDSraNzts6wduymF+m3Le18= X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 25 Sep 2023 07:29:00 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778020643291205218 X-GMAIL-MSGID: 1778020643291205218 If a duplicate attribute is found using kset_find_obj(), a reference to that attribute is returned which needs to be disposed accordingly using kobject_put(). Use kobject_put() to dispose the duplicate attribute in such a case. As a side note, a very similar bug was fixed in commit 7295a996fdab ("platform/x86: dell-sysman: Fix reference leak"), so it seems that the bug was copied from that driver. Compile-tested only. Fixes: a34fc329b189 ("platform/x86: hp-bioscfg: bioscfg") Suggested-by: Ilpo Järvinen Reviewed-by: Ilpo Järvinen Signed-off-by: Armin Wolf Reviewed-by: Jorge Lopez --- Chnages in v4: - fix missing whitespace - add Reviewed-by Changes in v3: - no changes Changes in v2: - add patch --- drivers/platform/x86/hp/hp-bioscfg/bioscfg.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) -- 2.39.2 diff --git a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c index 8c4f9e12f018..5798b49ddaba 100644 --- a/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c +++ b/drivers/platform/x86/hp/hp-bioscfg/bioscfg.c @@ -659,7 +659,7 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type, const char *guid, int min_elements, int instance_id) { - struct kobject *attr_name_kobj; + struct kobject *attr_name_kobj, *duplicate; union acpi_object *elements; struct kset *temp_kset; @@ -704,8 +704,11 @@ static int hp_init_bios_package_attribute(enum hp_wmi_data_type attr_type, } /* All duplicate attributes found are ignored */ - if (kset_find_obj(temp_kset, str_value)) { + duplicate = kset_find_obj(temp_kset, str_value); + if (duplicate) { pr_debug("Duplicate attribute name found - %s\n", str_value); + /* kset_find_obj() returns a reference */ + kobject_put(duplicate); goto pack_attr_exit; } @@ -768,7 +771,7 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type, const char *guid, int min_elements, int instance_id) { - struct kobject *attr_name_kobj; + struct kobject *attr_name_kobj, *duplicate; struct kset *temp_kset; char str[MAX_BUFF_SIZE]; @@ -794,8 +797,11 @@ static int hp_init_bios_buffer_attribute(enum hp_wmi_data_type attr_type, temp_kset = bioscfg_drv.main_dir_kset; /* All duplicate attributes found are ignored */ - if (kset_find_obj(temp_kset, str)) { + duplicate = kset_find_obj(temp_kset, str); + if (duplicate) { pr_debug("Duplicate attribute name found - %s\n", str); + /* kset_find_obj() returns a reference */ + kobject_put(duplicate); goto buff_attr_exit; }