From patchwork Wed Apr 15 07:39:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 11489991 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 236B592C for ; Wed, 15 Apr 2020 07:40:48 +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 F3DEB206D9 for ; Wed, 15 Apr 2020 07:40:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="I1pxRNgp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3DEB206D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch 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 244676E86C; Wed, 15 Apr 2020 07:40:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by gabe.freedesktop.org (Postfix) with ESMTPS id A68156E86C for ; Wed, 15 Apr 2020 07:40:42 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id x25so16190748wmc.0 for ; Wed, 15 Apr 2020 00:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cf9NwGBx6o3jxBWNCdD42pM4CebCUY4eRjmnErOMllk=; b=I1pxRNgpnMNAGVS9MVWLJWs2PDkpxJ7TOtZKqdn3I5Oy2sQSt5EwlUm/rjQGyY/dU5 6svp4ht0Hb85H6dQce8SnS2+o0ZHCtN/TQiE7+PbyFmfDEythLLuC9xr48yF4JTexu2T yQCJiMm8UYyS9SO9ZFT2g4UJjdcasgByEy1JA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cf9NwGBx6o3jxBWNCdD42pM4CebCUY4eRjmnErOMllk=; b=Xbb5OHMd1Hm+C6/BRwWylkWTjirRrS6JuShM5uQggEWeb7h6jIL9mkiLDhhbQ4XgPH XvjY2Ai2x8cBBDxhkvLztSQqkNiPbbp3YVXIlBmMv9VA58kf8j6s8beme/B1y09+kz3N FYcl322F/D4V3n80b3Ary+Xu1dZkBDPkkXd77RkuCjwBpM6vhmMXhc/O9FTlQ0c2MMYQ G3tqCxMe7DHvVOcbBVOiFWudlfggnCq2f7pAEY/mns7HGfIlf5LmOPEYLo3QJFzbpknC WTdKLdRuSoqztrDt1WVjdA5wRC6SrxTeklMbRVv0xFYdUaB+QkjBvZLrYbnQ6LBNeVko Fb1Q== X-Gm-Message-State: AGi0Pub7CuVAGnXdVWLPTHy//PdNbgEE3ZSHhugz2itAB5woLnGAPtgD sNHBQfRJH7Rr3oVqKa1BCg2FxA== X-Google-Smtp-Source: APiQypKtdeZJsJPPCQbp2xqNDdClupl931WYZeEUPHbtaVb5m6SQKZkj+F94hXuoA3/scH6lppYVBg== X-Received: by 2002:a05:600c:225a:: with SMTP id a26mr3810248wmm.104.1586936441311; Wed, 15 Apr 2020 00:40:41 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id u30sm1878552wru.13.2020.04.15.00.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 00:40:40 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Subject: [PATCH 01/59] drm: Add devm_drm_dev_alloc macro Date: Wed, 15 Apr 2020 09:39:36 +0200 Message-Id: <20200415074034.175360-2-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200415074034.175360-1-daniel.vetter@ffwll.ch> References: <20200415074034.175360-1-daniel.vetter@ffwll.ch> MIME-Version: 1.0 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: Daniel Vetter , DRI Development , Paul Kocialkowski , Laurent Pinchart , Daniel Vetter , Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a new macro helper to combine the usual init sequence in drivers, consisting of a kzalloc + devm_drm_dev_init + drmm_add_final_kfree triplet. This allows us to remove the rather unsightly drmm_add_final_kfree from all currently merged drivers. The kerneldoc is only added for this new function. Existing kerneldoc and examples will be udated at the very end, since once all drivers are converted over to devm_drm_dev_alloc we can unexport a lot of interim functions and make the documentation for driver authors a lot cleaner and less confusing. There will be only one true way to initialize a drm_device at the end of this, which is going to be devm_drm_dev_alloc. v2: - Actually explain what this is for in the commit message (Sam) - Fix checkpatch issues (Sam) Acked-by: Noralf Trønnes Cc: Noralf Trønnes Reviewed-by: Sam Ravnborg Cc: Sam Ravnborg Cc: Paul Kocialkowski Cc: Laurent Pinchart Signed-off-by: Daniel Vetter Reviewed-by: Thomas Zimmermann --- drivers/gpu/drm/drm_drv.c | 23 +++++++++++++++++++++++ include/drm/drm_drv.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 1bb4f636b83c..8e1813d2a12e 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -739,6 +739,29 @@ int devm_drm_dev_init(struct device *parent, } EXPORT_SYMBOL(devm_drm_dev_init); +void *__devm_drm_dev_alloc(struct device *parent, struct drm_driver *driver, + size_t size, size_t offset) +{ + void *container; + struct drm_device *drm; + int ret; + + container = kzalloc(size, GFP_KERNEL); + if (!container) + return ERR_PTR(-ENOMEM); + + drm = container + offset; + ret = devm_drm_dev_init(parent, drm, driver); + if (ret) { + kfree(container); + return ERR_PTR(ret); + } + drmm_add_final_kfree(drm, container); + + return container; +} +EXPORT_SYMBOL(__devm_drm_dev_alloc); + /** * drm_dev_alloc - Allocate new DRM device * @driver: DRM driver to allocate device for diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index e7c6ea261ed1..f07f15721254 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -626,6 +626,39 @@ int devm_drm_dev_init(struct device *parent, struct drm_device *dev, struct drm_driver *driver); +void *__devm_drm_dev_alloc(struct device *parent, struct drm_driver *driver, + size_t size, size_t offset); + +/** + * devm_drm_dev_alloc - Resource managed allocation of a &drm_device instance + * @parent: Parent device object + * @driver: DRM driver + * @type: the type of the struct which contains struct &drm_device + * @member: the name of the &drm_device within @type. + * + * This allocates and initialize a new DRM device. No device registration is done. + * Call drm_dev_register() to advertice the device to user space and register it + * with other core subsystems. This should be done last in the device + * initialization sequence to make sure userspace can't access an inconsistent + * state. + * + * The initial ref-count of the object is 1. Use drm_dev_get() and + * drm_dev_put() to take and drop further ref-counts. + * + * It is recommended that drivers embed &struct drm_device into their own device + * structure. + * + * Note that this manages the lifetime of the resulting &drm_device + * automatically using devres. The DRM device initialized with this function is + * automatically put on driver detach using drm_dev_put(). + * + * RETURNS: + * Pointer to new DRM device, or ERR_PTR on failure. + */ +#define devm_drm_dev_alloc(parent, driver, type, member) \ + ((type *) __devm_drm_dev_alloc(parent, driver, sizeof(type), \ + offsetof(type, member))) + struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct device *parent); int drm_dev_register(struct drm_device *dev, unsigned long flags);