From patchwork Fri Jun 19 14:33:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 224218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D195C433E0 for ; Fri, 19 Jun 2020 14:50:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C84020DD4 for ; Fri, 19 Jun 2020 14:50:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578242; bh=KKLwxl/ZfJ4twlLSEGeuu76jQlodASbwQcAU9WHc2Cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=xzufcNzw3uQ5wWia8n4fy/hrMIiV/txxuRiG4ILE5+Urla7Cn1vIWZhIYA+AjMimK rZFBImlP4cNbVzffJ0p20h84x9hfxhV6X0KXXzoY3BeI2JwiGOM5R+IVXXly9RwFLA wWr9J2pD5jVhxQZ/DPpTUM8PJxRF3d1jI5GeWWuM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389334AbgFSOuj (ORCPT ); Fri, 19 Jun 2020 10:50:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389332AbgFSOui (ORCPT ); Fri, 19 Jun 2020 10:50:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C86A721548; Fri, 19 Jun 2020 14:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578238; bh=KKLwxl/ZfJ4twlLSEGeuu76jQlodASbwQcAU9WHc2Cg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V4F3Oi6YusfJJBtAqz6egDtQeOj7TJAd05oUqeqcHeXGtv467rAjGaTsIhuEULE55 LH7gymQ0SlGFopE4BKVEdznYcU1/Is0MlG/oiZLYwzjEPJ3qq2dsXIbyKUKclEPNJy HFnSIwS7L6FEemWNE/aMl3U53KSKgxGHF0tBf9DE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qiushi Wu , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 4.14 137/190] cpuidle: Fix three reference count leaks Date: Fri, 19 Jun 2020 16:33:02 +0200 Message-Id: <20200619141640.474078246@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141633.446429600@linuxfoundation.org> References: <20200619141633.446429600@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 ae948b1da93a..909bd2255978 100644 --- a/drivers/cpuidle/sysfs.c +++ b/drivers/cpuidle/sysfs.c @@ -414,7 +414,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; } kobject_uevent(&kobj->kobj, KOBJ_ADD); @@ -544,7 +544,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; } @@ -638,7 +638,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; }