Received: by 10.192.165.148 with SMTP id m20csp4396365imm; Tue, 24 Apr 2018 01:55:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx49oYQqfdWOe303Qg8P3F/00zcOKwV27abz0QzpkgmAEfHC2RQ/xjNZBOcqOkr1RMF7pkmys X-Received: by 2002:a17:902:7c0f:: with SMTP id x15-v6mr23879750pll.369.1524560126247; Tue, 24 Apr 2018 01:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524560126; cv=none; d=google.com; s=arc-20160816; b=wsknii/M34D0J1nMokH2gT845UPjkITFHs+lGkCVfJIDASUa4jRQ+frc2rDFH8T6ad uw5U/hBJ6zVXB0KWKiAbn5Txb4Y38lN412VfAEGgU5BO5nhTZcRYq/AS4B373dJkjlZP lRwCIpvpxrA7nEfly12hlZgMEtyGMe+WBcS7LllRLQYeHxHlGS9zXkeXwqnT7+VksdYo oExSnFHkHTHynKci/pA7j/pRl6A/ZwAzAX1KlfMAJBg0i5MEPAkG0ri9QsuoZf7WRBsA o0j9wD3q5h1AUqvSu8Gnu6U6yDgqPHwVLletFuKrtGIzAoLQTlHjBd/DcaCDAB3rri/d 2Qdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=MCAiPDfrbbshGJCwnVeycd89I/DXaRfdDMHUxYLtVPg=; b=wL0l4H3nMSe1np5m+5bmSOBVUNcpC0Vg+mz75sm6x2N6UG6yFxYNGNTVshuzVpsAsg MMBGN2ef4QLvgEJjzBMliqfqTpIOt2vhAyzUXjJrHrzNDUcNH56Uev8D09so1vVBbO4M 2icKp40mKDe6mJE6xhxB10W23mJqdfpyEgl0eHI3AwCvox9oBXgaIs4abbK4+quRgYra UzDGaQaj8hSFCzhRbGwIIanPN6TArJmIVGPWQ4ryc0Amjk068QZAkodHD+UjTuuzaXXt EknrWDqy6PkgQpEGkGkviZwjoQ+lMM1T60VSkkKQgn/REyvtxYq4zGErbOixI8X1rkch Svkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=YDWcwTaZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si11447503pgc.381.2018.04.24.01.55.11; Tue, 24 Apr 2018 01:55:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=YDWcwTaZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756553AbeDXII6 (ORCPT + 99 others); Tue, 24 Apr 2018 04:08:58 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:50758 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756046AbeDXIIq (ORCPT ); Tue, 24 Apr 2018 04:08:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MCAiPDfrbbshGJCwnVeycd89I/DXaRfdDMHUxYLtVPg=; b=YDWcwTaZ7tzMKRUFI/XFwrnMS mNI6I5e1yV2qGSG7u8dopH1J6oxuyeuQTQEfB9i7m8mMZOZOUshfmXeAz6cPsFXB1FqaXBxd5gNyw MUiO5Ehl9pXBlJ0O5m0Fuz546iFV/plArdjaYgAHvPLVDNfOTC0XdKCzgNpMMPCuPm5D0=; Received: from n2100.armlinux.org.uk ([fd8f:7570:feb6:1:214:fdff:fe10:4f86]:32857) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1fAt09-0001RM-CR; Tue, 24 Apr 2018 09:08:37 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1fAt06-0002re-Hl; Tue, 24 Apr 2018 09:08:34 +0100 Date: Tue, 24 Apr 2018 09:08:33 +0100 From: Russell King - ARM Linux To: Peter Rosin Cc: linux-kernel@vger.kernel.org, David Airlie , Rob Herring , Mark Rutland , Nicolas Ferre , Alexandre Belloni , Boris Brezillon , Jyri Sarha , Tomi Valkeinen , Laurent Pinchart , Jacopo Mondi , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v4 7/8] drm/i2c: tda998x: register as a drm bridge Message-ID: <20180424080833.GJ16141@n2100.armlinux.org.uk> References: <20180423072301.11962-1-peda@axentia.se> <20180423072301.11962-8-peda@axentia.se> <20180423160833.GF16141@n2100.armlinux.org.uk> <5d6866d0-75bc-4de8-9b87-4fee5430e9dd@axentia.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5d6866d0-75bc-4de8-9b87-4fee5430e9dd@axentia.se> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 24, 2018 at 08:58:42AM +0200, Peter Rosin wrote: > On 2018-04-23 18:08, Russell King - ARM Linux wrote: > > On Mon, Apr 23, 2018 at 09:23:00AM +0200, Peter Rosin wrote: > >> static int tda998x_remove(struct i2c_client *client) > >> { > >> - component_del(&client->dev, &tda998x_ops); > >> + struct device *dev = &client->dev; > >> + struct tda998x_bridge *bridge = dev_get_drvdata(dev); > >> + > >> + drm_bridge_remove(&bridge->bridge); > >> + component_del(dev, &tda998x_ops); > >> + > > > > I'd like to ask a rather fundamental question about DRM bridge support, > > because I suspect that there's a major fsckup here. > > > > The above is the function that deals with the TDA998x device being > > unbound from the driver. With the component API, this results in the > > DRM device correctly being torn down, because one of the hardware > > devices has gone. > > > > With DRM bridge, the bridge is merely removed from the list of > > bridges: > > > > void drm_bridge_remove(struct drm_bridge *bridge) > > { > > mutex_lock(&bridge_lock); > > list_del_init(&bridge->list); > > mutex_unlock(&bridge_lock); > > } > > EXPORT_SYMBOL(drm_bridge_remove); > > > > and the memory backing the "struct tda998x_bridge" (which contains > > the struct drm_bridge) will be freed by the devm subsystem. > > > > However, there is no notification into the rest of the DRM subsystem > > that the device has gone away. Worse, the memory that is still in > > use by DRM has now been freed, so further use of the DRM device > > results in a use-after-free bug. > > > > This is really not good, and to me looks like a fundamental problem > > with the DRM bridge code. I see nothing in the DRM bridge code that > > deals with the lifetime of a "DRM bridge" or indeed the lifetime of > > the actual device itself. > > > > So, from what I can see, there seems to be a fundamental lifetime > > issue with the design of the DRM bridge code. This needs to be > > fixed. > > Oh crap. A gigantic can of worms... Yes, it's especially annoying for me, having put the effort in to the component helper to cover all these cases. > Would a patch (completely untested btw) along this line of thinking make > any difference whatsoever? It looks interesting - from what I can see of the device links code, it would have the effect of unbinding the DRM device just before TDA998x is unbound, so that's an improvement. However, from what I can see, the link vanishes at that point (as DL_FLAG_AUTOREMOVE is set), and re-binding the TDA998x device results in nothing further happening - the link will be recreated, but there appears to be nothing that triggers the "consumer" to rebind at that point. Maybe I've missed something? -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up