Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp209924lqp; Tue, 11 Jun 2024 01:57:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjMPqBSfv9rfWI3SxllooZLGTTq25p9wajoc16H4bIW1KJNotb/ICQ4Cy+n+sj2j19/OpSxZlDQ6TXavJYvhoRxPRRrNCA8oWZStahAQ== X-Google-Smtp-Source: AGHT+IGjrFROQrpfvJDyKQlR6jlDFeEvKcUFx4Fsote3XnLxRXVFFD6RTS0eD2/yQm3Yv6101nqt X-Received: by 2002:a92:c26c:0:b0:375:bde7:7f86 with SMTP id e9e14a558f8ab-375bde78467mr8786665ab.14.1718096274140; Tue, 11 Jun 2024 01:57:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718096274; cv=pass; d=google.com; s=arc-20160816; b=M14bIGCUVEZnkTsfB1Z1JA7WggwGxq94ruG+15DFFagkGqeuDd8lUBP3G5QojKb6jc OwVv2xjSq1gQs0iftJtNTdw4EG1kUBdPlBoC1hE/WmgN4ZytQLrvL+cvOm+U+93uK2Co Jimv1Owo/6b0bE7SJYdlarG0vVVyqM3EQaKwWVqkdCMhe2b2VTHKPuWWR2b3L/Kf3cCO yV1bVLx6nCHAcfVVbaX92kvfqpye4IeB9tkkHqKFY3IY+QFzHipfntLArdSq2KJKf84e O8A8RDalu0oSUlxu7Bj2KVL4TKj++hUldWuoOzq9e1OK17TSgPMXiAHjO1ZRw+AaegSd p5pQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ShJSMZj4oIsl2rWNa2ShYqMOi4qGylFXTVcvJcmKOkE=; fh=/l7KTfaOaEj29cmeT0U1xiRuxHylk/q373Pc0/mNu4Y=; b=Fsd/wmc6Rfu7e3DJ6er1BsOSQiw4mFX/FCBE9emt02qhCFRNytd70hgc7mm9USyp9G afLbq+O2/7vunwF2HejZ7/5F+7knRYxRRmlsA6G1rkRcbr3mdZb11NAxn8m9JyLGaVYL dTZmZo7Nc6UiPB3Pd5fOLailqEqRW8z4T7KqJsrQDvtLdFPEl9PaFw+bp1zfNLQveebW oqTxbATPCcqNJ/0qoBuKcXNf+toZmLbXmFJhJVeWIRWg48dOSuhSCiK49TuFhg1FPOBV krvLk/8H7Atpz8DndolD2sUv6z+SNRZTW5EcgtEk+Cj1l/R9p3KJLk34stMyXbwCGcfF qmMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U2VxRtDe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-209528-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209528-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6ea88e288d4si4305776a12.805.2024.06.11.01.57.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 01:57:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209528-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U2VxRtDe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-209528-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209528-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6870628BEB2 for ; Tue, 11 Jun 2024 08:56:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66FF117623B; Tue, 11 Jun 2024 08:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U2VxRtDe" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 480F917556B; Tue, 11 Jun 2024 08:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718096056; cv=none; b=UOGOK3UodhEP60KbPsPTf49o39mQjxSvAc38AwWGwJI0tlpAthaiqYFFOmEtF2cW4SCUlGOEYb2vaIauNcI0n/JYQa47OFnWbITpxCjh5EOqwrOMl/GIb1Ygr0XExb7NbfDIm1a7hr1fvflz2GLY6E6x0sZqk95mY7ewRjN87fE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718096056; c=relaxed/simple; bh=2ukzE5jSByrfkU0EBD6JgAzltjAX1WVjV+wRmSqE2Kk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jwuQpaGUh64qhDQyaAmXR/11In55/5pKPInfkv0+o4M40xz41HjnBGFkLss3mpn2kJ9dvoZrqEqCTUOvweT3iN875Y+EHlgJ3cUcZmZwwkG5J1Okqo9ytXqTs2mYLiVMjctQRnsK8UXJEDyH8Rue9Va1Lx/FCmDY3I/0Awee/Ek= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U2VxRtDe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DF15C2BD10; Tue, 11 Jun 2024 08:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718096055; bh=2ukzE5jSByrfkU0EBD6JgAzltjAX1WVjV+wRmSqE2Kk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=U2VxRtDeYMlPg+12tPprCTkNAGaTrxlhfGvjZ+WlQMIx/7TGa2pX3sQPp6TQV+WYf mv7ii94fVbr8QuJmnvkEYOhLoBvyeo4lahrcRYS2Ablufh5BnJgbcDlQYF13eCI/ZP 9qVnWlZU9KupHrMcPB+QTdSYxeYDZ/ccT75YYaYDTNF+v9mo4LGjn8Uui+hHSjMuMU DnScucgx/dcXir7hjEHrBp5Xlsz2VFHBnNR2h4A4uLjNvfNGAzqx1eEN3Lb9KcEWxh 9l5/qbuc6uT+VYFRUi5xbHfvVq2/eGDuW2D9dy6+ng3sFLGNEgGpOWazHjfPuGkMvz qjkqGaG49zHhg== Date: Tue, 11 Jun 2024 10:54:12 +0200 From: Maxime Ripard To: Dmitry Baryshkov Cc: Hans de Goede , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Clark , Abhinav Kumar , Sean Paul , Marijn Suijten , 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 Message-ID: <20240611-zippy-pragmatic-catfish-cceee5@houat> References: <20240607-bridge-hdmi-connector-v5-0-ab384e6021af@linaro.org> <20240607-bridge-hdmi-connector-v5-2-ab384e6021af@linaro.org> <20240610-secret-rottweiler-from-asgard-132f75@houat> <20240610-smooth-liberal-guan-59853e@houat> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="l7blei7rzdrnpggn" Content-Disposition: inline In-Reply-To: --l7blei7rzdrnpggn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 10, 2024 at 08:54:09PM GMT, Dmitry Baryshkov wrote: > On Mon, Jun 10, 2024 at 02:07:06PM +0200, Maxime Ripard wrote: > > Hi, > >=20 > > +Hans > >=20 > > On Mon, Jun 10, 2024 at 02:46:03PM GMT, Dmitry Baryshkov wrote: > > > On Mon, 10 Jun 2024 at 11:04, Maxime Ripard wrot= e: > > > > > > > > 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 ha= ndled > > > > > by the drm_connector_cleanup() and so are safe to be dropped. > > > > > > > > > > Acked-by: Maxime Ripard > > > > > Signed-off-by: Dmitry Baryshkov > > > > > --- > > > > > 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 > > > > > #include > > > > > #include > > > > > +#include > > > > > #include > > > > > #include > > > > > > > > > > @@ -193,19 +194,6 @@ drm_bridge_connector_detect(struct drm_conne= ctor *connector, bool force) > > > > > return status; > > > > > } > > > > > > > > > > -static void drm_bridge_connector_destroy(struct drm_connector *c= onnector) > > > > > -{ > > > > > - struct drm_bridge_connector *bridge_connector =3D > > > > > - 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_connect= or *connector, > > > > > struct dentry *root) > > > > > { > > > > > @@ -224,7 +212,6 @@ static const struct drm_connector_funcs drm_b= ridge_connector_funcs =3D { > > > > > .reset =3D drm_atomic_helper_connector_reset, > > > > > .detect =3D drm_bridge_connector_detect, > > > > > .fill_modes =3D drm_helper_probe_single_connector_modes, > > > > > - .destroy =3D drm_bridge_connector_destroy, > > > > > .atomic_duplicate_state =3D drm_atomic_helper_connector_dup= licate_state, > > > > > .atomic_destroy_state =3D drm_atomic_helper_connector_destr= oy_state, > > > > > .debugfs_init =3D drm_bridge_connector_debugfs_init, > > > > > @@ -328,7 +315,7 @@ struct drm_connector *drm_bridge_connector_in= it(struct drm_device *drm, > > > > > int connector_type; > > > > > int ret; > > > > > > > > > > - bridge_connector =3D kzalloc(sizeof(*bridge_connector), GFP= _KERNEL); > > > > > + bridge_connector =3D drmm_kzalloc(drm, sizeof(*bridge_conne= ctor), 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_in= it(struct drm_device *drm, > > > > > return ERR_PTR(-EINVAL); > > > > > } > > > > > > > > > > - ret =3D drm_connector_init_with_ddc(drm, connector, > > > > > - &drm_bridge_connector_fun= cs, > > > > > - connector_type, ddc); > > > > > + ret =3D 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 l= eak 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_han= dle_get too. > > >=20 > > > But drm_connector_cleanup() already contains > > > fwnode_handle_put(connector->fwnode). Isn't that enough? > >=20 > > It does, but now I'm confused. > >=20 > > 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. > >=20 > > 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. >=20 > The mentioned patch documents that pretty clearly: >=20 > * Drivers can set this to associate a fwnode with a connector, drivers > * are expected to get a reference on the fwnode when setting this. > * drm_connector_cleanup() will call fwnode_handle_put() on this. >=20 > This is logical. Whoever sets the drm_connector::fwnode pointer, should > get reference. This way drm_connector_init() doesn't need to play with > the reference counting. The cleanup code drops the reference (so the > driver doesn't need to), because cleanup might be assynchronous.. Right, but it's the cleanup part that isn't logical. It makes total sense to have the connector that sets connector->fwnode get the reference itself. It doesn't make sense to have the core give that reference instead of the driver. It's confusing, because if the driver is supposed to handle its reference itself, then it should handle all of it itself. This bug is the testament for that: the natural approach is buggy. > The drm_bridge_connector follows this approach: it sets > drm_connector->fwnode, so it gets the reference. It uses > drm_connector_cleanup(), so it doesn't need to put it. Yet, it calls fwnode_handle_put in its destroy path, because it grabbed a reference before. Maxime --l7blei7rzdrnpggn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCZmgQtAAKCRDj7w1vZxhR xS5PAP0ecACIdyHVUANOEstpBHZYkKuDtBGi51NuDHKzgPZIVQEAteId7U0SLYEG XjvB4MdtarwH+H3AyHBZF+xD0iHC/Qs= =xPY7 -----END PGP SIGNATURE----- --l7blei7rzdrnpggn--