Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp285185pxb; Wed, 8 Sep 2021 00:48:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUSmFiyroG4bZbDgfiNDYHo5nkRN3WAEoFK6Gqp+PxTMNVdkmZWMiRUF3vc8prQi4ZJX5E X-Received: by 2002:aa7:ce14:: with SMTP id d20mr2472713edv.132.1631087331170; Wed, 08 Sep 2021 00:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631087331; cv=none; d=google.com; s=arc-20160816; b=nB2lJd1hHqYym60P+l+PdViF5D9i1eeqhVw3QglWuOHWolAi6O//mNDeR3y4h7pF6y IWMvwNabV+GcFoi01vHLgEBRbd/xyfxBztNKzzn5aCUl8kiJHYduEJoS/Cw15uck1WdY 8A47aaRDbxnfYJ9nuo7+ZNGC7ac15pIMErB8b+mBomtlaa23WbGN2e7Vr/bobeIHHeDB 8xf5AHO1FSStFNNFyxouOzCLj0sPrtmxn23QcFkZ8E15I0WWc7v39Rd50QmRr0GsaCMi pM/f3uWMHV/3mGBD4PbMCaLXanMocqTCMMgcekRz3qQFTx8Giornz+Fa+GOFZJbrkPC3 nAkw== 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:subject :references:in-reply-to:message-id:cc:to:reply-to:from:date; bh=HLTYUeV6oSUUu10qVlBJ/4z5q0T1kB1sF9Bv6nrTaSw=; b=RgLtxGgK4h+9Kcv5/Rmyp/GGq9+mwhHH7vfR6LNoveqlAVJRX6NX4cF3UyOVroqMSr G2dD+TwnSQlSG+CtnvK1ePKsVb2YhW+iGE5+BPEss49ON1GMC85aDXJwb6FRyyQQvIkZ JXAXOR4fD3XrG9gf5Dm1sqW0m9ph1q6XEMOzbV1HcUgrL1BUmJZuhEAJessQ+8Jpo3N6 M9U/XJPIS75fVhYLiI5MqgDpJQH0N7F+oQCQCkNcBS47XTBYmMR7U1/YKUA9ymy1Lrmx 3CYaUAKA3Yd49Ny7/O9aZvKP1YLcVudT3FN7BuvBXQ+83ZIyo5paowH/VzJ26AuLjzZD WYvA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si1330512ejz.183.2021.09.08.00.48.28; Wed, 08 Sep 2021 00:48:51 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346068AbhIHGv3 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 8 Sep 2021 02:51:29 -0400 Received: from smtp09.smtpout.orange.fr ([80.12.242.131]:53993 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243186AbhIHGvX (ORCPT ); Wed, 8 Sep 2021 02:51:23 -0400 Received: from wwinf1e33 ([10.232.35.107]) by mwinf5d85 with ME id rJqE2500W2Jhpnu03JqE83; Wed, 08 Sep 2021 08:50:14 +0200 X-ME-Helo: wwinf1e33 X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Wed, 08 Sep 2021 08:50:14 +0200 X-ME-IP: 80.77.224.234 Date: Wed, 8 Sep 2021 08:50:14 +0200 (CEST) From: Marion et Christophe JAILLET Reply-To: Marion et Christophe JAILLET To: Dan Carpenter Cc: minyard@acm.org, zweiss@equinix.com, andrew@aj.id.au, openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Message-ID: <450800047.345.1631083814685.JavaMail.www@wwinf1e33> In-Reply-To: <20210908062719.GO1957@kadam> References: <20210908062719.GO1957@kadam> Subject: Re: [PATCH] ipmi: kcs_bmc: Fix a memory leak in the error handling path of 'kcs_bmc_serio_add_device()' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [80.77.224.234] X-WUM-FROM: |~| X-WUM-TO: |~| X-WUM-CC: |~||~||~||~||~||~| X-WUM-REPLYTO: |~| Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org   > Message du 08/09/21 08:28 > De : "Dan Carpenter" > A : "Christophe JAILLET" > Copie à : minyard@acm.org, zweiss@equinix.com, andrew@aj.id.au, openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org > Objet : Re: [PATCH] ipmi: kcs_bmc: Fix a memory leak in the error handling path of 'kcs_bmc_serio_add_device()' > > On Tue, Sep 07, 2021 at 11:06:32PM +0200, Christophe JAILLET wrote: > > In the unlikely event where 'devm_kzalloc()' fails and 'kzalloc()' > > succeeds, 'port' would be leaking. > > > > Test each allocation separately to avoid the leak. > > > > Fixes: 3a3d2f6a4c64 ("ipmi: kcs_bmc: Add serio adaptor") > > Signed-off-by: Christophe JAILLET > > --- > > drivers/char/ipmi/kcs_bmc_serio.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/char/ipmi/kcs_bmc_serio.c b/drivers/char/ipmi/kcs_bmc_serio.c > > index 7948cabde50b..7e2067628a6c 100644 > > --- a/drivers/char/ipmi/kcs_bmc_serio.c > > +++ b/drivers/char/ipmi/kcs_bmc_serio.c > > @@ -73,10 +73,12 @@ static int kcs_bmc_serio_add_device(struct kcs_bmc_device *kcs_bmc) > > struct serio *port; > > > > priv = devm_kzalloc(kcs_bmc->dev, sizeof(*priv), GFP_KERNEL); > > + if (!priv) > > + return -ENOMEM; > > > > /* Use kzalloc() as the allocation is cleaned up with kfree() via serio_unregister_port() */ > > The serio_unregister_port() calls serio_destroy_port() which calls > put_device(&serio->dev). But I wasn't able to track it further than > that to the actual kfree(). Hi Dan, Checking this release path was not the goal of this patch. It was only about the VERRYYYY unlikely memory leak. However my understanding is: kcs_bmc_serio_add_device --> serio_register_port --> __serio_register_port --> serio_init_port --> serio->dev.release = serio_release_port And in serio_release_port: struct serio *serio = to_serio_port(dev); kfree(serio); For me, this 'serio' looks to the one allocated by 'kcs_bmc_serio_add_device'. I think that the comment is correct. CJ > > Is there a trick to finding ->release() functions? > > regards, > dan carpenter > > >