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 B0867C433EF for ; Wed, 20 Apr 2022 10:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244785AbiDTKVE (ORCPT ); Wed, 20 Apr 2022 06:21:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbiDTKVD (ORCPT ); Wed, 20 Apr 2022 06:21:03 -0400 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D732B641B for ; Wed, 20 Apr 2022 03:18:16 -0700 (PDT) Received: from fsav113.sakura.ne.jp (fsav113.sakura.ne.jp [27.133.134.240]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 23KAHtls083375; Wed, 20 Apr 2022 19:17:55 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav113.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav113.sakura.ne.jp); Wed, 20 Apr 2022 19:17:55 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav113.sakura.ne.jp) Received: from [192.168.1.9] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 23KAHthu083371 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Wed, 20 Apr 2022 19:17:55 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Wed, 20 Apr 2022 19:17:53 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH] wwan_hwsim: Avoid flush_scheduled_work() usage Content-Language: en-US To: Loic Poulain Cc: Sergey Ryazanov , Johannes Berg , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Network Development References: <0bc6443a-dbac-70ab-bf99-9a439e35f3ef@I-love.SAKURA.ne.jp> From: Tetsuo Handa In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2022/04/20 18:53, Loic Poulain wrote: >> @@ -506,9 +507,15 @@ static int __init wwan_hwsim_init(void) >> if (wwan_hwsim_devsnum < 0 || wwan_hwsim_devsnum > 128) >> return -EINVAL; >> >> + wwan_wq = alloc_workqueue("wwan_wq", 0, 0); >> + if (!wwan_wq) >> + return -ENOMEM; >> + >> wwan_hwsim_class = class_create(THIS_MODULE, "wwan_hwsim"); >> - if (IS_ERR(wwan_hwsim_class)) >> + if (IS_ERR(wwan_hwsim_class)) { >> + destroy_workqueue(wwan_wq); >> return PTR_ERR(wwan_hwsim_class); >> + } >> >> wwan_hwsim_debugfs_topdir = debugfs_create_dir("wwan_hwsim", NULL); >> wwan_hwsim_debugfs_devcreate = >> @@ -524,6 +531,7 @@ static int __init wwan_hwsim_init(void) >> >> err_clean_devs: Do you want debugfs_remove(wwan_hwsim_debugfs_devcreate); here (as a separate patch)? >> wwan_hwsim_free_devs(); >> + destroy_workqueue(wwan_wq); >> debugfs_remove(wwan_hwsim_debugfs_topdir); >> class_destroy(wwan_hwsim_class); >> >> @@ -534,7 +542,7 @@ static void __exit wwan_hwsim_exit(void) >> { >> debugfs_remove(wwan_hwsim_debugfs_devcreate); /* Avoid new devs */ >> wwan_hwsim_free_devs(); >> - flush_scheduled_work(); /* Wait deletion works completion */ >> + destroy_workqueue(wwan_wq); /* Wait deletion works completion */ > > Wouldn't it be simpler to just remove the flush call. It Looks like > all ports have been removed at that point, and all works cancelled, > right? I guess that this flush_scheduled_work() is for waiting for schedule_work(&dev->del_work) from wwan_hwsim_debugfs_devdestroy_write(). That is, if wwan_hwsim_debugfs_devdestroy_write() already scheduled this work, wwan_hwsim_dev_del() from wwan_hwsim_dev_del_work() might be still in progress even after wwan_hwsim_dev_del() from wwan_hwsim_free_devs() from wwan_hwsim_exit() returned.