Received: by 10.192.165.148 with SMTP id m20csp1279196imm; Wed, 25 Apr 2018 15:59:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+9mPLd9ZLeyJ+exB5vABjuiQ6d8vBmABaNSvDnXYM8QIiR1OSKkTGpZftuFYcteLSXJrW+ X-Received: by 2002:a17:902:5389:: with SMTP id c9-v6mr21142008pli.143.1524697149543; Wed, 25 Apr 2018 15:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524697149; cv=none; d=google.com; s=arc-20160816; b=ajMYJAC2kFtcGVZKv4CPBXlEkMhYXX8QNSLhYlOSEgOQ3vDldY09xtzg/rkkMjrwAK xSclcNVFn6ElYq3VM60Ee6seCeH4CBryqKKGk+0Vm6ILHK9YrSl267VOhqZaxLHBS7m9 EfsM0rI0v8Cra/7hZbLHs04v8A5uE62Euwk2Tm6m7HSOYSrvjAUb9VFvDuKSM4cpXJlS A9EWLd3YX4Zs4JYLPOGpHaTfZbb+lJF+9ritFEzADNW2CWriHG7zOLCD/SJ7CxzpEfp7 3TDtRG67ZGBBshd/+CIOsUr5cYgD2rZ9kZW9khD7h9p+DwDbLnPq+fCVvPL2v1x6CEs5 Uqgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=4FPbsPTNKBcMfozfv+RPO1VCO+/KLQUztSfzgy/Tn4A=; b=C2L/O2AOomjowK1PCblCer9K4XjfHf4gG6IfR1UCgHWa7IkDy0cRhW6KVCuk6C+Hdr uerVaWtUBuF4FgO930poS0Bb8qbYsLtoTDKSxrTgK6Gx8ZofH+OjwcFj+D89b1u4mgjV oeVmf8rAa5H9/K2kjrqjc9xcxxrKfIA5pHSNeD0C7EzmKwrD49n0wxFb2MY2Jp0K2YBa sLSkCTxovekc3eRa8XWH34CLLnOKKYd8pa+YmZN3DDlKo9FhQhMfhW0Mk8jlFgMepAeg FPtSS+QClck2qBjb6NdqQwCb5/gE+mW6AQehQe3YaV73dbUA5ra3muyysBu2KjP8zqYX h7kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tgNQEPBY; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i35-v6si16348741plg.504.2018.04.25.15.58.54; Wed, 25 Apr 2018 15:59:09 -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=pass header.i=@gmail.com header.s=20161025 header.b=tgNQEPBY; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754033AbeDYW5i (ORCPT + 99 others); Wed, 25 Apr 2018 18:57:38 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33930 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753701AbeDYW5e (ORCPT ); Wed, 25 Apr 2018 18:57:34 -0400 Received: by mail-wm0-f67.google.com with SMTP id w2so6324052wmw.1 for ; Wed, 25 Apr 2018 15:57:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=4FPbsPTNKBcMfozfv+RPO1VCO+/KLQUztSfzgy/Tn4A=; b=tgNQEPBYoHBYjvdgzgh1Tb4X7LmLpjZuqt5XMos0hTn/vfMsYAoqazRj1BGLLO1RYC RW4+6UiOyTf/y4U0O4Ugt23P8hP5L+fVmitDWBDdVwsTHY8PfyHhf/MU2fVT21/MjWk/ Duf6IXkOEQPpNB5oYQBTLbcBv3akK3NpTPam6nEsT3YZiSc7l6cDg1zKr80+mnADETUg 69soVthhC7tlc12a+4qUWQ4K+v/+YiDpsjrhffMlIL0kpHPHCvFs3FKQ/QYeuWjjJ5Ay Oy0FYNYhYpJBKoJ/R1RA2cy4I5Ktm+2Bjh4Nv6qDqShUM0xZh5hemWnh9Q3iAqiF4YRk SUxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=4FPbsPTNKBcMfozfv+RPO1VCO+/KLQUztSfzgy/Tn4A=; b=armFPUEfOrRtC/spe0+ASX6HNB1DFrk97wlC4SilwFC9HD7Bpdt0CRSwHYLbVJ6ZIH Gmp0mhj+iAKBeYTZcIMZApsWSHoa6S1r2ZsTHqCRKjdEK1DUQvDCEhCspQy4fFo2+1WX q3VWSKF9PBHUVpIOddErFv3U/5v5WsCZyAGaQvT4LbqQi/RHWzpvKNdooFXRGfjsZi9M SjLA6Z/x/4joJ/xTH3LooRyiUkHOMl2TgZ+3PiZJ3rFFVSSX2K1F0PIOAXuFq3vP8Rd/ onPTRMzKJ2aVdhzm74nN95R3mVk0HW/LdkFvE9/fxiq0eugHEPgvtOq8ZFk0eN1Hyrlt moww== X-Gm-Message-State: ALQs6tCM7AeGfRHssq4/z6llBDFoB9kh2mRKJYBATA/8dgAkhS3c1T6M GLZZCP4wVyTpuW2KUGWJR1e3yP7WqyuNU1oW0xk= X-Received: by 10.28.141.138 with SMTP id p132mr2698868wmd.49.1524697053460; Wed, 25 Apr 2018 15:57:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.169.150 with HTTP; Wed, 25 Apr 2018 15:56:53 -0700 (PDT) In-Reply-To: <20180424130445.GD31310@phenom.ffwll.local> References: <20180420115001.161745-1-lndmrk@chromium.org> <20180420135532.GH73214@art_vandelay> <20180424130445.GD31310@phenom.ffwll.local> From: =?UTF-8?Q?St=C3=A9phane_Marchesin?= Date: Wed, 25 Apr 2018 15:56:53 -0700 Message-ID: Subject: Re: [PATCH] drm: udl: Destroy framebuffer only if it was initialized To: Sean Paul , Emil Lundmark , Dave Airlie , Linux Kernel list , dri-devel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 6:04 AM, Daniel Vetter wrote: > On Fri, Apr 20, 2018 at 09:55:32AM -0400, Sean Paul wrote: >> On Fri, Apr 20, 2018 at 01:50:01PM +0200, Emil Lundmark wrote: >> > This fixes a NULL pointer dereference that can happen if the UDL >> > driver is unloaded before the framebuffer is initialized. This can >> > happen e.g. if the USB device is unplugged right after it was plugged >> > in. >> > >> >> JFYI, in future, if someone makes a suggestion on how to fix a bug, it's= good >> practice to add a Suggested-by tag to give credit. >> >> Reviewed-by: Sean Paul > > I think a bit more detail in the commit message on why this is even > possible would be good. I think it can only happen when you only plug in > the udl, without anything connected. Hehe, I was just reviewing this code internally, so I can answer that one := ) It happens when fbdev is disabled (which is the case for Chrome OS). Even though intialization of the fbdev part is optional (it's done in udlfb_create which is the callback for fb_probe()), the teardown isn't optional (udl_driver_unload -> udl_fbdev_cleanup -> udl_fbdev_destroy). Note that udl_fbdev_cleanup *tries* to be conditional (you can see it does if (!udl->fbdev)) but that doesn't work, because udl->fbdev is always set during udl_fbdev_init. St=C3=A9phane > > In that case fbdev setup will be delayed until something shows up (so we > don't pin a too small fb for it, a feature requested by soc people). This > can easily be tested: > First: > - plug in udl device > - wait a minute or so (to make it clear it's not a race) > - unplug > > And then: > - plug in an udl device, but with something connected. > - unplug right away. > > I expect that in the first case you'll always blow up, but in the 2nd one > you'll never blow up (no matter how fast you unplug). > > Cheers, Daniel > > > >> >> > Signed-off-by: Emil Lundmark >> > --- >> > drivers/gpu/drm/udl/udl_fb.c | 8 +++++--- >> > 1 file changed, 5 insertions(+), 3 deletions(-) >> > >> > diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb= .c >> > index 2ebdc6d5a76e..5754e37f741b 100644 >> > --- a/drivers/gpu/drm/udl/udl_fb.c >> > +++ b/drivers/gpu/drm/udl/udl_fb.c >> > @@ -426,9 +426,11 @@ static void udl_fbdev_destroy(struct drm_device *= dev, >> > { >> > drm_fb_helper_unregister_fbi(&ufbdev->helper); >> > drm_fb_helper_fini(&ufbdev->helper); >> > - drm_framebuffer_unregister_private(&ufbdev->ufb.base); >> > - drm_framebuffer_cleanup(&ufbdev->ufb.base); >> > - drm_gem_object_put_unlocked(&ufbdev->ufb.obj->base); >> > + if (ufbdev->ufb.obj) { >> > + drm_framebuffer_unregister_private(&ufbdev->ufb.base); >> > + drm_framebuffer_cleanup(&ufbdev->ufb.base); >> > + drm_gem_object_put_unlocked(&ufbdev->ufb.obj->base); >> > + } >> > } >> > >> > int udl_fbdev_init(struct drm_device *dev) >> > -- >> > 2.17.0.484.g0c8726318c-goog >> > >> >> -- >> Sean Paul, Software Engineer, Google / Chromium OS >> _______________________________________________ >> dri-devel mailing list >> dri-devel@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/dri-devel > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel