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 7B8A5C433F5 for ; Tue, 15 Feb 2022 04:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231370AbiBOEW3 (ORCPT ); Mon, 14 Feb 2022 23:22:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230508AbiBOEW2 (ORCPT ); Mon, 14 Feb 2022 23:22:28 -0500 Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D19FA88B8; Mon, 14 Feb 2022 20:22:17 -0800 (PST) Received: from [192.168.12.102] (unknown [159.196.94.94]) by mail.codeconstruct.com.au (Postfix) with ESMTPSA id B2E712015A; Tue, 15 Feb 2022 12:22:14 +0800 (AWST) Message-ID: Subject: Re: [PATCH net-next v5 2/2] mctp i2c: MCTP I2C binding driver From: Matt Johnston To: Jakub Kicinski , Wolfram Sang Cc: "David S . Miller" , Jeremy Kerr , linux-i2c@vger.kernel.org, netdev@vger.kernel.org, Zev Weiss Date: Tue, 15 Feb 2022 12:22:14 +0800 In-Reply-To: <20220211143815.55fb29e3@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> References: <20220210063651.798007-1-matt@codeconstruct.com.au> <20220210063651.798007-3-matt@codeconstruct.com.au> <20220211143815.55fb29e3@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4-1ubuntu2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, 2022-02-11 at 14:38 -0800, Jakub Kicinski wrote: > > > +// Removes and unregisters a mctp-i2c netdev > > +static void mctp_i2c_free_netdev(struct mctp_i2c_dev *midev) > > > You're doing a lot before the unregister call, this is likely racy. > The usual flow is to unregister the netdev, then do uninit, then free. > For instance you purge the queue but someone may Tx afterwards. > needs_free_netdev is a footgun. Thanks Jakub. I've reworked it here to do the work before register/after unregister, without needs_free_netdev. One question, the tx thread calls netif_wake_queue() - is it safe to call that after unregister_netdev()? (before free_netdev) I've moved the kthread_stop() to the post-unregister cleanup. static int mctp_i2c_tx_thread(void *data) { struct mctp_i2c_dev *midev = data; struct sk_buff *skb; unsigned long flags; for (;;) { if (kthread_should_stop()) break; spin_lock_irqsave(&midev->tx_queue.lock, flags); skb = __skb_dequeue(&midev->tx_queue); if (netif_queue_stopped(midev->ndev)) netif_wake_queue(midev->ndev); // <------- spin_unlock_irqrestore(&midev->tx_queue.lock, flags); > > + INIT_LIST_HEAD(&mi_driver_state.clients); > > + mutex_init(&mi_driver_state.lock); > > I think there are static initializers for these. *nod* Thanks, Matt