From patchwork Wed Jul 3 15:55:35 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: 168458 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1913068ilk; Thu, 4 Jul 2019 00:26:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyIL2tHGiLN4rENTE9byL2bQONEeoviVCEP+F0O3g4nKA8D6pDz1H03oAYDirIvMgHmHCT X-Received: by 2002:a65:5901:: with SMTP id f1mr41364759pgu.84.1562225218075; Thu, 04 Jul 2019 00:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562225218; cv=none; d=google.com; s=arc-20160816; b=0MBilRZpNvTJt3B4Mm3u7z1Lh+9jQxBgAY2d1wm8uUnVEVi+RbsS2ZMMs230+r3A9Y eqdTvzHn7U4wXADCjsCSqN/ks5q19Gp5s/3DL5dlKmbLx/5qvZfrv1haUrHZV9vhnDaG oSAjiNa9O6fYcOeQJ8ZCYTPMF6mk6I05hTY/JGZarls4fKTteLGPTiezyhkPosP3ZNAS OVlB5tz8ocHcc73RTwb1lbwgRj8ElrR8o+eisOaaUox6oqMsUzuTIZ8XVz3GA/CqT6tX hgjliISU5MDM82lO7xZ77QJThFkCBvvBTe/kZQLqShY8h8QlV33OVI2adsf8U7H2mflA vVQA== 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=7aj6dcitBuaRQVD5ne/0TdD/SVP/wUQJBMIkyNYh3h0=; b=LWIPWpIjKNjFCHBv2LIuS0HeVuckpGxSRJ9G/ux0WYVWUUsBAUkBtYAJYEmn3GyYOZ 6veNkIlGC1s+i91WSEbulEIs+US/1G+/yKvd2OKb9l2cGQFSnuXgYQtZzifNbiAwxGx3 AEIi04y5ysPWAHZsq52Mj8YCAxFAvfun+s+EfMdW3uPP+F8TDI9IHL3xuTsD7SmKDrGZ zXDc+Jb2gHXdlXk3n84ohjReWazgc1VHEg0VHEC8jzQRAYj2NN9zM272IoqTvBy5Ftcv kAxJB2SnzjgKEIcVwr8FepSwcCbXVh8HzX75lVMKRFkWyADM0uaf6uS+nbl3XO3tx0Oq oa6w== 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 x70si4915062pgd.311.2019.07.04.00.26.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jul 2019 00:26:58 -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 2AC466E2CE; Thu, 4 Jul 2019 07:25:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by gabe.freedesktop.org (Postfix) with ESMTPS id 13A476E175 for ; Wed, 3 Jul 2019 15:55:52 +0000 (UTC) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x63Ftoeq071814; Wed, 3 Jul 2019 10:55:50 -0500 Received: from DFLE105.ent.ti.com (dfle105.ent.ti.com [10.64.6.26]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x63FtopX016540 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 3 Jul 2019 10:55:50 -0500 Received: from DFLE110.ent.ti.com (10.64.6.31) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 3 Jul 2019 10:55:50 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE110.ent.ti.com (10.64.6.31) 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; Wed, 3 Jul 2019 10:55:50 -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 x63FtnHl052650; Wed, 3 Jul 2019 10:55:49 -0500 From: Jean-Jacques Hiblot To: , , , Subject: [PATCH 7/8] drm/omap: add omap_gem_validate_flags() Date: Wed, 3 Jul 2019 17:55:35 +0200 Message-ID: <20190703155536.28339-8-jjhiblot@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190703155536.28339-1-jjhiblot@ti.com> References: <20190703155536.28339-1-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Mailman-Approved-At: Thu, 04 Jul 2019 07:25:13 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1562169350; bh=5iqsAmmbxUMc7EK2WjMB3guYcr3nfMA9sGZSKGIK9fI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=LHR4D4fhjmWwJiWLeYH4uRWX/jic62fOA+CSQTa5UdZnG4KJaCIhHMqeDusRi++Qr vysK6biOXEIusvfi6qbgp1JbRrzTn4Eg2IdYvQ1dNEonPIyhXmS8QVaXH/ZABZzkCe 0FOgileCJOwVDbgjiPcmvXIq3N6WwSVS8gdP7hr4= 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 539eec05b1c2..705403825e9d 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem.c +++ b/drivers/gpu/drm/omapdrm/omap_gem.c @@ -1130,6 +1130,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) @@ -1141,13 +1173,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.