Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp331490pxb; Wed, 20 Jan 2021 08:03:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/T1M+gJz1rsAos/XW5ILSm/MyAn5b/snk6oiSVxkl1dqiPZrO7M4gRiB3fHJsv4XazDxn X-Received: by 2002:a05:6402:54d:: with SMTP id i13mr1966583edx.12.1611158583291; Wed, 20 Jan 2021 08:03:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611158583; cv=none; d=google.com; s=arc-20160816; b=yCxFpfRcJxy4ulWlI3f40NvAqMu+iw1ViQZEhQDlhAynCVtI/VBwSQoJAQbsvCcGtj Qms6TyN7yjKtBu8mZYsHxr5iyeWk5U5vuxznyvfmFGmo/NaO1ByL75qrDbMfeOVZXOgZ HtccyGyBIYNowRso4HMjttd4dEankO67RMVOgnbiHtGhTM+QX55Eo5VNr+zMpbjXQIgM CTFNwXlFf+qm/IwPcOe085DQY1ibBGTTs0bHvVQus/67ytIf1wyL6WmN3Qj3cOsO5EEJ ZYfKVTnj0i9DWMC1ZqbF+8e5SAi0yw2Eb2D2Zg4oFgWmS6WpEDFZpUn63fQNg/Q7HEp6 IJ5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:cc:to:subject:from:date; bh=TCRYRZugo4aJOGEGipYctl93gQ3kfQ1UAaQeNq426OA=; b=IqmQUilvCVs/tBLaBnr9CuE36rGhW1eNIarpzh61qNnWJhdf4nCuvePiVEQ97YXlcZ GmrCzq+QQbNROk2vXiBxXWjgZNgAmfcpLj3OkZS18Tu2qipxD/3wo8JLu6FHzhpRxFBq 9Yo2ae61wIydGWRDWKsnviwn4J1A4/JS1lQSzsBydqpGuQ9x5YvS4SvvHql2YMkB7XeE Ue1/8idL+SbdLtv6vnceuaVImccHWcwNfP0He1/iuIolLI8xEYrfQliVhayM/uTL8+ge jyKB0Hn0jAjdXFkPYqR35v95XrI9weYCDUssSzyPmAPnVjBjDWp9eY9Bt5yZYEnM85yA RkVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y14si993732edt.2.2021.01.20.08.02.34; Wed, 20 Jan 2021 08:03:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390572AbhATP7J convert rfc822-to-8bit (ORCPT + 99 others); Wed, 20 Jan 2021 10:59:09 -0500 Received: from aposti.net ([89.234.176.197]:58060 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389798AbhATP4c (ORCPT ); Wed, 20 Jan 2021 10:56:32 -0500 Date: Wed, 20 Jan 2021 15:55:33 +0000 From: Paul Cercueil Subject: Re: [PATCH v2 2/3] drm/ingenic: Register devm action to cleanup encoders To: Daniel Vetter Cc: David Airlie , Sam Ravnborg , Laurent Pinchart , od@zcrc.me, dri-devel , Linux Kernel Mailing List , stable Message-Id: In-Reply-To: References: <20210120123535.40226-1-paul@crapouillou.net> <20210120123535.40226-3-paul@crapouillou.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le mer. 20 janv. 2021 ? 15:04, Daniel Vetter a ?crit : > On Wed, Jan 20, 2021 at 2:21 PM Paul Cercueil > wrote: >> >> >> >> Le mer. 20 janv. 2021 ? 14:01, Daniel Vetter a >> ?crit : >> > On Wed, Jan 20, 2021 at 1:36 PM Paul Cercueil >> >> > wrote: >> >> >> >> Since the encoders have been devm-allocated, they will be freed >> way >> >> before drm_mode_config_cleanup() is called. To avoid >> use-after-free >> >> conditions, we then must ensure that drm_encoder_cleanup() is >> called >> >> before the encoders are freed. >> >> >> >> v2: Use the new __drmm_simple_encoder_alloc() function >> >> >> >> Fixes: c369cb27c267 ("drm/ingenic: Support multiple >> panels/bridges") >> >> Cc: # 5.8+ >> >> Signed-off-by: Paul Cercueil >> >> --- >> >> >> >> Notes: >> >> Use the V1 of this patch to fix v5.11 and older kernels. >> This >> >> V2 only >> >> applies on the current drm-misc-next branch. >> >> >> >> drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 16 +++++++--------- >> >> 1 file changed, 7 insertions(+), 9 deletions(-) >> >> >> >> diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c >> >> b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c >> >> index 7bb31fbee29d..158433b4c084 100644 >> >> --- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c >> >> +++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c >> >> @@ -1014,20 +1014,18 @@ static int ingenic_drm_bind(struct >> device >> >> *dev, bool has_components) >> >> bridge = >> >> devm_drm_panel_bridge_add_typed(dev, panel, >> >> >> >> DRM_MODE_CONNECTOR_DPI); >> >> >> >> - encoder = devm_kzalloc(dev, sizeof(*encoder), >> >> GFP_KERNEL); >> >> - if (!encoder) >> >> - return -ENOMEM; >> >> + encoder = __drmm_simple_encoder_alloc(drm, >> >> sizeof(*encoder), 0, >> > >> > Please don't use the __ prefixed functions, those are the internal >> > ones. The official one comes with type checking and all that >> included. >> > Otherwise lgtm. >> > -Daniel >> >> The non-prefixed one assumes that I want to allocate a struct that >> contains the encoder, not just the drm_encoder itself. > > Hm, but using the internal one is also a bit too ugly. A > drm_plain_simple_enocder_alloc(drm, type) wrapper would be the right > thing here I think? Setting the offsets and struct sizes directly in > these in drivers really doesn't feel like a good idea. I think simple > encoder is the only case where we really have a need for a > non-embeddable struct. > -Daniel Alright, I will add a wrapper. Cheers, -Paul >> >> >> + >> >> DRM_MODE_ENCODER_DPI); >> >> + if (IS_ERR(encoder)) { >> >> + ret = PTR_ERR(encoder); >> >> + dev_err(dev, "Failed to init encoder: >> >> %d\n", ret); >> >> + return ret; >> >> + } >> >> >> >> encoder->possible_crtcs = 1; >> >> >> >> drm_encoder_helper_add(encoder, >> >> &ingenic_drm_encoder_helper_funcs); >> >> >> >> - ret = drm_simple_encoder_init(drm, encoder, >> >> DRM_MODE_ENCODER_DPI); >> >> - if (ret) { >> >> - dev_err(dev, "Failed to init encoder: >> >> %d\n", ret); >> >> - return ret; >> >> - } >> >> - >> >> ret = drm_bridge_attach(encoder, bridge, NULL, >> 0); >> >> if (ret) { >> >> dev_err(dev, "Unable to attach >> bridge\n"); >> >> -- >> >> 2.29.2 >> >> >> > >> > >> > -- >> > Daniel Vetter >> > Software Engineer, Intel Corporation >> > http://blog.ffwll.ch >> >> > > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch