From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= Subject: Re: [PATCH 2/6] drm: Add drm_simple_encoder_{init,create}() Date: Fri, 7 Feb 2020 15:36:49 +0100 Message-ID: References: <20200207084135.4524-1-tzimmermann@suse.de> <20200207084135.4524-3-tzimmermann@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20200207084135.4524-3-tzimmermann@suse.de> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" To: Thomas Zimmermann , airlied@linux.ie, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, sam@ravnborg.org, alexander.deucher@amd.com, emil.velikov@collabora.com Cc: spice-devel@lists.freedesktop.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org List-Id: virtualization@lists.linuxfoundation.org Den 07.02.2020 09.41, skrev Thomas Zimmermann: > The simple-encoder helpers initialize an encoder with an empty > implementation. This covers the requirements of most of the existing > DRM drivers. A call to drm_simple_encoder_create() allocates and > initializes an encoder instance, a call to drm_simple_encoder_init() > initializes a pre-allocated instance. > > Signed-off-by: Thomas Zimmermann > --- > drivers/gpu/drm/drm_encoder.c | 116 ++++++++++++++++++++++++++++++++++ > include/drm/drm_encoder.h | 10 +++ > 2 files changed, 126 insertions(+) > > diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c > +/** > + * drm_simple_encoder_create - Allocate and initialize an encoder > + * @dev: drm device > + * @encoder_type: user visible type of the encoder > + * @name: printf style format string for the encoder name, or NULL for > + * default name > + * > + * Allocates and initialises an encoder that has no further functionality. The > + * encoder will be released automatically. > + * > + * Returns: > + * The encoder on success, a pointer-encoder error code on failure. > + */ > +struct drm_encoder *drm_simple_encoder_create(struct drm_device *dev, > + int encoder_type, > + const char *name, ...) > +{ > + char *namestr = NULL; > + struct drm_encoder *encoder; > + int ret; > + > + encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL); The encoder can outlive the devres if the device is unbound when userspace has open fds, so you can't use devm_ here. Noralf. > + if (!encoder) > + return ERR_PTR(-ENOMEM); > + > + if (name) { > + va_list ap; > + > + va_start(ap, name); > + namestr = kvasprintf(GFP_KERNEL, name, ap); > + va_end(ap); > + if (!namestr) { > + ret = -ENOMEM; > + goto err_devm_kfree; > + } > + } > + > + ret = __drm_encoder_init(dev, encoder, > + &drm_simple_encoder_funcs_destroy, > + encoder_type, namestr); > + if (ret) > + goto err_kfree; > + > + return encoder; > + > +err_kfree: > + if (name) > + kfree(namestr); > +err_devm_kfree: > + devm_kfree(dev->dev, encoder); > + return ERR_PTR(ret); > +} > +EXPORT_SYMBOL(drm_simple_encoder_create); > + 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=-8.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 0B68EC35242 for ; Fri, 7 Feb 2020 14:37:02 +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 C703620720 for ; Fri, 7 Feb 2020 14:37:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=tronnes.org header.i=@tronnes.org header.b="fDjZZd5T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C703620720 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=tronnes.org 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 480196FCDA; Fri, 7 Feb 2020 14:37:00 +0000 (UTC) Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 602766FCDA for ; Fri, 7 Feb 2020 14:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org ; s=ds201912; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=66b7XSZ892In4dZ1AtrKGUvL65iL8vLWanZ6tyoqMyM=; b=fDjZZd5Te5Rl4u+13tgU7fo1yE t0hdo1JSajVqq/0GyXpgPjWr34xG0ck/qHXuXiA7BaXEPZxkZZvu9kz5/vtschpCjAz7mRdZ4JU5e /t4JvBnn+8BAMawK/EUP+Vg1Ttqw1XX/RAYzuW5B5QxNmYPcryDzcYiYufL2aprt5aRlaTwFRXRuh sM1UBRz6YgGBCjioJvSrIzeD7TRHbIGNodRufiOFereFgTYpnypEcRxgkzhu+SEhiqA+vFvgWfxux GmOh6bF5tlYq2gGIvRAOvc4T2fjbsWcNlW0SZJEIwxKsVgLgGQfdyjIfn3nlg12KrAhyWuEviug7A hZq/uDJg==; Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:54428 helo=[192.168.10.61]) by smtp.domeneshop.no with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j04kb-0006FI-2F; Fri, 07 Feb 2020 15:36:57 +0100 Subject: Re: [PATCH 2/6] drm: Add drm_simple_encoder_{init,create}() To: Thomas Zimmermann , airlied@linux.ie, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, sam@ravnborg.org, alexander.deucher@amd.com, emil.velikov@collabora.com References: <20200207084135.4524-1-tzimmermann@suse.de> <20200207084135.4524-3-tzimmermann@suse.de> From: =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= Message-ID: Date: Fri, 7 Feb 2020 15:36:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: <20200207084135.4524-3-tzimmermann@suse.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: spice-devel@lists.freedesktop.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Den 07.02.2020 09.41, skrev Thomas Zimmermann: > The simple-encoder helpers initialize an encoder with an empty > implementation. This covers the requirements of most of the existing > DRM drivers. A call to drm_simple_encoder_create() allocates and > initializes an encoder instance, a call to drm_simple_encoder_init() > initializes a pre-allocated instance. > > Signed-off-by: Thomas Zimmermann > --- > drivers/gpu/drm/drm_encoder.c | 116 ++++++++++++++++++++++++++++++++++ > include/drm/drm_encoder.h | 10 +++ > 2 files changed, 126 insertions(+) > > diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c > +/** > + * drm_simple_encoder_create - Allocate and initialize an encoder > + * @dev: drm device > + * @encoder_type: user visible type of the encoder > + * @name: printf style format string for the encoder name, or NULL for > + * default name > + * > + * Allocates and initialises an encoder that has no further functionality. The > + * encoder will be released automatically. > + * > + * Returns: > + * The encoder on success, a pointer-encoder error code on failure. > + */ > +struct drm_encoder *drm_simple_encoder_create(struct drm_device *dev, > + int encoder_type, > + const char *name, ...) > +{ > + char *namestr = NULL; > + struct drm_encoder *encoder; > + int ret; > + > + encoder = devm_kzalloc(dev->dev, sizeof(*encoder), GFP_KERNEL); The encoder can outlive the devres if the device is unbound when userspace has open fds, so you can't use devm_ here. Noralf. > + if (!encoder) > + return ERR_PTR(-ENOMEM); > + > + if (name) { > + va_list ap; > + > + va_start(ap, name); > + namestr = kvasprintf(GFP_KERNEL, name, ap); > + va_end(ap); > + if (!namestr) { > + ret = -ENOMEM; > + goto err_devm_kfree; > + } > + } > + > + ret = __drm_encoder_init(dev, encoder, > + &drm_simple_encoder_funcs_destroy, > + encoder_type, namestr); > + if (ret) > + goto err_kfree; > + > + return encoder; > + > +err_kfree: > + if (name) > + kfree(namestr); > +err_devm_kfree: > + devm_kfree(dev->dev, encoder); > + return ERR_PTR(ret); > +} > +EXPORT_SYMBOL(drm_simple_encoder_create); > + _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel