Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp13607741rwb; Sun, 27 Nov 2022 08:17:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf5C4fH/TMaOzctSV+F+o4O4FYJTv2RRbR7yWdmn6KVHArJ0ArzWr8rSFbEQoQo4WToSydv0 X-Received: by 2002:a50:fe0e:0:b0:46a:cb3b:d117 with SMTP id f14-20020a50fe0e000000b0046acb3bd117mr10616392edt.103.1669565866492; Sun, 27 Nov 2022 08:17:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669565866; cv=none; d=google.com; s=arc-20160816; b=Wr8gHq0FqQ3uTEEB0LUyce6JYyROYijzgcqECKKox2QY6ckU/9E4QYVyLmEF+JmhsL kyOHG+FEyzQY+IYzdFpuqkhvivD8IHpak5ZpZNzZ9ACVZ6V1yiTyOPIfvXhkmQVebUJv e9nufi9PTsSEdVL4ER/Pjm/eLTXItiw0Et8z+uWb+mEunP9grvzIDzP4wbMmU66Nasej TPWRWDakPsmfPnJoCuadgMHzat2HRWN4g1wJQR3YrNwjwqVq96pEHyQym1G9k/ftV0QT ROL1ox9hBgyOUES+jk6+nynDNeTvJAYV7GhQtyDChFWq3hdBB8T3AsYJ2Jm54gCIZ6BO NaVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=IH6zbXu8+LiztqnNpyxs/cBi+mW/NtvmP/bSIHwf/L4=; b=VsAN7O2wYg9GljufbgfDFZil1T3P+czF/9gN3wyW+HAaV0hMG5jGH0szbTwE/aO6+d O7PCPzeI8Ja7qmDQi8m0RPfWTTj5hOWNbPKH3dfLfJvNxV1uZZxenqjjoz5mTHtZDXA4 GCgpM2JoAE5Pi/wA9VgjdJnNzP6qtWNUV7IcuPOBvcn/1w057gx+ZMXrPIxtnGMqXL13 4fpQaGAbJEqH+DqcnE/oi4D6UYEZRsBjT9onf1rIEycMf+UdG0jaCXvdpa+ksg1jd1Dm rOXNfOlV1LdfpnJ+gBNmnxwczJ2voq0rGZxbvGCXEMuge5e8/zT0wQ08Skp8OD422z9S uZJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s27-20020a50ab1b000000b00461ea502defsi7804017edc.350.2022.11.27.08.17.24; Sun, 27 Nov 2022 08:17:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229615AbiK0PgU (ORCPT + 85 others); Sun, 27 Nov 2022 10:36:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbiK0PgS (ORCPT ); Sun, 27 Nov 2022 10:36:18 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 05B02DEB7 for ; Sun, 27 Nov 2022 07:36:16 -0800 (PST) Received: (qmail 294816 invoked by uid 1000); 27 Nov 2022 10:36:15 -0500 Date: Sun, 27 Nov 2022 10:36:15 -0500 From: Alan Stern To: Vincent MAILHOL Cc: Andrew Lunn , linux-can@vger.kernel.org, Marc Kleine-Budde , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , netdev@vger.kernel.org, linux-usb@vger.kernel.org, Saeed Mahameed , Jiri Pirko , Lukas Magel Subject: Re: [PATCH v4 2/6] can: etas_es58x: add devlink support Message-ID: References: <20221104073659.414147-1-mailhol.vincent@wanadoo.fr> <20221126162211.93322-1-mailhol.vincent@wanadoo.fr> <20221126162211.93322-3-mailhol.vincent@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 27, 2022 at 02:10:32PM +0900, Vincent MAILHOL wrote: > > Should devlink_free() be after usb_set_inftdata()? > > A look at > $ git grep -W "usb_set_intfdata(.*NULL)" > > shows that the two patterns (freeing before or after > usb_set_intfdata()) coexist. > > You are raising an important question here. usb_set_intfdata() does > not have documentation that freeing before it is risky. And the > documentation of usb_driver::disconnect says that: > "@disconnect: Called when the interface is no longer accessible, > usually because its device has been (or is being) disconnected > or the driver module is being unloaded." > Ref: https://elixir.bootlin.com/linux/v6.1-rc6/source/include/linux/usb.h#L1130 > > So the interface no longer being accessible makes me assume that the > order does not matter. If it indeed matters, then this is a foot gun > and there is some clean-up work waiting for us on many drivers. > > @Greg, any thoughts on whether or not the order of usb_set_intfdata() > and resource freeing matters or not? In fact, drivers don't have to call usb_set_intfdata(NULL) at all; the USB core does it for them after the ->disconnect() callback returns. But if a driver does make the call, it should be careful to ensure that the call happens _after_ the driver is finished using the interface-data pointer. For example, after all outstanding URBs have completed, if the completion handlers will need to call usb_get_intfdata(). Remember, the interface-data pointer is owned by the driver. Nothing else in the kernel uses it. So the driver merely has to be careful not to clear the pointer while it is still using it. Alan Stern