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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B4A0BC433FE for ; Thu, 20 Jan 2022 17:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=D1uieBs2AKFtwic66pNcAu0EDsEKPIBbKZvTuMML7wc=; b=nOMNnMUOOfj6Av ZnCvnG9HaFktAyPRy0JUKBfSci226k3fnke5RdJJ96MJazwJEYEEMvjryKlUgcxO2YcWnk24SZRAQ C8y7MCx8h5bT1PD6Is+hNorfrfc+YuJlWaCw95/MTmDZJXn/qb2zCT6hSMY1oRiK8MHAB01IdVe0h uO3+nmfckGk4XJl+7URxruaY/MGLTgoHwpSBCFi/Ei1fjezXGQiXUYCNVUCx+7lkfkL0x7wKM9FOd 9JPNypvRgDHb0V8TJRspbyqqgrKBaaTe/H+T2htAaWmtVN7Mbr6R66F1OOdHco1S2uBDYCnChbgGr Ale0LqU/MdxTUrG4lQ9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAbg2-00Cfja-S8; Thu, 20 Jan 2022 17:56:51 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAbfy-00CfhT-Py for linux-arm-kernel@lists.infradead.org; Thu, 20 Jan 2022 17:56:48 +0000 Received: by mail-pj1-x1032.google.com with SMTP id l16so6602311pjl.4 for ; Thu, 20 Jan 2022 09:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eQK5zVzqLI6klwHyZj/+smdOpWkvGx4b96oH7k78DVI=; b=h3qF4O7gvq4Ngmvx2/kjn9H6OS8Lau1YuC4M8nMdC4/En8aXI85M6NX9I4dtxPuOvR LNGI3s0xYtWiTsLZfVyvPffs9SGIdhwwhB08iHTgIbwdEKrOpN6nExX/Zskqq4UoQy3k 0f03014Xr2C6BvgmptvCARFJ9pal8Hm7K/4ilIj5aKBePIr+EzC6iQgAxhA9rthj6zmc YxyrQhJYlnF+K8UUOOi49dbDeQhGLo1Sw/G6XAhjUCofgEfj4fFt6xPZdx0LmQtijzzL +lcuDM95hzIzn4gLZ244o+UN20aYeZLYV5Vq0FHitFwHP7OmtX2iiCe/0wb5VIKGjXe+ 6J0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eQK5zVzqLI6klwHyZj/+smdOpWkvGx4b96oH7k78DVI=; b=vdmd8KjlUgGvZq28vrbxz7Wo0yAru6OpgXkDOrVFXIqh2E/nEl6/oN8rNyKCsTiBI/ qVMklTtG6F4u1D28uohFVfFK+9wzGq+zsyCvPFJeAr+sPv4x0HAg2dQtz5KzqFOlmsIN H8YAHEgxYiwcFQJZjaDD+GmAZexc7MGOLXxnTNHDlQ0hF62oysMZQo+Kq19TLIKvRcb3 osHjdojOkbKLcVh8slVF86wHjl820sQtIPgT7GRsxeTXpdA97PyMXIb+lnbgnupbHcs/ 41NKzrf3YVaYazGUKPE/MRvlvflGen4pPkbFjeYf5YS9BcnZSN9RYdLIhbcvT34eoZap 1D/w== X-Gm-Message-State: AOAM530LUlfu4pqqKBzu+l0nvZOpy1TxpqZW1NVnaqCIU/ufxJExjpEo bJo0y+XSiJyFUHAdlO5u0ewFzA== X-Google-Smtp-Source: ABdhPJwUKxMCYglR9XOpdXVnTtB/k9OqpDZEl+oS4hqc6RRWe0ciZkXLEvosyCk8upOLgBMKD0Y5YA== X-Received: by 2002:a17:90a:c08f:: with SMTP id o15mr2479838pjs.204.1642701405601; Thu, 20 Jan 2022 09:56:45 -0800 (PST) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id rj2sm9860364pjb.54.2022.01.20.09.56.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jan 2022 09:56:44 -0800 (PST) Date: Thu, 20 Jan 2022 10:56:42 -0700 From: Mathieu Poirier To: Miaoqian Lin Cc: Suzuki K Poulose , Mike Leach , Leo Yan , Alexander Shishkin , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] coresight: syscfg: Fix memleak on registration failure in cscfg_create_device Message-ID: <20220120175642.GB1338735@p14s> References: <20220110073100.15497-1-linmq006@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220110073100.15497-1-linmq006@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220120_095646_876192_DD81035D X-CRM114-Status: GOOD ( 19.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Good morning, On Mon, Jan 10, 2022 at 07:31:00AM +0000, Miaoqian Lin wrote: > device_register() calls device_initialize(), > according to doc of device_initialize: > > Use put_device() to give up your reference instead of freeing > * @dev directly once you have called this function. That is _if_ device_initialize() is called manually. In this instance @dev is registered with device_register() and unregistered with device_unregister(). The latter conforms to the comment you pointed out and calls put_device() as expected. Thanks, Mathieu > > To prevent potential memleak, use put_device() instead call kfree > directly. > > Signed-off-by: Miaoqian Lin > --- > drivers/hwtracing/coresight/coresight-syscfg.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c > index 43054568430f..007fa1c761a7 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c > @@ -764,7 +764,7 @@ struct device *cscfg_device(void) > /* Must have a release function or the kernel will complain on module unload */ > static void cscfg_dev_release(struct device *dev) > { > - kfree(cscfg_mgr); > + put_device(dev); > cscfg_mgr = NULL; > } > > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel