Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp661132pxb; Tue, 5 Apr 2022 17:44:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygBwVIxmkfhOMKhkuqOXY9krr6ZzbrZGkP6+1c2J9zSMIsidYdeYlPnNqRYG1lg3A/oobj X-Received: by 2002:a05:6402:2794:b0:419:2ea9:7de3 with SMTP id b20-20020a056402279400b004192ea97de3mr6203482ede.169.1649205883467; Tue, 05 Apr 2022 17:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649205883; cv=none; d=google.com; s=arc-20160816; b=qcfDqqv0UjHFNgH83zjRrVeB8A64RSIfkT4DMmtkTSlt2Stf0Yqn9Qq/mHn7lYb8kI OztpAoPs2474GX4kmCFOd3c9UsEhBV2Qm0AJ+/d/X43L+Xm4FG2WFPFj6JbK+lfxA900 eXT6Hq1PUZtWZIph/CGuDMHPxg466aEmEJso7U1MRJcvDSTF5JKpeVDSRhzCA9vF0Ljr zDfWgPopoTDcus6VPkxXACW7VDvMQt4SQ9RkmAnSNp3tYTmh0ktBYCk3lrDitsrlW7Kb y++uV8Dm32BehSo+mNx7jgIntH7rGzvUUfOr7eUYjttvr9vjIKRIba/kVHzavxdMuyOK mLdA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WzzEXOfU++eu6OE6/PVX6SrzQhl1QKssVJ75qHbfUKE=; b=PDbKu+SYKExmQlciXYqMNWmYawh6wIMaq7kKMLv4hP+CWkwHO864uuPh98yhaPppzi sbqPAalb/k4aa0NMVM4N0d0WcYFf1lkdug7rDuQuf7T3aMija2slwYsw+6S+PcG2Z1AL 9KBJjMas8Ew7To+JSoGRAwV4ThI/MATaDa516B09kfVSZZi1DKtthw5Hltle5vUMI9PY NomkhOwdaku1xbiC38dz8eLLSBtTbPSSFlKyBjVCNmV7z1MsWwI80dH1NveiXpWUFCuz h1A/nkjImd3EyYW+Uxd3DuP8TQpooKqAEBtzIWQdzaZ3QuvxMY5SjBo2II3rWu3yRqez /f0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jkKwSzOC; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n12-20020a05640205cc00b0041c80bb88e7si10877139edx.208.2022.04.05.17.44.17; Tue, 05 Apr 2022 17:44:43 -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=@linuxfoundation.org header.s=korg header.b=jkKwSzOC; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1385484AbiDEMdO (ORCPT + 99 others); Tue, 5 Apr 2022 08:33:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235347AbiDEJBf (ORCPT ); Tue, 5 Apr 2022 05:01:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC88E2671; Tue, 5 Apr 2022 01:53:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7955461511; Tue, 5 Apr 2022 08:53:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B0F2C385A1; Tue, 5 Apr 2022 08:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148826; bh=s0Xl/tDZ/nn9ljOEmMoDjIHW5BTj9WeUhGDK0Dd9ojI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jkKwSzOCEKUDWQOPlaPMe9x9I5IXsnmlwCaCaTY9T06PmX/7OYeovGDmNIXn6YjMM mai19Jgxlgzrg8MKomeU/QwicHG+xtU4LzMOFC/FQvPxd1inkh6dE2u3EbF21+AjJ9 +UMD7n+qt0AVnU3CId4A6o9gkQ+ikoK0g2ZKmCDg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaoqian Lin , Sebastian Reichel , Sasha Levin Subject: [PATCH 5.16 0495/1017] power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init Date: Tue, 5 Apr 2022 09:23:28 +0200 Message-Id: <20220405070408.992987017@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Miaoqian Lin [ Upstream commit 6a4760463dbc6b603690938c468839985189ce0a ] kobject_init_and_add() takes reference even when it fails. According to the doc of kobject_init_and_add(): If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Fix memory leak by calling kobject_put(). Fixes: 8c0984e5a753 ("power: move power supply drivers to power/supply") Signed-off-by: Miaoqian Lin Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/ab8500_fg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 05fe9724ba50..57799a8079d4 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -2545,8 +2545,10 @@ static int ab8500_fg_sysfs_init(struct ab8500_fg *di) ret = kobject_init_and_add(&di->fg_kobject, &ab8500_fg_ktype, NULL, "battery"); - if (ret < 0) + if (ret < 0) { + kobject_put(&di->fg_kobject); dev_err(di->dev, "failed to create sysfs entry\n"); + } return ret; } -- 2.34.1