Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752412AbdDIPQY (ORCPT ); Sun, 9 Apr 2017 11:16:24 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:46094 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752150AbdDIPQS (ORCPT ); Sun, 9 Apr 2017 11:16:18 -0400 Date: Sun, 9 Apr 2017 08:16:14 -0700 From: Guenter Roeck To: Mats Karrman Cc: Heikki Krogerus , Greg KH , Felipe Balbi , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: USB Type-C Port Manager API concern Message-ID: <20170409151614.GA23984@roeck-us.net> References: <20170221142405.76299-3-heikki.krogerus@linux.intel.com> <4b4bbffc-db02-3b54-04bc-e7de79b2d9ed@roeck-us.net> <07618170-d561-e7fe-08e0-91316c53d832@gmail.com> <20170303125940.GA6999@kuha.fi.intel.com> <6ddb2eac-03d5-127e-df1e-ad189968e6b2@gmail.com> <20170306131442.GC6999@kuha.fi.intel.com> <696552a7-c36a-1d73-9517-543907e9da39@gmail.com> <9b32fabf-3ff5-112f-4249-a7024f808b20@roeck-us.net> <4fe455d8-30d9-0c21-46aa-6d273cd24d50@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4fe455d8-30d9-0c21-46aa-6d273cd24d50@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2433 Lines: 58 Hi Mats, On Sun, Apr 09, 2017 at 01:09:57AM +0200, Mats Karrman wrote: > Hi Guenter, > > From a previous thread: > > On 03/08/2017 02:38 AM, Guenter Roeck wrote: > >On 03/07/2017 02:30 PM, Mats Karrman wrote: > >[ ... ] > > > >> > >>I'm still struggling to catch up on what you guys have been up to during > >>the > >>last year or so :-) and came across some patches of Guenter from last > >>October: > >> > >>http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1243527.html > >> > >>What happened to them? Has there been any progress since then? > >> > > > >Updates to keep in sync with API changes, bug fixes, and minor > >improvements, > >for the most part. I can post a current version if there is interest. > >The latest version is also available from > >https://chromium-review.googlesource.com/#/c/389917/ > > I'm working on a tcpi driver and have some concern about the tcpm api. > The tcpm_register_port() is typically called from the probe function of > tcpi driver where the tcpm_port reference returned is stored in the > driver private data. The problem I ran into is that tcpm_register_port() > calls back to the not yet fully initialized tcpi driver, causing null- > pointer dereferences. This could of course be solved by extra logic in > the tcpi driver but I think it would be more elegant if the registration > of a port could be free of premature callbacks. E.g. it could be required > that the tcpi driver probe called tcpm_tcpc_reset() once it's done > initializing or the necessary data could be supplied in the call to > tcpm_register_port(). > What do you think? Let me think about it. In theory it should be possible to avoid callbacks into the underlying driver until after the return from the registration code, but that would still be racy if the underlying driver is not ready. Basic problem seems to be that an API in general assumes that the caller is ready to serve it once it registers itself. It is kind of unusual to have two calls, one to register the driver and one to tell the infrastructure that it is ready (which I assume your reset call would do). Ultimately this means that the tcpm driver would have to have additional logic to identify if the underlying driver is ready to handle callbacks. Can you delay tcpm registration until after the underlying driver is ready, ie typically to the end of its probe function ? Or am I misunderstanding your problem ? Thanks, Guenter