Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1356456ybt; Thu, 18 Jun 2020 06:55:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV8MpZjM0PeTvV4f82PI5Jjc+BFrPKmjNR+ZYLo6TEIhSld+FJLCYqxrM2paWc7WbWehOa X-Received: by 2002:a05:6402:545:: with SMTP id i5mr4232954edx.179.1592488548420; Thu, 18 Jun 2020 06:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592488548; cv=none; d=google.com; s=arc-20160816; b=HLuLPpx0rH6HxSZHd7VBebuKBSlsNf6n2I5NQNO65dVnNhS7WTFxS+dpF1gmHWaE1h 13Bw6WmIr3VTvN8KceaCsdD095bE7ztPXuGkOLT1GQ63Hy0u+nE0zrsL5N2ISS24NOFe BxuVxVrYsFsPk5O8/B7lnNTju9zOGxj1kVFp2y51zUwF8n/TXrfv4n+26rcn4o3MagJY 5uK86AR0jErtEu7Udh19rvH/2bsuU2iNV6NbyQyQRtnZbgTL+XLk9Gngt/qsJLpkr3qi QZJT/FTaUX8Cp83Ans9jN30oLyQypzpNWI2aMTtdqFiqMDJhpN+0POy/tSHBrrulrJ10 nNMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject; bh=LhfDa7t4LseCFiTBV5p1/wYrNgYy7A8IaUDkch1h+FI=; b=iWv0MPwnVqb1NOwq3p6/ANI4o15EvbD/5o0uaZesPfjFoKjgUzYellIUBeZq80iYyi OTozYN8cpNbO6wUnABoxgBGJzMXJl+cA6vEgYvTGx7zpUNaZ9VTAHrILLjkNpw0ExULU TGWaSdXthI08Y4FJfElL7yluOCWJwsc6BeFocKAcaFp6tV27oQ0vvjxmZOW3ArROFYCC eyKTqmLWqc9cbWRKwEOYtob5PSYWT1uKRM5mQnHkIR8fhWJJ/ugy7qR/IxbmiAJfp5d6 TqhGtyhfOsaV4tgGrA3EnNnyhgK+K4gC3TjwmpG9DxndsTr1leB7GMcwQKvfljDtgMvZ VkFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt2si2547046ejc.596.2020.06.18.06.55.26; Thu, 18 Jun 2020 06:55:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730469AbgFRNww (ORCPT + 99 others); Thu, 18 Jun 2020 09:52:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:54724 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730205AbgFRNwi (ORCPT ); Thu, 18 Jun 2020 09:52:38 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9FFD5AB98; Thu, 18 Jun 2020 13:52:33 +0000 (UTC) Subject: Re: [PATCH v2] drm/hisilicon: Code refactoring for hibmc_drv_vdac To: Tian Tao , puck.chen@hisilicon.com, airlied@linux.ie, daniel@ffwll.ch, kraxel@redhat.com, alexander.deucher@amd.com, tglx@linutronix.de, dri-devel@lists.freedesktop.org, xinliang.liu@linaro.org, linux-kernel@vger.kernel.org Cc: linuxarm@huawei.com References: <1586586315-12764-1-git-send-email-tiantao6@hisilicon.com> From: Thomas Zimmermann Autocrypt: addr=tzimmermann@suse.de; keydata= mQENBFs50uABCADEHPidWt974Cax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Hx2Dyoklv5g4BzkgqTqwmaYzsl8UxZKvbaxq0zb ehDda8lvhFXodNFMAgTLJlLuDYOGLK2AwbrS3Sp0AEbkpdJBb44qVlGm5bApZouHeJ/+n+7r 12+lqdsAEQEAAYkBPAQYAQgAJhYhBHIX+6yM6c9jRKFo5WgNwR1TC3ojBQJbOdLgAhsMBQkD wmcAAAoJEGgNwR1TC3ojpfcIAInwP5OlcEKokTnHCiDTz4Ony4GnHRP2fXATQZCKxmu4AJY2 h9ifw9Nf2TjCZ6AMvC3thAN0rFDj55N9l4s1CpaDo4J+0fkrHuyNacnT206CeJV1E7NYntxU n+LSiRrOdywn6erjxRi9EYTVLCHcDhBEjKmFZfg4AM4GZMWX1lg0+eHbd5oL1as28WvvI/uI aMyV8RbyXot1r/8QLlWldU3NrTF5p7TMU2y3ZH2mf5suSKHAMtbE4jKJ8ZHFOo3GhLgjVrBW HE9JXO08xKkgD+w6v83+nomsEuf6C6LYrqY/tsZvyEX6zN8CtirPdPWu/VXNRYAl/lat7lSI 3H26qrE= Message-ID: <21d9f165-3fe9-d0cb-35ce-c91889e7e0dd@suse.de> Date: Thu, 18 Jun 2020 15:52:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <1586586315-12764-1-git-send-email-tiantao6@hisilicon.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="bMq42WMT5VsIyVKShMmg9UM3yjBKvRebk" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --bMq42WMT5VsIyVKShMmg9UM3yjBKvRebk Content-Type: multipart/mixed; boundary="eShotCSXpdcfDQZHiqDDGiBqtaP8lv2Qy"; protected-headers="v1" From: Thomas Zimmermann To: Tian Tao , puck.chen@hisilicon.com, airlied@linux.ie, daniel@ffwll.ch, kraxel@redhat.com, alexander.deucher@amd.com, tglx@linutronix.de, dri-devel@lists.freedesktop.org, xinliang.liu@linaro.org, linux-kernel@vger.kernel.org Cc: linuxarm@huawei.com Message-ID: <21d9f165-3fe9-d0cb-35ce-c91889e7e0dd@suse.de> Subject: Re: [PATCH v2] drm/hisilicon: Code refactoring for hibmc_drv_vdac References: <1586586315-12764-1-git-send-email-tiantao6@hisilicon.com> In-Reply-To: <1586586315-12764-1-git-send-email-tiantao6@hisilicon.com> --eShotCSXpdcfDQZHiqDDGiBqtaP8lv2Qy Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Hi, sorry for letting these patches sit around for so long. I'd say that if you waited for a week or two without further responses, it's ok to ping people. Am 11.04.20 um 08:25 schrieb Tian Tao: > code refactoring for hibmc_drv_vdac.c, no actual function changes. >=20 > v2: > remove the debug message. >=20 > Signed-off-by: Tian Tao > Reviewed-by: Joe Perches > --- > drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 50 +++++++---------= -------- > 1 file changed, 14 insertions(+), 36 deletions(-) >=20 > diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers= /gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c > index 678ac2e..077b7996 100644 > --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c > +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c > @@ -52,32 +52,6 @@ static const struct drm_connector_funcs hibmc_connec= tor_funcs =3D { > .atomic_destroy_state =3D drm_atomic_helper_connector_destroy_state, > }; > =20 > -static struct drm_connector * > -hibmc_connector_init(struct hibmc_drm_private *priv) > -{ > - struct drm_device *dev =3D priv->dev; > - struct drm_connector *connector; > - int ret; > - > - connector =3D devm_kzalloc(dev->dev, sizeof(*connector), GFP_KERNEL);= > - if (!connector) { > - DRM_ERROR("failed to alloc memory when init connector\n"); > - return ERR_PTR(-ENOMEM); > - } > - > - ret =3D drm_connector_init(dev, connector, > - &hibmc_connector_funcs, > - DRM_MODE_CONNECTOR_VGA); > - if (ret) { > - DRM_ERROR("failed to init connector: %d\n", ret); > - return ERR_PTR(ret); > - } > - drm_connector_helper_add(connector, > - &hibmc_connector_helper_funcs); > - > - return connector; > -} > - > static void hibmc_encoder_mode_set(struct drm_encoder *encoder, > struct drm_display_mode *mode, > struct drm_display_mode *adj_mode) > @@ -109,18 +83,9 @@ int hibmc_vdac_init(struct hibmc_drm_private *priv)= > struct drm_connector *connector; > int ret; > =20 > - connector =3D hibmc_connector_init(priv); > - if (IS_ERR(connector)) { > - DRM_ERROR("failed to create connector: %ld\n", > - PTR_ERR(connector)); > - return PTR_ERR(connector); > - } > - > encoder =3D devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL); > - if (!encoder) { > - DRM_ERROR("failed to alloc memory when init encoder\n"); > + if (!encoder) > return -ENOMEM; > - } > =20 > encoder->possible_crtcs =3D 0x1; > ret =3D drm_encoder_init(dev, encoder, &hibmc_encoder_funcs, > @@ -131,6 +96,19 @@ int hibmc_vdac_init(struct hibmc_drm_private *priv)= > } > =20 > drm_encoder_helper_add(encoder, &hibmc_encoder_helper_funcs); > + > + connector =3D devm_kzalloc(dev->dev, sizeof(*connector), GFP_KERNEL);= Overall, the patch seems correct, expect for this line. DRM data structures should now be allocated with drmm_kzalloc() in drm_managed.h. It was added recently. With devm_kzalloc(), the memory will be released when the HW device goes away. If userspace still holds a reference, the driver can segfault. Using drmm_kzalloc() delays the release until the memory is really unused= =2E However, hibmc's modesetting pipeline appears to be always the same. I think you should consider embedding connector and encoder (and crtc) in struct hibmc_drm_private. Would make the code simpler and more robust. Best regards Thomas > + if (!connector) > + return -ENOMEM; > + > + ret =3D drm_connector_init(dev, connector, &hibmc_connector_funcs, > + DRM_MODE_CONNECTOR_VGA); > + if (ret) { > + DRM_ERROR("failed to init connector: %d\n", ret); > + return ret; > + } > + drm_connector_helper_add(connector, &hibmc_connector_helper_funcs); > + > drm_connector_attach_encoder(connector, encoder); > =20 > return 0; >=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 --eShotCSXpdcfDQZHiqDDGiBqtaP8lv2Qy-- --bMq42WMT5VsIyVKShMmg9UM3yjBKvRebk Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEchf7rIzpz2NEoWjlaA3BHVMLeiMFAl7rcZ0ACgkQaA3BHVML eiP9QggAptYdaNLZREzAwQ3D109OpCD7FmzN610r8cAnUtL3w2FycjP1iGWhO4UY NmdwmKhgVXeQnCp0jrjcZL75cAGgCZA4XRvOrqWES5yoFaMJ3U9ziZ3+nb1e/gUy okypHn07qNZjdnksbSKgko4u04aS6KLOgskSZubTHlZeKgPbjkw9UnJIaLMXnNHX XNI4pRuB5oRkuply7DqzXmKlLu4J8n/s7J2y1mlXLFaQFhOM4Hlb/4XI1g1R2XyX NU4IDle8BPpCt5LajQZctcYz8SyNVIbeCOTIZ9LouohgjzJoa7VFPO1j2AJLi9dr jDD6ODlT8W8/uOlYsrhidr1dEu67WQ== =ZHIf -----END PGP SIGNATURE----- --bMq42WMT5VsIyVKShMmg9UM3yjBKvRebk--