Linux ARM-MSM sub-architecture
 help / color / mirror / Atom feed
From: Maxime Ripard <mripard@kernel.org>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>,
	 Hans de Goede <hdegoede@redhat.com>
Cc: Andrzej Hajda <andrzej.hajda@intel.com>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	Robert Foss <rfoss@kernel.org>,
	 Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	 Jernej Skrabec <jernej.skrabec@gmail.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>,
	 Daniel Vetter <daniel@ffwll.ch>, Rob Clark <robdclark@gmail.com>,
	 Abhinav Kumar <quic_abhinavk@quicinc.com>,
	Sean Paul <sean@poorly.run>,
	 Marijn Suijten <marijn.suijten@somainline.org>,
	dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
	 freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/9] drm/bridge-connector: switch to using drmm allocations
Date: Mon, 10 Jun 2024 14:07:06 +0200	[thread overview]
Message-ID: <20240610-smooth-liberal-guan-59853e@houat> (raw)
In-Reply-To: <CAA8EJpogi2qm0bhCwumY4zj-xMUkF4zbK-NAPqCeDbLcybFciw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4798 bytes --]

Hi,

+Hans

On Mon, Jun 10, 2024 at 02:46:03PM GMT, Dmitry Baryshkov wrote:
> On Mon, 10 Jun 2024 at 11:04, Maxime Ripard <mripard@kernel.org> wrote:
> >
> > Hi,
> >
> > On Fri, Jun 07, 2024 at 04:22:59PM GMT, Dmitry Baryshkov wrote:
> > > Turn drm_bridge_connector to using drmm_kzalloc() and
> > > drmm_connector_init() and drop the custom destroy function. The
> > > drm_connector_unregister() and fwnode_handle_put() are already handled
> > > by the drm_connector_cleanup() and so are safe to be dropped.
> > >
> > > Acked-by: Maxime Ripard <mripard@kernel.org>
> > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> > > ---
> > >  drivers/gpu/drm/drm_bridge_connector.c | 23 +++++------------------
> > >  1 file changed, 5 insertions(+), 18 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_bridge_connector.c b/drivers/gpu/drm/drm_bridge_connector.c
> > > index 982552c9f92c..e093fc8928dc 100644
> > > --- a/drivers/gpu/drm/drm_bridge_connector.c
> > > +++ b/drivers/gpu/drm/drm_bridge_connector.c
> > > @@ -15,6 +15,7 @@
> > >  #include <drm/drm_connector.h>
> > >  #include <drm/drm_device.h>
> > >  #include <drm/drm_edid.h>
> > > +#include <drm/drm_managed.h>
> > >  #include <drm/drm_modeset_helper_vtables.h>
> > >  #include <drm/drm_probe_helper.h>
> > >
> > > @@ -193,19 +194,6 @@ drm_bridge_connector_detect(struct drm_connector *connector, bool force)
> > >       return status;
> > >  }
> > >
> > > -static void drm_bridge_connector_destroy(struct drm_connector *connector)
> > > -{
> > > -     struct drm_bridge_connector *bridge_connector =
> > > -             to_drm_bridge_connector(connector);
> > > -
> > > -     drm_connector_unregister(connector);
> > > -     drm_connector_cleanup(connector);
> > > -
> > > -     fwnode_handle_put(connector->fwnode);
> > > -
> > > -     kfree(bridge_connector);
> > > -}
> > > -
> > >  static void drm_bridge_connector_debugfs_init(struct drm_connector *connector,
> > >                                             struct dentry *root)
> > >  {
> > > @@ -224,7 +212,6 @@ static const struct drm_connector_funcs drm_bridge_connector_funcs = {
> > >       .reset = drm_atomic_helper_connector_reset,
> > >       .detect = drm_bridge_connector_detect,
> > >       .fill_modes = drm_helper_probe_single_connector_modes,
> > > -     .destroy = drm_bridge_connector_destroy,
> > >       .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
> > >       .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
> > >       .debugfs_init = drm_bridge_connector_debugfs_init,
> > > @@ -328,7 +315,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
> > >       int connector_type;
> > >       int ret;
> > >
> > > -     bridge_connector = kzalloc(sizeof(*bridge_connector), GFP_KERNEL);
> > > +     bridge_connector = drmm_kzalloc(drm, sizeof(*bridge_connector), GFP_KERNEL);
> >
> > So you make destroy's kfree call unnecessary here ...
> >
> > >       if (!bridge_connector)
> > >               return ERR_PTR(-ENOMEM);
> > >
> > > @@ -383,9 +370,9 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
> > >               return ERR_PTR(-EINVAL);
> > >       }
> > >
> > > -     ret = drm_connector_init_with_ddc(drm, connector,
> > > -                                       &drm_bridge_connector_funcs,
> > > -                                       connector_type, ddc);
> > > +     ret = drmm_connector_init(drm, connector,
> > > +                               &drm_bridge_connector_funcs,
> > > +                               connector_type, ddc);
> >
> > ... and here of drm_connector_cleanup.
> >
> > drm_connector_unregister wasn't needed, so can ignore it, but you leak a reference to
> > connector->fwnode since you don't call fwnode_handle_put anymore.
> >
> > We should register a drmm action right below the call to fwnode_handle_get too.
> 
> But drm_connector_cleanup() already contains
> fwnode_handle_put(connector->fwnode). Isn't that enough?

It does, but now I'm confused.

drm_bridge_connector_init takes a reference, drm_connector_init doesn't.
It will call drm_bridge_connector_destroy() that gives back its
reference (which makes sense to me), but then why do
drm_connector_cleanup() does? None of the drm_connector code even took
that reference, and we end up with a double-put.

It looks like it was introduced by commit 48c429c6d18d ("drm/connector:
Add a fwnode pointer to drm_connector and register with ACPI (v2)") from
Hans, which does call put, but never gets that reference.

It has nothing to do with this series anymore, but that's super fishy to
me, and the source of bugs as we can see here.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2024-06-10 12:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-07 13:22 [PATCH v5 0/9] drm/msm: make use of the HDMI connector infrastructure Dmitry Baryshkov
2024-06-07 13:22 ` [PATCH v5 1/9] drm/connector: hdmi: allow disabling Audio Infoframe Dmitry Baryshkov
2024-06-10  8:30   ` Maxime Ripard
2024-06-07 13:22 ` [PATCH v5 2/9] drm/bridge-connector: switch to using drmm allocations Dmitry Baryshkov
2024-06-10  8:04   ` Maxime Ripard
2024-06-10 11:46     ` Dmitry Baryshkov
2024-06-10 12:07       ` Maxime Ripard [this message]
2024-06-10 17:54         ` Dmitry Baryshkov
2024-06-11  8:54           ` Maxime Ripard
2024-06-11 11:26             ` Dmitry Baryshkov
2024-06-13  7:57               ` Maxime Ripard
2024-06-07 13:23 ` [PATCH v5 3/9] drm/bridge-connector: implement glue code for HDMI connector Dmitry Baryshkov
2024-06-07 13:23 ` [PATCH v5 4/9] drm/msm/hdmi: switch to atomic bridge callbacks Dmitry Baryshkov
2024-06-20 20:19   ` Abhinav Kumar
2024-06-07 13:23 ` [PATCH v5 5/9] drm/msm/hdmi: turn mode_set into atomic_enable Dmitry Baryshkov
2024-06-20 20:27   ` Abhinav Kumar
2024-06-20 20:32     ` Dmitry Baryshkov
2024-06-20 20:49       ` Abhinav Kumar
2024-06-20 21:24         ` Dmitry Baryshkov
2024-06-20 22:05           ` Abhinav Kumar
2024-06-20 22:17             ` Dmitry Baryshkov
2024-06-07 13:23 ` [PATCH v5 6/9] drm/msm/hdmi: make use of the drm_connector_hdmi framework Dmitry Baryshkov
2024-06-07 13:23 ` [PATCH v5 7/9] drm/msm/hdmi: get rid of hdmi_mode Dmitry Baryshkov
2024-06-20 20:54   ` Abhinav Kumar
2024-06-07 13:23 ` [PATCH v5 8/9] drm/msm/hdmi: update HDMI_GEN_PKT_CTRL_GENERIC0_UPDATE definition Dmitry Baryshkov
2024-06-20 20:57   ` Abhinav Kumar
2024-06-07 13:23 ` [PATCH v5 9/9] drm/msm/hdmi: also send the SPD and HDMI Vendor Specific InfoFrames Dmitry Baryshkov
2024-06-10  8:39   ` Maxime Ripard
2024-06-12  8:02 ` (subset) [PATCH v5 0/9] drm/msm: make use of the HDMI connector infrastructure Dmitry Baryshkov
2024-06-23  7:14 ` Dmitry Baryshkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240610-smooth-liberal-guan-59853e@houat \
    --to=mripard@kernel.org \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=airlied@gmail.com \
    --cc=andrzej.hajda@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonas@kwiboo.se \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=marijn.suijten@somainline.org \
    --cc=neil.armstrong@linaro.org \
    --cc=quic_abhinavk@quicinc.com \
    --cc=rfoss@kernel.org \
    --cc=robdclark@gmail.com \
    --cc=sean@poorly.run \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox