Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3938481pxb; Mon, 21 Feb 2022 08:41:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaQzvBBZvJdeThcbLZ+9ccF8nS/gNxiEfVdtPOiGeWNem7KG6SL1K5crUkbjiSXiNNaNJA X-Received: by 2002:a05:6402:908:b0:410:ef84:f6f1 with SMTP id g8-20020a056402090800b00410ef84f6f1mr21816054edz.34.1645461679739; Mon, 21 Feb 2022 08:41:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645461679; cv=none; d=google.com; s=arc-20160816; b=pl2IoVGY21otHTHPZrLowSVqTXC1Qi1e1zFEL0IhFfx8ZOxtAfyq3YqYK3hr4dNMV8 1ggGdj/XVeoUgAY20g2Y3E6Ts6OBqz8dxJURL0+3BgwvwOLflzuRgUQtHQ6yDGvJI94/ /H+h+8Dk4cSekCIaK8daCdqyQ8PP8tp750Rslj41IlLd+a+KVU0Ejx2MsxZoTcF+ah0b wLmQZasyyPje2h8uxboD9STz7ve5XXVQflWUX1grC/Zad8Np6aSL/GBwy9kWZrmP1L0c 6kOTB7F2YP/NDJUK7kfOQA6V0vFKYdZ3/2LrqKrxDBkZn6jajARM3cNLOnP4n1McGcoq 0Dhg== 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=wCXSZQZ+XLu9H/0amRx/wc+q2rIibjdt69QcGFGB4c4=; b=sLytWhrwaexwrLxlGPXWfxgR4z2LLHuec1I2iNioZOsD5z7eSBpZ3NoK+rdQCsN97z ohcv6745DuCjGKkX8kY0+WeDMttWCYGAjqYxwu4VxLUvE1t5bHgXSso1gXjeJ7aOKSC4 Q0IbiPDRDdy1kVo6ilK+rqjR6ExCW5CWYjPeIxsNqV5xLLiBjf5Aa55SgEAlm7+r4eT7 zJfC47wL0WEBAZrc6Itdo0kYI+KWYIQg/OlrX23iYvZjRpEYJXQajIHATgrEYMy9H9Hp 7AzzXNnwbbD6SNL9c8NsNHpdYGepkh3j8sI/NFqt9vVL748XVcqKyNKsD7cWa9Y0yZeb ALGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0Ok8n8v4; 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 g9si11745882edt.243.2022.02.21.08.40.55; Mon, 21 Feb 2022 08:41:19 -0800 (PST) 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=0Ok8n8v4; 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 S1349460AbiBUJMa (ORCPT + 99 others); Mon, 21 Feb 2022 04:12:30 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347773AbiBUJIe (ORCPT ); Mon, 21 Feb 2022 04:08:34 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 248FE3205A; Mon, 21 Feb 2022 01:00:21 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id D211EB80EB7; Mon, 21 Feb 2022 09:00:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EBE3C340E9; Mon, 21 Feb 2022 09:00:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645434018; bh=56qsthHrRBoFHqDWWpaeZQq+7/bpnQRvecrGixEmZW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0Ok8n8v4OZcI5ZyC1uDdTN1sVtlCyEgSIF3Gzq14lZEkyufP0ZhsL8i87vhfzP5xI fHyZPIw+/HKTuBe0I5hn/GV47drtWYWf0fQnL+zbhujm7g+vxPrfCHwFyAyWuP6YmD a5M6R301q3qh25DdiWTMJlZ9WRDLBxEL4LSIEHaA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaoqian Lin , Juan Vazquez , Wei Liu , Sasha Levin Subject: [PATCH 5.4 65/80] Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj Date: Mon, 21 Feb 2022 09:49:45 +0100 Message-Id: <20220221084917.715623302@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084915.554151737@linuxfoundation.org> References: <20220221084915.554151737@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 8bc69f86328e87a0ffa79438430cc82f3aa6a194 ] 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: c2e5df616e1a ("vmbus: add per-channel sysfs info") Signed-off-by: Miaoqian Lin Reviewed-by: Juan Vazquez Link: https://lore.kernel.org/r/20220203173008.43480-1-linmq006@gmail.com Signed-off-by: Wei Liu Signed-off-by: Sasha Levin --- drivers/hv/vmbus_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 2d2568dac2a66..6b7ab8f234e87 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1787,8 +1787,10 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) kobj->kset = dev->channels_kset; ret = kobject_init_and_add(kobj, &vmbus_chan_ktype, NULL, "%u", relid); - if (ret) + if (ret) { + kobject_put(kobj); return ret; + } ret = sysfs_create_group(kobj, &vmbus_chan_group); @@ -1797,6 +1799,7 @@ int vmbus_add_channel_kobj(struct hv_device *dev, struct vmbus_channel *channel) * The calling functions' error handling paths will cleanup the * empty channel directory. */ + kobject_put(kobj); dev_err(device, "Unable to set up channel sysfs files\n"); return ret; } -- 2.34.1