From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B844BC4361B for ; Tue, 15 Dec 2020 11:04:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 52E4B2224C for ; Tue, 15 Dec 2020 11:04:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52E4B2224C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=raspberrypi.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=OPrrW3sUWAugzp1yAE1OTpJ730vuN3E2mOuPHh3RxSg=; b=PwUqNspxibT1mBSmfVu/PJ+8G OGIQIxRtVzfRh6Af6s7BIKgJYoV1764rUwj39v/ynEWpR7pDIkHZVwd2z8iNsg5Gd5pDQUVS3zoUh BDG5CnNEQCrRGXb52+k3bSX718G/S1hRAC4SKHKfPxR0Uv2h4+OKfjak9RpX8xozUAz57NF0FEhnG FSWcZCOM61Kzxyoc/2PQOfdOa3q3t+faIo6Sb0g9BwOkZbSwd4stGe16DgaQflbraEVaBTJ6yc+sp G8qc0/t2j2LRfLAlI3oB/T+B/2L7kDwcc0CQRbRTDhqLWR/wqMqWGxFlx9YUPJYV8LkEnhQT70+dJ MwqJlRo0g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kp86V-0003n3-JC; Tue, 15 Dec 2020 11:02:51 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kp86R-0003lj-Bt for linux-arm-kernel@lists.infradead.org; Tue, 15 Dec 2020 11:02:48 +0000 Received: by mail-wr1-x443.google.com with SMTP id q18so11890399wrn.1 for ; Tue, 15 Dec 2020 03:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=g8OiD2oVgl752irPXqrQDpekK2rivukbIEiJ5JnIADY=; b=R5y0LIxZe4MNJZDqhTONBJ1GaUq7eieWDKfVrO3i1k4QfMLGW22iLzmbxvjufSHL5A DGg/GhqQuRitslub+3yqDVwZ6WJZ4itOej1ZARgTjiwhFjghVrYOLZ8WSssMFclHUkg1 2NZ81F/7EEL1H0E6bxihrpsV39PocXHojo0ESr0UfRjzuruhMradLVbvdmEBEA9voGjJ ZW9R4EEw/9GT8ZxVx0Ngmzj4tpY2p0SLKHZKYpy/FDKpCN67A6hoTx/AUJyWAzWJDWxR vicb/SVNkQ0Fr5b7w+nkVAqjY7TpEZ/zmoN3fptDBcqtxGlyF//FBqzL4accbsdVK7II aZEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=g8OiD2oVgl752irPXqrQDpekK2rivukbIEiJ5JnIADY=; b=L/v2N7lBeyYgdFDKE764BT1wzTxWcBe1RmDHrUJMVk1JiunA9c+fRO6rjLtEaZh6La cogVwgjYPzbzFWhFL48fAMtjpKbf0Bpw5TQ1M5D2X7+AnIPXdm5gWYLpmAEfStqgw75X qJScOuywADj39D42nZOaYOsk6KlOnzzqqsaeFB7hMq7kYDzBep2fXGWjDOmPUoQ87BhE +1mmQ8aKm4IOsrfTohPl1XYc3mnN+d2YOGs9vwUK4pvwXhYL2gXtlILRlARWA3oSCs0+ cmmwWVdddV5JjahXEkAEQLg7yc5iS0KRMuj2A5aqQpAvC1ZOZo6QKmi0oF7MzhSuwVdV 5MCQ== X-Gm-Message-State: AOAM533WMjKG5bGPQzXOFbRzcw2TXgqBlmUK6dD3rc6Bh2gQdEieJv6j wg3OWPz4Bbwg95E75695XJ2V9+wcte7x7jXgudedmg== X-Google-Smtp-Source: ABdhPJySaBSVh6y3AEsd2fDbJ39jQm7186om8mV/XYQW51MtOHvpo5t+dWJrqpneH6u+SxAeFDqH0pKK/s49FbU90jU= X-Received: by 2002:adf:8290:: with SMTP id 16mr32425767wrc.27.1608030164545; Tue, 15 Dec 2020 03:02:44 -0800 (PST) MIME-Version: 1.0 References: <20201210142329.10640-1-maxime@cerno.tech> <20201210142329.10640-6-maxime@cerno.tech> In-Reply-To: <20201210142329.10640-6-maxime@cerno.tech> From: Dave Stevenson Date: Tue, 15 Dec 2020 11:02:28 +0000 Message-ID: Subject: Re: [PATCH v6 5/9] drm/vc4: hdmi: Create a custom connector state To: Maxime Ripard X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201215_060247_467106_46A27B85 X-CRM114-Status: GOOD ( 23.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Maarten Lankhorst , DRI Development , Eric Anholt , bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, Thomas Zimmermann , Daniel Vetter , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Maxime On Thu, 10 Dec 2020 at 14:23, Maxime Ripard wrote: > > When run with a higher bpc than 8, the clock of the HDMI controller needs > to be adjusted. Let's create a connector state that will be used at > atomic_check and atomic_enable to compute and store the clock rate > associated to the state. > > Acked-by: Thomas Zimmermann > Reviewed-by: Dave Stevenson > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/vc4/vc4_hdmi.c | 33 ++++++++++++++++++++++++++++++--- > drivers/gpu/drm/vc4/vc4_hdmi.h | 10 ++++++++++ > 2 files changed, 40 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > index 61039cc89d9d..8978df3f0ca4 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > @@ -170,10 +170,37 @@ static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) > > static void vc4_hdmi_connector_reset(struct drm_connector *connector) > { > - drm_atomic_helper_connector_reset(connector); > + struct vc4_hdmi_connector_state *old_state = > + conn_state_to_vc4_hdmi_conn_state(connector->state); > + struct vc4_hdmi_connector_state *new_state = > + kzalloc(sizeof(*conn_state), GFP_KERNEL); > > if (connector->state) > - drm_atomic_helper_connector_tv_reset(connector); > + __drm_atomic_helper_connector_destroy_state(connector->state); > + > + kfree(old_state); > + > + if (!new_state) > + return; This has changed since v5 that I added my R-B to. So we no longer call __drm_atomic_helper_connector_reset should the kzalloc fail. Doesn't that mean connector->state is still set to old_state? Except we've called kfree on that and it's therefore invalid. Calling __drm_atomic_helper_connector_reset unconditionally is fine as it checks for the new pointer being NULL before dereferencing, but always assigns it to connector->state. Calling drm_atomic_helper_connector_tv_reset when connector->state = NULL isn't safe. > + __drm_atomic_helper_connector_reset(connector, &new_state->base); Put the if (!new_state) return; here? Patch 9/9 can set the max_bpc and max_bpc_requested field here too. Dave > + drm_atomic_helper_connector_tv_reset(connector); > +} > + > +static struct drm_connector_state * > +vc4_hdmi_connector_duplicate_state(struct drm_connector *connector) > +{ > + struct drm_connector_state *conn_state = connector->state; > + struct vc4_hdmi_connector_state *vc4_state = conn_state_to_vc4_hdmi_conn_state(conn_state); > + struct vc4_hdmi_connector_state *new_state; > + > + new_state = kzalloc(sizeof(*new_state), GFP_KERNEL); > + if (!new_state) > + return NULL; > + > + __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base); > + > + return &new_state->base; > } > > static const struct drm_connector_funcs vc4_hdmi_connector_funcs = { > @@ -181,7 +208,7 @@ static const struct drm_connector_funcs vc4_hdmi_connector_funcs = { > .fill_modes = drm_helper_probe_single_connector_modes, > .destroy = vc4_hdmi_connector_destroy, > .reset = vc4_hdmi_connector_reset, > - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, > + .atomic_duplicate_state = vc4_hdmi_connector_duplicate_state, > .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, > }; > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h > index 0526a9cf608a..2cf5362052e2 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.h > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h > @@ -180,6 +180,16 @@ encoder_to_vc4_hdmi(struct drm_encoder *encoder) > return container_of(_encoder, struct vc4_hdmi, encoder); > } > > +struct vc4_hdmi_connector_state { > + struct drm_connector_state base; > +}; > + > +static inline struct vc4_hdmi_connector_state * > +conn_state_to_vc4_hdmi_conn_state(struct drm_connector_state *conn_state) > +{ > + return container_of(conn_state, struct vc4_hdmi_connector_state, base); > +} > + > void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, > struct drm_display_mode *mode); > void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi); > -- > 2.28.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C96EEC4361B for ; Tue, 15 Dec 2020 11:02:48 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 339F72222A for ; Tue, 15 Dec 2020 11:02:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 339F72222A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=raspberrypi.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 550086E1A7; Tue, 15 Dec 2020 11:02:47 +0000 (UTC) Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 24E976E1A7 for ; Tue, 15 Dec 2020 11:02:46 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id y17so19389853wrr.10 for ; Tue, 15 Dec 2020 03:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=g8OiD2oVgl752irPXqrQDpekK2rivukbIEiJ5JnIADY=; b=R5y0LIxZe4MNJZDqhTONBJ1GaUq7eieWDKfVrO3i1k4QfMLGW22iLzmbxvjufSHL5A DGg/GhqQuRitslub+3yqDVwZ6WJZ4itOej1ZARgTjiwhFjghVrYOLZ8WSssMFclHUkg1 2NZ81F/7EEL1H0E6bxihrpsV39PocXHojo0ESr0UfRjzuruhMradLVbvdmEBEA9voGjJ ZW9R4EEw/9GT8ZxVx0Ngmzj4tpY2p0SLKHZKYpy/FDKpCN67A6hoTx/AUJyWAzWJDWxR vicb/SVNkQ0Fr5b7w+nkVAqjY7TpEZ/zmoN3fptDBcqtxGlyF//FBqzL4accbsdVK7II aZEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=g8OiD2oVgl752irPXqrQDpekK2rivukbIEiJ5JnIADY=; b=AwvluTCZRQpVopdT14SrhQkxI6dyRWLkeT+AR47zbOhhoOBPwbMKwETf1e8xJgzbsC mGnUH1/QbXQ9f1p7NXkUlvyYX+i3jEw9C0GWGUXnGe3wDhPvNdNJ03vSBsB9YVUw7/oh ZFPIqEnPrFMzJcCOFh/SVFo8A0pDv55+4czCszDQ/0rXvB+n6g4Wq7K6QeSV5uo8k3jM YNxTJlXZo0iC8dHeCtV/+I35kHJNdyY4JE3uoJozEIEra6xFbhtS43VSOfYGN+I1I0O0 EpYVxHLNRhon3O0osKzER5TwS/Vk6UqRUhrwnOofW7UxbH+HNuqfgEUK8f/XlJrZaoPD 5liw== X-Gm-Message-State: AOAM5307aDMiySEwfuwfHNFqPUD0OqN9d0zCi4XW7Ewn1OVLb3fFR1MZ GXfSsNlfgN+XfkZlE393lihsw3Lg+b+pdGrRua26jA== X-Google-Smtp-Source: ABdhPJySaBSVh6y3AEsd2fDbJ39jQm7186om8mV/XYQW51MtOHvpo5t+dWJrqpneH6u+SxAeFDqH0pKK/s49FbU90jU= X-Received: by 2002:adf:8290:: with SMTP id 16mr32425767wrc.27.1608030164545; Tue, 15 Dec 2020 03:02:44 -0800 (PST) MIME-Version: 1.0 References: <20201210142329.10640-1-maxime@cerno.tech> <20201210142329.10640-6-maxime@cerno.tech> In-Reply-To: <20201210142329.10640-6-maxime@cerno.tech> From: Dave Stevenson Date: Tue, 15 Dec 2020 11:02:28 +0000 Message-ID: Subject: Re: [PATCH v6 5/9] drm/vc4: hdmi: Create a custom connector state To: Maxime Ripard X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , DRI Development , bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, Thomas Zimmermann , Daniel Vetter , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi Maxime On Thu, 10 Dec 2020 at 14:23, Maxime Ripard wrote: > > When run with a higher bpc than 8, the clock of the HDMI controller needs > to be adjusted. Let's create a connector state that will be used at > atomic_check and atomic_enable to compute and store the clock rate > associated to the state. > > Acked-by: Thomas Zimmermann > Reviewed-by: Dave Stevenson > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/vc4/vc4_hdmi.c | 33 ++++++++++++++++++++++++++++++--- > drivers/gpu/drm/vc4/vc4_hdmi.h | 10 ++++++++++ > 2 files changed, 40 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > index 61039cc89d9d..8978df3f0ca4 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > @@ -170,10 +170,37 @@ static int vc4_hdmi_connector_get_modes(struct drm_connector *connector) > > static void vc4_hdmi_connector_reset(struct drm_connector *connector) > { > - drm_atomic_helper_connector_reset(connector); > + struct vc4_hdmi_connector_state *old_state = > + conn_state_to_vc4_hdmi_conn_state(connector->state); > + struct vc4_hdmi_connector_state *new_state = > + kzalloc(sizeof(*conn_state), GFP_KERNEL); > > if (connector->state) > - drm_atomic_helper_connector_tv_reset(connector); > + __drm_atomic_helper_connector_destroy_state(connector->state); > + > + kfree(old_state); > + > + if (!new_state) > + return; This has changed since v5 that I added my R-B to. So we no longer call __drm_atomic_helper_connector_reset should the kzalloc fail. Doesn't that mean connector->state is still set to old_state? Except we've called kfree on that and it's therefore invalid. Calling __drm_atomic_helper_connector_reset unconditionally is fine as it checks for the new pointer being NULL before dereferencing, but always assigns it to connector->state. Calling drm_atomic_helper_connector_tv_reset when connector->state = NULL isn't safe. > + __drm_atomic_helper_connector_reset(connector, &new_state->base); Put the if (!new_state) return; here? Patch 9/9 can set the max_bpc and max_bpc_requested field here too. Dave > + drm_atomic_helper_connector_tv_reset(connector); > +} > + > +static struct drm_connector_state * > +vc4_hdmi_connector_duplicate_state(struct drm_connector *connector) > +{ > + struct drm_connector_state *conn_state = connector->state; > + struct vc4_hdmi_connector_state *vc4_state = conn_state_to_vc4_hdmi_conn_state(conn_state); > + struct vc4_hdmi_connector_state *new_state; > + > + new_state = kzalloc(sizeof(*new_state), GFP_KERNEL); > + if (!new_state) > + return NULL; > + > + __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base); > + > + return &new_state->base; > } > > static const struct drm_connector_funcs vc4_hdmi_connector_funcs = { > @@ -181,7 +208,7 @@ static const struct drm_connector_funcs vc4_hdmi_connector_funcs = { > .fill_modes = drm_helper_probe_single_connector_modes, > .destroy = vc4_hdmi_connector_destroy, > .reset = vc4_hdmi_connector_reset, > - .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, > + .atomic_duplicate_state = vc4_hdmi_connector_duplicate_state, > .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, > }; > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h > index 0526a9cf608a..2cf5362052e2 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.h > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h > @@ -180,6 +180,16 @@ encoder_to_vc4_hdmi(struct drm_encoder *encoder) > return container_of(_encoder, struct vc4_hdmi, encoder); > } > > +struct vc4_hdmi_connector_state { > + struct drm_connector_state base; > +}; > + > +static inline struct vc4_hdmi_connector_state * > +conn_state_to_vc4_hdmi_conn_state(struct drm_connector_state *conn_state) > +{ > + return container_of(conn_state, struct vc4_hdmi_connector_state, base); > +} > + > void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, > struct drm_display_mode *mode); > void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi); > -- > 2.28.0 > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel