From nobody Thu Dec 18 22:14:35 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37C582147FC for ; Mon, 31 Mar 2025 16:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743437824; cv=none; b=GLN3pb6waAMhzcrwhUqggeu6o1sW7kvdFjMWwK0KBSxsCJDOC7sWuJtlRsEeOHYWlMdJaI6tTqosdMWNWYNJT3q2eDGZQDF+1m7sboJKOKThUhsP+Qau1gloQqNCBzSNbm+50uExIjBUG05z6yrs48Ft6ywH9cr2quEmRmUlxDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743437824; c=relaxed/simple; bh=dGFdiEEIoKrBY0CHQmQoP3dS1mlW8dQMT7u1cDNngOs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CgX7MV/eTYE5a/BkKEqbF8sxoN1bSPZH3v78pRBKaOmm2n1A78Kkbg0ng+7w3JFj4wY3/yx00IMk+ArI9dcmey8wCxdXXPkn5LctERwYbwVuXnu+NnYzuLXMZFfX+J0icjFdOjzOHoWsfaaFg+5xRrzflNVXqBvocEQXD2uA7Dc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=NntawUBT; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NntawUBT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743437822; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rc18XBScOjqMIv9eqwD1pgYcY8jfVOClLYYKTh2GFcQ=; b=NntawUBTIE0fE12R7zP+2bNTqeZ3B7sngHB/oiDWE8yjuXCDpbHbackYBbxfBq0Se41d8C 65eGImW6NUb+gOvaEDizSMya1GcLrufGzHxtTCBIpSkuYl5ATRLMw3DsM+c6pDtLfoI5xy uzl3rTbFWFf3JT1DL28o/fLC6QVKkFo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-ANJ93_-OOuSO9gkjg_HSTg-1; Mon, 31 Mar 2025 12:16:59 -0400 X-MC-Unique: ANJ93_-OOuSO9gkjg_HSTg-1 X-Mimecast-MFC-AGG-ID: ANJ93_-OOuSO9gkjg_HSTg_1743437817 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 03CB9195608B; Mon, 31 Mar 2025 16:16:57 +0000 (UTC) Received: from asrivats-na.rmtustx.csb (unknown [10.2.16.30]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9E7D119541A5; Mon, 31 Mar 2025 16:16:54 +0000 (UTC) From: Anusha Srivatsa Date: Mon, 31 Mar 2025 11:15:25 -0400 Subject: [PATCH v4 1/4] drm/panel: Add new helpers for refcounted panel allocatons Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250331-b4-panel-refcounting-v4-1-dad50c60c6c9@redhat.com> References: <20250331-b4-panel-refcounting-v4-0-dad50c60c6c9@redhat.com> In-Reply-To: <20250331-b4-panel-refcounting-v4-0-dad50c60c6c9@redhat.com> To: Neil Armstrong , Jessica Zhang , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Luca Ceresoli , Anusha Srivatsa X-Developer-Signature: v=1; a=ed25519-sha256; t=1743434129; l=3414; i=asrivats@redhat.com; s=20250122; h=from:subject:message-id; bh=dGFdiEEIoKrBY0CHQmQoP3dS1mlW8dQMT7u1cDNngOs=; b=46v732Jvdko2Hi0ojuCGWwTcK3VysH+7AHOIiL4pc4l6mcyvhTsLQPkb4cEaby0m/QjVCdJ7n SGCf8ULoqgMD4GBEcK8fApAY8TCZstshnWjk7SsgtkRkMfBM9XFqw6m X-Developer-Key: i=asrivats@redhat.com; a=ed25519; pk=brnIHkBsUZEhyW6Zyn0U92AeIZ1psws/q8VFbIkf1AU= X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Introduce reference counted allocations for panels to avoid use-after-free. The patch adds the macro devm_drm_bridge_alloc() to allocate a new refcounted panel. Followed the documentation for drmm_encoder_alloc() and devm_drm_dev_alloc and other similar implementations for this purpose. Reviewed-by: Maxime Ripard Signed-off-by: Anusha Srivatsa --- v4: Remove documentation about refcounting in this patch, it is not used yet. v3: Remove include. Fix typos. Code style corrections (Luca) - Move the documentation to the main helper instead of in returns (Maxime) v2: Better documentation for connector_type field - follow drm_panel_init documentation. (Luca) - Clarify the refcount initialisation in comments.(Maxime) - Correct the documentation of the return type (Maxime) --- drivers/gpu/drm/drm_panel.c | 25 +++++++++++++++++++++++++ include/drm/drm_panel.h | 22 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index c627e42a7ce70459f50eb5095fffc806ca45dabf..bdeab5710ee324dc1742fbc7758= 2250960556308 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -355,6 +355,31 @@ struct drm_panel *of_drm_find_panel(const struct devic= e_node *np) } EXPORT_SYMBOL(of_drm_find_panel); =20 +void *__devm_drm_panel_alloc(struct device *dev, size_t size, size_t offse= t, + const struct drm_panel_funcs *funcs, + int connector_type) +{ + void *container; + struct drm_panel *panel; + + if (!funcs) { + dev_warn(dev, "Missing funcs pointer\n"); + return ERR_PTR(-EINVAL); + } + + container =3D devm_kzalloc(dev, size, GFP_KERNEL); + if (!container) + return ERR_PTR(-ENOMEM); + + panel =3D container + offset; + panel->funcs =3D funcs; + + drm_panel_init(panel, dev, funcs, connector_type); + + return container; +} +EXPORT_SYMBOL(__devm_drm_panel_alloc); + /** * of_drm_get_panel_orientation - look up the orientation of the panel thr= ough * the "rotation" binding from a device tree node diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h index a9c042c8dea1a82ef979c7a68204e0b55483fc28..415e85e8b76a15679f59c944ea1= 52367dc3e0488 100644 --- a/include/drm/drm_panel.h +++ b/include/drm/drm_panel.h @@ -268,6 +268,28 @@ struct drm_panel { bool enabled; }; =20 +void *__devm_drm_panel_alloc(struct device *dev, size_t size, size_t offse= t, + const struct drm_panel_funcs *funcs, + int connector_type); + +/** + * devm_drm_panel_alloc - Allocate and initialize a refcounted panel. + * + * @dev: struct device of the panel device + * @type: the type of the struct which contains struct &drm_panel + * @member: the name of the &drm_panel within @type + * @funcs: callbacks for this panel + * @connector_type: the connector type (DRM_MODE_CONNECTOR_*) correspondin= g to + * the panel interface + * + * Returns: + * Pointer to container structure embedding the panel, ERR_PTR on failure. + */ +#define devm_drm_panel_alloc(dev, type, member, funcs, connector_type) \ + ((type *)__devm_drm_panel_alloc(dev, sizeof(type), \ + offsetof(type, member), funcs, \ + connector_type)) + void drm_panel_init(struct drm_panel *panel, struct device *dev, const struct drm_panel_funcs *funcs, int connector_type); --=20 2.48.1