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=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 D8839C433E5 for ; Wed, 22 Jul 2020 14:43:54 +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 B75DC20771 for ; Wed, 22 Jul 2020 14:43:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B75DC20771 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de 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 2AC9A89D4F; Wed, 22 Jul 2020 14:43:54 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id DFBF289D4F for ; Wed, 22 Jul 2020 14:43:52 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DC694AC7F; Wed, 22 Jul 2020 14:43:58 +0000 (UTC) Subject: Re: [PATCH] drm/simple_kms_helper: add drmm_simple_encoder_init() To: Philipp Zabel , dri-devel@lists.freedesktop.org References: <20200722132558.28289-1-p.zabel@pengutronix.de> From: Thomas Zimmermann Message-ID: <34224c32-7c17-4c7e-1ec9-03215ec7ed8a@suse.de> Date: Wed, 22 Jul 2020 16:43:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200722132558.28289-1-p.zabel@pengutronix.de> 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: kernel@pengutronix.de Content-Type: multipart/mixed; boundary="===============1621607108==" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --===============1621607108== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="388bGmlDlzZKQ3M202jHkyjRoPXgGkctO" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --388bGmlDlzZKQ3M202jHkyjRoPXgGkctO Content-Type: multipart/mixed; boundary="ymr65FRSXqTV8gXjqMXTDGovH9qkRzIru"; protected-headers="v1" From: Thomas Zimmermann To: Philipp Zabel , dri-devel@lists.freedesktop.org Cc: kernel@pengutronix.de Message-ID: <34224c32-7c17-4c7e-1ec9-03215ec7ed8a@suse.de> Subject: Re: [PATCH] drm/simple_kms_helper: add drmm_simple_encoder_init() References: <20200722132558.28289-1-p.zabel@pengutronix.de> In-Reply-To: <20200722132558.28289-1-p.zabel@pengutronix.de> --ymr65FRSXqTV8gXjqMXTDGovH9qkRzIru Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Hi Am 22.07.20 um 15:25 schrieb Philipp Zabel: > Add a drm_simple_encoder_init() variant that registers > drm_encoder_cleanup() with drmm_add_action(). >=20 > Now drivers can store encoders in memory allocated with drmm_kmalloc() > after the call to drmm_mode_config_init(), without having to manually > make sure that drm_encoder_cleanup() is called before the memory is > freed. >=20 > Signed-off-by: Philipp Zabel > --- > drivers/gpu/drm/drm_simple_kms_helper.c | 42 +++++++++++++++++++++++++= > include/drm/drm_simple_kms_helper.h | 4 +++ > 2 files changed, 46 insertions(+) >=20 > diff --git a/drivers/gpu/drm/drm_simple_kms_helper.c b/drivers/gpu/drm/= drm_simple_kms_helper.c > index 74946690aba4..a243f00cf63d 100644 > --- a/drivers/gpu/drm/drm_simple_kms_helper.c > +++ b/drivers/gpu/drm/drm_simple_kms_helper.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -71,6 +72,47 @@ int drm_simple_encoder_init(struct drm_device *dev, > } > EXPORT_SYMBOL(drm_simple_encoder_init); > =20 > +static void drmm_encoder_cleanup(struct drm_device *dev, void *ptr) > +{ > + struct drm_encoder *encoder =3D ptr; > + > + drm_encoder_cleanup(encoder); > +} This doesn't work. DRM cleans up the encoder by invoking the destroy callback from the encoder functions. This additional helper would cleanup the encoder a second time. You can already embed the encoder in another structure and things should work as expected. Best regards Thomas > + > +/** > + * drmm_simple_encoder_init - Initialize a preallocated encoder with > + * basic functionality. > + * @dev: drm device > + * @encoder: the encoder to initialize > + * @encoder_type: user visible type of the encoder > + * > + * Initialises a preallocated encoder that has no further functionalit= y. > + * Settings for possible CRTC and clones are left to their initial val= ues. > + * Cleanup is automatically handled through registering drm_encoder_cl= eanup() > + * with drmm_add_action(). > + * > + * The caller of drmm_simple_encoder_init() is responsible for allocat= ing > + * the encoder's memory with drmm_kzalloc() to ensure it is automatica= lly > + * freed after the encoder has been cleaned up. > + * > + * Returns: > + * Zero on success, error code on failure. > + */ > +int drmm_simple_encoder_init(struct drm_device *dev, > + struct drm_encoder *encoder, > + int encoder_type) > +{ > + int ret; > + > + ret =3D drm_encoder_init(dev, encoder, &drm_simple_encoder_funcs_clea= nup, > + encoder_type, NULL); > + if (ret) > + return ret; > + > + return drmm_add_action_or_reset(dev, drmm_encoder_cleanup, encoder); > +} > +EXPORT_SYMBOL(drmm_simple_encoder_init); > + > static enum drm_mode_status > drm_simple_kms_crtc_mode_valid(struct drm_crtc *crtc, > const struct drm_display_mode *mode) > diff --git a/include/drm/drm_simple_kms_helper.h b/include/drm/drm_simp= le_kms_helper.h > index a026375464ff..27f0915599c8 100644 > --- a/include/drm/drm_simple_kms_helper.h > +++ b/include/drm/drm_simple_kms_helper.h > @@ -185,4 +185,8 @@ int drm_simple_encoder_init(struct drm_device *dev,= > struct drm_encoder *encoder, > int encoder_type); > =20 > +int drmm_simple_encoder_init(struct drm_device *dev, > + struct drm_encoder *encoder, > + int encoder_type); > + > #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */ >=20 --=20 Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 N=C3=BCrnberg, Germany (HRB 36809, AG N=C3=BCrnberg) Gesch=C3=A4ftsf=C3=BChrer: Felix Imend=C3=B6rffer --ymr65FRSXqTV8gXjqMXTDGovH9qkRzIru-- --388bGmlDlzZKQ3M202jHkyjRoPXgGkctO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQFIBAEBCAAyFiEEchf7rIzpz2NEoWjlaA3BHVMLeiMFAl8YUKYUHHR6aW1tZXJt YW5uQHN1c2UuZGUACgkQaA3BHVMLeiNLrgf/Xc/Wnh5HraJBp2GOZXNFpjtpiIJX 9pnStnnKywSMfmUs2O+0urX0a/mzYrM+qcPFfBYXQ8H+Dc+qjbsj/SUcWV/Zyn5M pLNsnhvbSMMIkiIE6RDC8XB1NkeRBc8XoJAJHPDjMf+nO0igAQtPZF9zHcShfRPF mlZtrTden7M5EtKbY5rmm8BbWVTwe58XnwZYpcz38x5zuVe5UgtRXzUkPv7T8pnx xZ82+8ecmIMA/kWSL7GPJ+kUFiptPQzGb9wJ1SG5CqY8SJqVLv3mvasuH8GVu3Kq 4TpTkxOlm62ec3msfRknrr1pWZ5pqQelz+sWOeCoxsXZv1svNm0ch2sauA== =sQ+1 -----END PGP SIGNATURE----- --388bGmlDlzZKQ3M202jHkyjRoPXgGkctO-- --===============1621607108== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel --===============1621607108==--