Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp107460ybg; Mon, 8 Jun 2020 17:48:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOP4A0AdbOElIPRysU9Z4XnJV+aHSMx1S61+4z2Eju1CWt+0oYFulVnVk6XoMBgL3Stin8 X-Received: by 2002:a17:906:3441:: with SMTP id d1mr22514682ejb.489.1591663683800; Mon, 08 Jun 2020 17:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663683; cv=none; d=google.com; s=arc-20160816; b=bamHnZIzVqHIoUBU3wcfDHXnjdQpcPytqJMR9/k7ZHKGb71914nbqZM4Nd27qf3W+E CpC8GcROfaiuekxze5Y5BYyDpZ/r64kOqJ/wQP6zyd+l3TfjK+YsDEWqlcACk5ZzlrOG dVq8lepWGmTOqq/yrWy3MyFaRVLd1QKjHpC6mpSGWwCK48G6cZTXkNLbPoQlJGHLMvYC NbUBGi5nu4UOL/qPE9axLqehA2sEi1aHQc12Eyg9Cb0wzFM3FmZ8Grz7EreyeqgV16h2 L9vD5zqiidTtZeyBQnI0qtYkSJZzgtWLs9J1L6pRTlECHVm2fc0TVvudJp6kOATI6wXR EIrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iROZ+F1AyBuGqXdzvB51GrxmZg1zsd96/S2A2tak90I=; b=QDlICy5FS0USAEC15lnTYN5zTMnzpX6/L+hSNqsBLvdTWUfzScvrVsjn87ntyjVsY/ 78kP1OO2rOoZ0EN+IV8aXAxmuPD4+z/oBXxter1oapHF/EzYL8jr9W1t0EIcxy5EcuP1 F0pio4tU2gYDxTvQ2RG2SOmGJ9yTGUX6arHRXWNYhO06+4WytRp626DycnwhpBX8Lpmz bSRAR8hxVyJLdUVoc2V8/7iqRwbU9+k2ol/NjL7z8iSFrOK4bcGRNiUHWNC2C4PHcmvz 7Sr/Tw6QjTGi1vNCw3EnSpRfh3Ip0YwSY9SCtpQEnqacuV02oMOaZihlXejTzYgMmvJR seig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nJZYs9AH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si3551271edn.106.2020.06.08.17.47.40; Mon, 08 Jun 2020 17:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nJZYs9AH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732292AbgFIAp6 (ORCPT + 99 others); Mon, 8 Jun 2020 20:45:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728234AbgFHXLo (ORCPT ); Mon, 8 Jun 2020 19:11:44 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3648D21508; Mon, 8 Jun 2020 23:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657903; bh=3RrjVjucjaQRqQ0XpzGPy0vis0dtQ3RxxAdXgJmrAC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nJZYs9AHcvtBqOZ/0evyRmorFpTprlg5EB1khVH8jcjf+InDEJUCWRnzCRNPIMCB2 +JHYBI2xMHDPNgrjU08S3odzdDSLWU5jym3aRwbC6Bpla/46ivNxNo+R1BeLlAZGwo ATPhWgygZm9NucV5o+h3AMTvg/UzOIRGJiLSoVYo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Qiushi Wu , "Rafael J . Wysocki" , Sasha Levin , linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 256/274] cpuidle: Fix three reference count leaks Date: Mon, 8 Jun 2020 19:05:49 -0400 Message-Id: <20200608230607.3361041-256-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qiushi Wu [ Upstream commit c343bf1ba5efcbf2266a1fe3baefec9cc82f867f ] kobject_init_and_add() takes reference even when it fails. If this function returns an error, kobject_put() must be called to properly clean up the memory associated with the object. Previous commit "b8eb718348b8" fixed a similar problem. Signed-off-by: Qiushi Wu [ rjw: Subject ] Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/cpuidle/sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c index cdeedbf02646..55107565b319 100644 --- a/drivers/cpuidle/sysfs.c +++ b/drivers/cpuidle/sysfs.c @@ -515,7 +515,7 @@ static int cpuidle_add_state_sysfs(struct cpuidle_device *device) ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &kdev->kobj, "state%d", i); if (ret) { - kfree(kobj); + kobject_put(&kobj->kobj); goto error_state; } cpuidle_add_s2idle_attr_group(kobj); @@ -646,7 +646,7 @@ static int cpuidle_add_driver_sysfs(struct cpuidle_device *dev) ret = kobject_init_and_add(&kdrv->kobj, &ktype_driver_cpuidle, &kdev->kobj, "driver"); if (ret) { - kfree(kdrv); + kobject_put(&kdrv->kobj); return ret; } @@ -740,7 +740,7 @@ int cpuidle_add_sysfs(struct cpuidle_device *dev) error = kobject_init_and_add(&kdev->kobj, &ktype_cpuidle, &cpu_dev->kobj, "cpuidle"); if (error) { - kfree(kdev); + kobject_put(&kdev->kobj); return error; } -- 2.25.1