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 7A34FC55162 for ; Thu, 30 Jul 2026 16:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type: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=L+6btDPNM97WzMYH5D23AWn86cOtGDouehBPODye2wE=; b=YE/YQkZ6SuwQ4j9V6nhD4mmDG6 DLRMO9QmdKTSoxRqIr02n1sXJoanDRxI9hPHLJqTl41Er/0wcqt3v48dRBrXNxFyRHSqJGzz7xek4 qjNNEfB4xMoxQWuQOP6cDLuIXGDHEMuCzxSDiTHwal96IJLv+iux23DF+vYWOd66GYydccLDZfsoD lKCcj/pe4xDmIt1QnTOhtgCWivhKRmzkcAMvdaafYqeWWdh8sM/UvKBhtUP8L3zC0O+mgNP3EO0Vv 72BE9rmHJ91tyEoxgiZ1lSgEl5zfP5eOZcAiD02gdJISyFHAQLbc1I6VEBPmt0do/XB+lFjOUtl6V 1xb4kF0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wpTOp-0000000Axg4-0BDq; Thu, 30 Jul 2026 16:14:23 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wpTOl-0000000Axdm-2CTI for linux-arm-kernel@lists.infradead.org; Thu, 30 Jul 2026 16:14:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785428058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L+6btDPNM97WzMYH5D23AWn86cOtGDouehBPODye2wE=; b=VXYZ3VEKNDUFHo6RuungshOHBlZpwRGevAfEXH18VT4rgiRWGC+wvAritE3iRgf/v+wdMP Yi1BKb9DvAF5Wwmea8UZQgST/Fk7GtryKCdfSwd9Cb8jBFD6qLZRTW/0D2TDfwKYrf3sZt Hi9Aw9Onv6l5p8a9gW84Nu67gUENHLQ= Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-671-0FAwTXM5OHiO_aNVeaDDKw-1; Thu, 30 Jul 2026 12:14:14 -0400 X-MC-Unique: 0FAwTXM5OHiO_aNVeaDDKw-1 X-Mimecast-MFC-AGG-ID: 0FAwTXM5OHiO_aNVeaDDKw_1785428054 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-7f5b54da461so36723527b3.3 for ; Thu, 30 Jul 2026 09:14:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785428054; x=1786032854; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:content-type:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=L+6btDPNM97WzMYH5D23AWn86cOtGDouehBPODye2wE=; b=qBJpyB9q9XqGoh7+35yqP0C5aBNcHnroexwymn3ES0syw1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received: by 2002:a05:690c:c1e:b0:81d:bc5:4624 with SMTP id 00721157ae682-81fb8953397mr23680487b3.25.1785428053873; Thu, 30 Jul 2026 09:14:13 -0700 (PDT) X-Received: by 2002:a05:690c:c1e:b0:81d:bc5:4624 with SMTP id 00721157ae682-81fb8953397mr23680137b3.25.1785428053319; Thu, 30 Jul 2026 09:14:13 -0700 (PDT) Received: from redhat.com (c-73-183-53-213.hsd1.pa.comcast.net. [73.183.53.213]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fb8abd480sm12784947b3.36.2026.07.30.09.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 09:14:12 -0700 (PDT) Date: Thu, 30 Jul 2026 12:14:10 -0400 From: Brian Masney To: Akari Tsuyukusa Cc: Michael Turquette , Stephen Boyd , Matthias Brugger , AngeloGioacchino Del Regno , "open list:COMMON CLK FRAMEWORK" , "open list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" , stable@vger.kernel.org, Chen-Yu Tsai , Miles Chen Subject: Re: [PATCH v2 5/6] clk: mediatek: mt8173: fix memory leak on module removal Message-ID: References: <20260707074839.240676-1-akkun11.open@gmail.com> <20260707074839.240676-6-akkun11.open@gmail.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.4.0 (2026-06-19) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: pLXBXxOQBufnP5gdjeK_ObwrPye1hjtk4hGqR9Canq0_1785428054 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260730_091421_001052_40D44BD7 X-CRM114-Status: GOOD ( 30.88 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Akari, On Wed, Jul 29, 2026 at 02:02:59AM +0900, Akari Tsuyukusa wrote: > On Tue, Jul 28, 2026 at 10:53:00AM -0400, Brian Masney wrote: > > On Tue, Jul 07, 2026 at 04:48:34PM +0900, Akari Tsuyukusa wrote: > > > clk-mt8173-apmixedsys.c and clk-mt8173-infracfg.c do not call > > > platform_set_drvdata() during their driver probe callback, > > > but their remove callback calls platform_get_drvdata(). > > > This results in platform_get_drvdata() returning NULL, > > > which leads to calling kfree(NULL) in mtk_free_clk_data(NULL). > > > This leaves clk_data unreleased, causing a memory leak. > > > > > > Fix this by calling platform_set_drvdata() during probe. > > > > > > Fixes: 4c02c9af3cb9 ("clk: mediatek: mt8173: Break down clock drivers and allow module build") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Akari Tsuyukusa > > > --- > > > drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 ++ > > > drivers/clk/mediatek/clk-mt8173-infracfg.c | 2 ++ > > > 2 files changed, 4 insertions(+) > > > > > > diff --git a/drivers/clk/mediatek/clk-mt8173-apmixedsys.c b/drivers/clk/mediatek/clk-mt8173-apmixedsys.c > > > index d7d416172ab3..65dc4489a09c 100644 > > > --- a/drivers/clk/mediatek/clk-mt8173-apmixedsys.c > > > +++ b/drivers/clk/mediatek/clk-mt8173-apmixedsys.c > > > @@ -179,6 +179,8 @@ static int clk_mt8173_apmixed_probe(struct platform_device *pdev) > > > if (r) > > > goto unregister_ref2usb; > > > > > > + platform_set_drvdata(pdev, clk_data); > > > + > > > return 0; > > > > > > unregister_ref2usb: > > > diff --git a/drivers/clk/mediatek/clk-mt8173-infracfg.c b/drivers/clk/mediatek/clk-mt8173-infracfg.c > > > index fa2d1d557e04..8b69009e1965 100644 > > > --- a/drivers/clk/mediatek/clk-mt8173-infracfg.c > > > +++ b/drivers/clk/mediatek/clk-mt8173-infracfg.c > > > @@ -128,6 +128,8 @@ static int clk_mt8173_infracfg_probe(struct platform_device *pdev) > > > if (r) > > > goto unregister_clk_hw; > > > > > > + platform_set_drvdata(pdev, clk_data); > > > + > > > > This patch doesn't compile. > > > > drivers/clk/mediatek/clk-mt8173-infracfg.c: In function ‘clk_mt8173_infracfg_probe’: > > drivers/clk/mediatek/clk-mt8173-infracfg.c:131:36: error: ‘clk_data’ undeclared (first use in this function); did you mean ‘clk_gate’? > > Sorry for sending you a broken patch. > I accidentally built only with ARCH=arm and missed the build failure. > > While fixing this, I noticed that clk-mt8173-infracfg.c can be converted > to use mtk_clk_simple_probe()/remove() instead of adding driver-specific > drvdata handling. > > The helper currently lacks cpumux support, but I have a reviewed patch > for it: > https://lore.kernel.org/lkml/20260304181024.738391-2-akkun11.open@gmail.com/ > (Reviewed-by: Chen-Yu Tsai ) > > Also, adding PLL support to the helper should allow more MediaTek clock > drivers to use the common probe/remove path: > https://github.com/TeamYogaBlade2/linux/commit/d991a61887ab76fd83708dffe8e48192e01023d5 > > Would it be preferable to extend mtk_clk_simple_probe()/remove() with > cpumux and PLL support and reorganize this series around it? Yes, that sounds good. Brian