From patchwork Mon Jul 8 10:45:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 168612 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp6983089ilk; Mon, 8 Jul 2019 03:45:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFG6IGIfBLW+BS4gS2xdEVW90nPBw2WDOQz1B7tH482eBFvgWEb01gsjpqFvss6q3AIejo X-Received: by 2002:a17:90a:c481:: with SMTP id j1mr24317215pjt.96.1562582744915; Mon, 08 Jul 2019 03:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562582744; cv=none; d=google.com; s=arc-20160816; b=P+379osxEcE1ONShug0nBYbwwPlTiROUpGEV+ABq+GSO/uQRIhvyB32sHrFmZnNGAK 33naxmsFCZVjax1kRLelIHsBz3oK1152owy2+WZTY3UxsqK1hBFnCW2DAwbRe3F1t10W u0A2VdbDbw9vSerwiOIA63mfD7pbwVMLivTj5ZUBFU1WR1/qeuTzavzoOH+uYTP9pcoy YhdIIRM5a6LYWBzQwJbaakCNv+8bE6eYV9xStdbxiN8wa8b5x6ZVY/IaK7SoosEL8pcN hD2e4/NU9KnmM8+V8PF2K+MAfLn/+wBs68xbwtizWgl8yeHt/CPAtkgHtRXiaSJaXVM4 2joQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=JjXOLahFuEpIEhv+Ge+sSS8nO72VPyuwIs1c5/blVqw=; b=hlPcs3IYZ+fK3ARMMnK1nvQvSCWPtra1Htem24hstTuoZW+XAtPkXFLVfKtOm2WEKR HcxnbxMwKV5eMqrjJ6gNLQXhEOUEHdQoXPZ8mszmiqIvscgg2r3Lpm/KlfLDGp36YyhD 4XsN1tS/BO9j3yIGxVKhc4n5ynlx5y+Ad0lV2bTa8Tgj49gKXuX+RWsx+E7AzVXzggTG ekgx5GFQminNNon3B0XT9yfZOZIvsuTdQlmlaUGMqFC8PLeqxrQd27MmMOA5EP/7MKal 4UBw09uSM0k/Ec7JjzbbLSw1Q1bg44jc1ijcOJAIC0HAIk2jmY/2U2sXzALPhDX9ccEO xo5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id l97si17666492pje.6.2019.07.08.03.45.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jul 2019 03:45:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 80D3789C89; Mon, 8 Jul 2019 10:45:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) by gabe.freedesktop.org (Postfix) with ESMTPS id 136A289C82 for ; Mon, 8 Jul 2019 10:45:38 +0000 (UTC) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x68Aja1Q045636; Mon, 8 Jul 2019 05:45:36 -0500 Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x68AjaD2031749 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 8 Jul 2019 05:45:36 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Mon, 8 Jul 2019 05:45:35 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Mon, 8 Jul 2019 05:45:35 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id x68AjYw3052658; Mon, 8 Jul 2019 05:45:35 -0500 From: Jean-Jacques Hiblot To: , , , Subject: [PATCH v2 7/8] drm/omap: add omap_gem_validate_flags() Date: Mon, 8 Jul 2019 12:45:19 +0200 Message-ID: <20190708104520.24217-8-jjhiblot@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190708104520.24217-1-jjhiblot@ti.com> References: <20190708104520.24217-1-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1562582736; bh=6R45qTVqa1K0ls6ScU6rgzv4DoVIhiFBUKSk72AUW5c=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ImhuiSW1r/m8KeLnXOWXeZWZ4CBGK1WfUrCXt2PRUwFoYG0e1FzK7+tuA6wZ4MQ4D PC1SUVpnb1cGbR3xCg87+xh72k377+uzt6HSfJbehPOHmJTQsuQ60HIUqY3dItvEVK g1tMjj8l75C4SqJ6ss8GOYmJWQlC93Y4npE+7G1A= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jsarha@ti.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tomi Valkeinen Add a helper function omap_gem_validate_flags() which validates the omap_bo flags passed from the userspace. Also drop the dev_err() message, as the userspace can cause that at will. Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/omapdrm/omap_gem.c | 40 ++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c index 5c4cdf618347..cafa9d0bf3c1 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem.c +++ b/drivers/gpu/drm/omapdrm/omap_gem.c @@ -1131,6 +1131,38 @@ void omap_gem_free_object(struct drm_gem_object *obj) kfree(omap_obj); } +static bool omap_gem_validate_flags(struct drm_device *dev, u32 flags) +{ + struct omap_drm_private *priv = dev->dev_private; + + switch (flags & OMAP_BO_CACHE_MASK) { + case OMAP_BO_CACHED: + case OMAP_BO_WC: + case OMAP_BO_CACHE_MASK: + break; + + default: + return false; + } + + if (flags & OMAP_BO_TILED_MASK) { + if (!priv->usergart) + return false; + + switch (flags & OMAP_BO_TILED_MASK) { + case OMAP_BO_TILED_8: + case OMAP_BO_TILED_16: + case OMAP_BO_TILED_32: + break; + + default: + return false; + } + } + + return true; +} + /* GEM buffer object constructor */ struct drm_gem_object *omap_gem_new(struct drm_device *dev, union omap_gem_size gsize, u32 flags) @@ -1142,13 +1174,11 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, size_t size; int ret; + if (!omap_gem_validate_flags(dev, flags)) + return NULL; + /* Validate the flags and compute the memory and cache flags. */ if (flags & OMAP_BO_TILED_MASK) { - if (!priv->usergart) { - dev_err(dev->dev, "Tiled buffers require DMM\n"); - return NULL; - } - /* * Tiled buffers are always shmem paged backed. When they are * scanned out, they are remapped into DMM/TILER.