Received: by 10.192.165.148 with SMTP id m20csp4896506imm; Tue, 24 Apr 2018 10:08:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoC+XRgaI2L4xYRf/4Zk8OHBjQe182qEaNk96LERnJOAWq7WFwaPowpZSeFcT0wlI1n2Q1I X-Received: by 10.167.133.206 with SMTP id z14mr3401613pfn.2.1524589682104; Tue, 24 Apr 2018 10:08:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524589682; cv=none; d=google.com; s=arc-20160816; b=gQBHiQB3E0xvTpnIQAYyvNwnWnbuRe3KiO+jYwe5OthXgBn9zOoSlQg4I83fEaTGn3 7mMtMPBCaXzR6Nsadl/rNzNinifQiyATJp+rRYWy8sDWk3K0wsp7lnwOUqEiKZ31uJwe REe9dpb/j33BXFRI9uU3e/43Vtv4rbzeb1UZPV/IovZrDfD3btLFOV8RZw5hW7M7DCg9 An/ptkOgMgpwq2utExCgosh0MVEo+KtJjrPUaRLP800z7/cYQAEVzHrzg3hc/IVG0Aa+ UVizD3TsGp1N7f8WWz5rPKlwa1s9k8S11IwpDB68wQFu9CV09W7mqQSMENiuOgV3pYCG kc7Q== 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=CghkFv4evSrNnZa6H/h9t6/GolJy/xlQSlzkWXfhkbc=; b=qw1KpoL6Plxwib8e6kyUVKQypX5ozJ91ephn89q0N10CWoHDBILoNVpPv1rzISPosw OQACpW7UnavOX5hbYGGnaBHmYWWhotwYBHVqrtbnIeV6S8j2k9MgxDF6xdYdFLjfIq2Z UP7jiKcB7prNVDUKvei9RP6VDZutBC5KmgnccKLCOOL35mCLqcGtbD6FW5xCtCHromFe 22CIXjj6XvrKv6gmd4W/nnFirwev0ZKEoGZiuuA4pM9WaCdY92RpwpzTzATa8SCRe79L YB5Tsqj3glwrII+Yzg2pkH3e1B+5yByDlJRtjVCFh/xcHOB203sb+g49sUdy9ff2LQKQ UEmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=WgUJ093P; 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 g19si8312456pfb.280.2018.04.24.10.07.47; Tue, 24 Apr 2018 10:08:02 -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=WgUJ093P; 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 S1751307AbeDXRGo (ORCPT + 99 others); Tue, 24 Apr 2018 13:06:44 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:57640 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750827AbeDXRGj (ORCPT ); Tue, 24 Apr 2018 13:06:39 -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=CghkFv4evSrNnZa6H/h9t6/GolJy/xlQSlzkWXfhkbc=; b=WgUJ093PmDx3yxwit/f0AgI4v QahcZiAOgAGo6P4jbbL3Q9U54mUiZZ8hXKSUPXcw2Hi2c9hXZPEWjrsPtISFeIWXLiK1BLahR2/82 ALANKnVuC/iwUZjffBo7Z/zyx/QhIF7jmdoYJSGDQOdM+DdZPpRwvZJQrYGBF9yDHRCEg=; Received: from n2100.armlinux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:44898) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1fB1Og-0003m9-9D; Tue, 24 Apr 2018 18:06:30 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1fB1Od-0000Oe-2K; Tue, 24 Apr 2018 18:06:27 +0100 Date: Tue, 24 Apr 2018 18:06:25 +0100 From: Russell King - ARM Linux To: Jyri Sarha Cc: Peter Rosin , linux-kernel@vger.kernel.org, David Airlie , Rob Herring , Mark Rutland , Nicolas Ferre , Alexandre Belloni , Boris Brezillon , 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: <20180424170625.GL16141@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> <20180424080833.GJ16141@n2100.armlinux.org.uk> <8448e90a-4562-b564-c160-1b5c67e0f92f@axentia.se> <0cbee3bd-8987-5f2f-519d-f8d1b426f2a3@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0cbee3bd-8987-5f2f-519d-f8d1b426f2a3@ti.com> 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 07:04:16PM +0300, Jyri Sarha wrote: > On 24/04/18 13:14, Peter Rosin wrote: > > On 2018-04-24 10:08, Russell King - ARM Linux wrote: > >> 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? > > > > Right, auto-remove is a no-go. So, improving on the previous... > > > > (I think drm_panel might suffer from this issue too?) > > Yes it does and I took a shot at trying to fix it at the end of the > previous merge window, but gave up as I run out of time. I re-spun the > work now after reading this thread. I add you and Russell to cc. Right, and these exact problems are what the component helper is there to sort out, in a subsystem independent way. What is the problem with the component helper that people seem to be soo loathed to use it, instead preferring to come up with sub- standard and broken alternatives? -- 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