From patchwork Mon Nov 27 10:07:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 841575 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YBA5ufMz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yljDj4hQNz9s9Y for ; Mon, 27 Nov 2017 21:08:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751277AbdK0KIf (ORCPT ); Mon, 27 Nov 2017 05:08:35 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:37611 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752145AbdK0KIQ (ORCPT ); Mon, 27 Nov 2017 05:08:16 -0500 Received: by mail-wr0-f195.google.com with SMTP id k61so25816140wrc.4 for ; Mon, 27 Nov 2017 02:08:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L+4txCF5yLVxPAj5fNGxbdVkR4fmFTk+7Yd4mqsJFF4=; b=YBA5ufMzHwFsNTJ6eGsODBi4/IwZDgBEs3lO9O5EhF3wRXhEpMmX+2hEbZlMBySzfp EIQR7q1HAfp1R3uL6AY4pHn1wPjxKyneQxr2QHGdehbGOZZKtkjQPhcLCqy1hUfU5AmB 9p57GcjqGH2QIxpsP1Zu/7D26KwsWXnpDAhccOEXtSLld1L5T5G63+gyE9oFS5SMZ/+y XIpeg6jAeh68Kv1mRkT+loy72G60vH25wSPvGe/mNTZXPkY7tmGCDkOXVhYD29p9+F6X m1ZiJ00OJh9ZPjoSZhm9y9vtxaCIw/uPBycBbzDnY1Me2xnw0E7nZ0wQ3s1u8Vvq312l MU7w== 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; bh=L+4txCF5yLVxPAj5fNGxbdVkR4fmFTk+7Yd4mqsJFF4=; b=XXU3JdngFAfVXXWcZR5aqCJJPCGtPdvAD58JN+uU7c4SyFkCMMpnXRs6i9KsDctbVv HYTRJGOpwz9viIjGOw8tMv01U5bYQOHgxf4hAs5T7oR/al9F6w98gVthV1akvUY/XQEA mug1rWcrEpBNi7Hv5x+kjCoRYgtS2sYRpHWBPfu6kk4JwGgkrM5qaz+MZUKVvDzJcl/M P+Ob8v43aZ57TUxJ6O7t+bbbieCn1Ev9LLOklkWYI9iEpYZm33WhrSmy+jOMw7km9ZdK 59OnnYMgEaeRwpMk5/gENjsUiqHemioaom8F1HQvha9ziyfnWSw1CmKihNff+J1OBcdV Tvqg== X-Gm-Message-State: AJaThX684N/MWMH9llOhyrQowC5Kg16exJc49/I26XqFAZ4B7Nq2VEzn CkdOhf2UwN710jz/yUEeltA= X-Google-Smtp-Source: AGs4zMa/bq4jhhoR2CKTRxHZU2Y/wcDuY0+LCTG0IWOXJCILLMplrGg/vJ3StacU/XP6Jvdwy6VMtg== X-Received: by 10.223.161.14 with SMTP id o14mr1203789wro.111.1511777294647; Mon, 27 Nov 2017 02:08:14 -0800 (PST) Received: from localhost (p200300E41F200F003F65F430A8AE2E44.dip0.t-ipconnect.de. [2003:e4:1f20:f00:3f65:f430:a8ae:2e44]) by smtp.gmail.com with ESMTPSA id g7sm36229728wra.38.2017.11.27.02.08.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Nov 2017 02:08:14 -0800 (PST) From: Thierry Reding To: Thierry Reding Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org Subject: [PATCH 10/13] drm/tegra: sor: Register debugfs in ->late_register() Date: Mon, 27 Nov 2017 11:07:55 +0100 Message-Id: <20171127100758.22149-11-thierry.reding@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171127100758.22149-1-thierry.reding@gmail.com> References: <20171127100758.22149-1-thierry.reding@gmail.com> Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Thierry Reding The ->late_register() and ->early_unregister() callbacks are called at the right time to make sure userspace only accesses interfaces when it should. Move debugfs registration and unregistration to these callback functions to avoid potential races with userspace. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/sor.c | 53 ++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/drm/tegra/sor.c b/drivers/gpu/drm/tegra/sor.c index f40fc987900c..2fba6c2bd486 100644 --- a/drivers/gpu/drm/tegra/sor.c +++ b/drivers/gpu/drm/tegra/sor.c @@ -183,7 +183,6 @@ struct tegra_sor { struct drm_dp_aux *aux; struct drm_info_list *debugfs_files; - struct drm_minor *minor; const struct tegra_sor_ops *ops; @@ -1256,53 +1255,46 @@ static const struct drm_info_list debugfs_files[] = { { "regs", tegra_sor_show_regs, 0, NULL }, }; -static int tegra_sor_debugfs_init(struct tegra_sor *sor, - struct drm_minor *minor) +static int tegra_sor_late_register(struct drm_connector *connector) { - struct dentry *root = sor->output.connector.debugfs_entry; - unsigned int i; + struct tegra_output *output = connector_to_output(connector); + unsigned int i, count = ARRAY_SIZE(debugfs_files); + struct drm_minor *minor = connector->dev->primary; + struct dentry *root = connector->debugfs_entry; + struct tegra_sor *sor = to_sor(output); int err; sor->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), GFP_KERNEL); - if (!sor->debugfs_files) { - err = -ENOMEM; - goto remove; - } + if (!sor->debugfs_files) + return -ENOMEM; - for (i = 0; i < ARRAY_SIZE(debugfs_files); i++) + for (i = 0; i < count; i++) sor->debugfs_files[i].data = sor; - err = drm_debugfs_create_files(sor->debugfs_files, - ARRAY_SIZE(debugfs_files), - root, minor); + err = drm_debugfs_create_files(sor->debugfs_files, count, root, minor); if (err < 0) goto free; - sor->minor = minor; - return 0; free: kfree(sor->debugfs_files); sor->debugfs_files = NULL; -remove: - debugfs_remove_recursive(root); + return err; } -static void tegra_sor_debugfs_exit(struct tegra_sor *sor) +static void tegra_sor_early_unregister(struct drm_connector *connector) { - struct dentry *root = sor->output.connector.debugfs_entry; - - drm_debugfs_remove_files(sor->debugfs_files, ARRAY_SIZE(debugfs_files), - sor->minor); - sor->minor = NULL; + struct tegra_output *output = connector_to_output(connector); + unsigned int count = ARRAY_SIZE(debugfs_files); + struct tegra_sor *sor = to_sor(output); + drm_debugfs_remove_files(sor->debugfs_files, count, + connector->dev->primary); kfree(sor->debugfs_files); sor->debugfs_files = NULL; - - debugfs_remove_recursive(root); } static void tegra_sor_connector_reset(struct drm_connector *connector) @@ -1355,6 +1347,8 @@ static const struct drm_connector_funcs tegra_sor_connector_funcs = { .destroy = tegra_output_connector_destroy, .atomic_duplicate_state = tegra_sor_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, + .late_register = tegra_sor_late_register, + .early_unregister = tegra_sor_early_unregister, }; static int tegra_sor_connector_get_modes(struct drm_connector *connector) @@ -2347,12 +2341,6 @@ static int tegra_sor_init(struct host1x_client *client) sor->output.encoder.possible_crtcs = 0x3; - if (IS_ENABLED(CONFIG_DEBUG_FS)) { - err = tegra_sor_debugfs_init(sor, drm->primary); - if (err < 0) - dev_err(sor->dev, "debugfs setup failed: %d\n", err); - } - if (sor->aux) { err = drm_dp_aux_attach(sor->aux, &sor->output); if (err < 0) { @@ -2421,9 +2409,6 @@ static int tegra_sor_exit(struct host1x_client *client) clk_disable_unprepare(sor->clk_dp); clk_disable_unprepare(sor->clk); - if (IS_ENABLED(CONFIG_DEBUG_FS)) - tegra_sor_debugfs_exit(sor); - return 0; }