Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp769pxb; Mon, 31 Jan 2022 03:46:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHTaaBkdda10fy6PiDgypQRCUV2pg+pY0a1BFIThohAuzg+I2NdwLpAQh1Q5tju3CVo+qp X-Received: by 2002:a05:6a00:140d:: with SMTP id l13mr19666777pfu.22.1643629563597; Mon, 31 Jan 2022 03:46:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643629563; cv=none; d=google.com; s=arc-20160816; b=NV4kabUJWk9bKCLv5jkSr2ko62yN26so8865+72tzzj5PBE7j/aTKXFm/JNd4jxHqR 1TeCZyrnqS4FLK4fiqjd1bHTex6nslQprn9ny230HZ/t6++UDF12J8EERWDY5UvB71Fj mk41bCzGqnGt0Z9ZAhxGFzfDQjd20a+4vWfSQeSzeBN2dW1OoHD1Bv8ou6Q3YQl7YdIm dNeqC3nc4C64WluSuathO1ikWPa4D+tBpb+zbJTi/9OKAkX8ibW/8m0kpFGAqmeaxzoj ns/+STxciNn+fHbkJtP3wWC8Wkb/kXMYne0JYGAF1qEeFEy9LbzUjvxufxUU/tSpz8is DQDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-filter; bh=9JajQ2cBB5tapkpmhdqs1zZw1ZE4vcEc/n6fplQCYFQ=; b=W7MONzGl9Q6om+kg1ZOMg0xB3adxnExgqICY4Mk9IE3uL/D6UCEktCqT0Gm1+YScvr msbDTi1h3IaxV+31w/5yg/QtO6vIV9rlZ2dBki/uu00ws9zOtXS5hM0qRYSlxmiGonE4 HkfMMyGbzY0ASucSoup0MdQ9e8/FXdpi8Z/46jGiASvhR4gUl6fDGnwtzRa0Dd5f9KEc cZn6f80aOv+fcT80Mxq+9qISAitmxj6SwAwpoLv3IUrCT5hnLZO4psrRiNkXF8zoHu09 Ja7gqeJnHNmz1XmcHKYphYM9aX4JgFakgXLeiqSWtDxEqTBzWmMbWrCbihyDAisuhMyn EOYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Hiu0PF/M"; 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=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i9si12959618plr.235.2022.01.31.03.45.44; Mon, 31 Jan 2022 03:46:03 -0800 (PST) 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=@linux.microsoft.com header.s=default header.b="Hiu0PF/M"; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351671AbiA1V4J (ORCPT + 99 others); Fri, 28 Jan 2022 16:56:09 -0500 Received: from linux.microsoft.com ([13.77.154.182]:39418 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235428AbiA1V4I (ORCPT ); Fri, 28 Jan 2022 16:56:08 -0500 Received: from surface (unknown [174.127.243.168]) by linux.microsoft.com (Postfix) with ESMTPSA id 582CB20B6C61; Fri, 28 Jan 2022 13:56:08 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 582CB20B6C61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1643406968; bh=9JajQ2cBB5tapkpmhdqs1zZw1ZE4vcEc/n6fplQCYFQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Hiu0PF/MX8BJZLEC/B7FeSL0l8z7DjmO9m/BWsOiWAyrczXlJKEvpZYFY6dK3VvfT 0bV1rgImlH83GTHD4xjMSu0USVhT07qltqji91Obuy44IR1DNg73SpJpM5eZ6gfua9 2MdVYAB07s8L0LpiQdTCq4DF6+qRhax9Laz/pIrk= Date: Fri, 28 Jan 2022 13:56:04 -0800 From: Juan Vazquez To: Miaoqian Lin Cc: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Greg Kroah-Hartman , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj Message-ID: <20220128215604.xuqdpnnn4yjqfaoy@surface> References: <20220126055247.8125-1-linmq006@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220126055247.8125-1-linmq006@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 26, 2022 at 05:52:46AM +0000, Miaoqian Lin wrote: > 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 > --- > drivers/hv/vmbus_drv.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c > index 17bf55fe3169..9e055697783b 100644 > --- a/drivers/hv/vmbus_drv.c > +++ b/drivers/hv/vmbus_drv.c > @@ -2028,8 +2028,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); If sysfs_create_group() fails same cleanup I think is required. Later kobject_uevent() may fail according to doc, but there is no error handling, maybe a good moment to consider adding it and do same cleanup. > > -- > 2.17.1