From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 5F232C433E0 for ; Wed, 3 Jun 2020 11:57:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41FF820678 for ; Wed, 3 Jun 2020 11:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726016AbgFCL5t (ORCPT ); Wed, 3 Jun 2020 07:57:49 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5781 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725855AbgFCL5s (ORCPT ); Wed, 3 Jun 2020 07:57:48 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8BD64301FB3ED8BC1805; Wed, 3 Jun 2020 19:57:45 +0800 (CST) Received: from [127.0.0.1] (10.166.215.205) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Wed, 3 Jun 2020 19:57:40 +0800 Subject: Re: [PATCH] cxl: Fix kobject memleak To: Andrew Donnellan , , , CC: , , , References: <20200602120733.5943-1-wanghai38@huawei.com> <72e2df75-b74b-cbd4-4cbe-c0f994d4c4f7@linux.ibm.com> From: "wanghai (M)" Message-ID: Date: Wed, 3 Jun 2020 19:57:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <72e2df75-b74b-cbd4-4cbe-c0f994d4c4f7@linux.ibm.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.166.215.205] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2020/6/3 19:33, Andrew Donnellan 写道: > On 2/6/20 10:07 pm, Wang Hai wrote: >> Currently the error return path from kobject_init_and_add() is not >> followed by a call to kobject_put() - which means we are leaking >> the kobject. >> >> Fix it by adding a call to kobject_put() in the error path of >> kobject_init_and_add(). >> >> Fixes: b087e6190ddc ("cxl: Export optional AFU configuration record >> in sysfs") >> Reported-by: Hulk Robot >> Signed-off-by: Wang Hai > > Thanks for the fix! > > I note that the err1 label returns without calling kfree(cr) and I > can't see a reason why we do that - so perhaps we should remove the > return statement in err1: so it falls through? > kfree(cr) can be called when kobject_put()-->kobject_release()-->kobject_cleanup()-->kobj_type->release() is called.  The kobj_type here is afu_config_record_type Thanks, Wang Hai From mboxrd@z Thu Jan 1 00:00:00 1970 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=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 07964C433E0 for ; Wed, 3 Jun 2020 12:16:39 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7624320772 for ; Wed, 3 Jun 2020 12:16:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7624320772 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49cSZC0XmJzDqbv for ; Wed, 3 Jun 2020 22:16:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=45.249.212.191; helo=huawei.com; envelope-from=wanghai38@huawei.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com X-Greylist: delayed 938 seconds by postgrey-1.36 at bilbo; Wed, 03 Jun 2020 22:13:33 AEST Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49cSVj2dvKzDqYJ for ; Wed, 3 Jun 2020 22:13:29 +1000 (AEST) Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8BD64301FB3ED8BC1805; Wed, 3 Jun 2020 19:57:45 +0800 (CST) Received: from [127.0.0.1] (10.166.215.205) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Wed, 3 Jun 2020 19:57:40 +0800 Subject: Re: [PATCH] cxl: Fix kobject memleak To: Andrew Donnellan , , , References: <20200602120733.5943-1-wanghai38@huawei.com> <72e2df75-b74b-cbd4-4cbe-c0f994d4c4f7@linux.ibm.com> From: "wanghai (M)" Message-ID: Date: Wed, 3 Jun 2020 19:57:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <72e2df75-b74b-cbd4-4cbe-c0f994d4c4f7@linux.ibm.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.166.215.205] X-CFilter-Loop: Reflected X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org, imunsie@au1.ibm.com, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 在 2020/6/3 19:33, Andrew Donnellan 写道: > On 2/6/20 10:07 pm, Wang Hai wrote: >> Currently the error return path from kobject_init_and_add() is not >> followed by a call to kobject_put() - which means we are leaking >> the kobject. >> >> Fix it by adding a call to kobject_put() in the error path of >> kobject_init_and_add(). >> >> Fixes: b087e6190ddc ("cxl: Export optional AFU configuration record >> in sysfs") >> Reported-by: Hulk Robot >> Signed-off-by: Wang Hai > > Thanks for the fix! > > I note that the err1 label returns without calling kfree(cr) and I > can't see a reason why we do that - so perhaps we should remove the > return statement in err1: so it falls through? > kfree(cr) can be called when kobject_put()-->kobject_release()-->kobject_cleanup()-->kobj_type->release() is called.  The kobj_type here is afu_config_record_type Thanks, Wang Hai