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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34096CDB465 for ; Thu, 19 Oct 2023 12:03:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235344AbjJSMDG (ORCPT ); Thu, 19 Oct 2023 08:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345641AbjJSMCt (ORCPT ); Thu, 19 Oct 2023 08:02:49 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05020D64; Thu, 19 Oct 2023 05:02:41 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R731e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0VuTwcF3_1697716956; Received: from 30.240.113.74(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0VuTwcF3_1697716956) by smtp.aliyun-inc.com; Thu, 19 Oct 2023 20:02:38 +0800 Message-ID: Date: Thu, 19 Oct 2023 20:02:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 3/4] drivers/perf: add DesignWare PCIe PMU driver Content-Language: en-US To: Yicong Yang , Jonathan Cameron Cc: yangyicong@hisilicon.com, chengyou@linux.alibaba.com, kaishen@linux.alibaba.com, helgaas@kernel.org, will@kernel.org, baolin.wang@linux.alibaba.com, robin.murphy@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, rdunlap@infradead.org, mark.rutland@arm.com, zhuo.song@linux.alibaba.com, renyu.zj@linux.alibaba.com References: <20231017013235.27831-1-xueshuai@linux.alibaba.com> <20231017013235.27831-4-xueshuai@linux.alibaba.com> <20231017103959.00006ec3@Huawei.com> <0704f9f6-1e9a-4587-b92f-c799b932b755@linux.alibaba.com> From: Shuai Xue In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On 2023/10/19 16:05, Yicong Yang wrote: > On 2023/10/18 11:33, Shuai Xue wrote: >> ... >> >>> >>>> + return PTR_ERR(dwc_pcie_pmu_dev); >>>> + } >>>> + >>>> + return 0; >>>> +} >>>> + >>>> +static void __exit dwc_pcie_pmu_exit(void) >>>> +{ >>>> + platform_device_unregister(dwc_pcie_pmu_dev); >>>> + platform_driver_unregister(&dwc_pcie_pmu_driver); >>>> + cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); >>>> + >>>> + if (dwc_pcie_pmu_notify) >>> >>> If you have something unusual like this a driver module_exit() it definitely >>> deserves a comment on why. I'm surprised by this as I'd expect the notifier >>> to be unregistered in the driver remove so not sure why this is here. >>> I've lost track of earlier discussions so if this was addressed then all >>> we need is a comment here for the next person to run into it! >> >> All replied above, I will unregistered the notifier by devm_add_action_or_reset(). >> >> I am curious about that what the difference between unregistered in module_exit() >> and remove()? >> > > From my understanding, if you register it in probe() then should undo it in remove(). > Otherwise you should register it in module_init(). Just make them coupled to make > sure cleanup the resources correctly. > > This driver is a bit different since device and driver are created in module_init() > so will works fine in most cases, because the device/driver removal will happens the > same time when unloading the module. However if manually unbind the driver and device > without unloading the module, we'll miss to unregister the notifier in the currently > implementation. > I see, thank you for your patient explanation. Thank you. Best Regards, Shuai