From patchwork Mon Oct 7 11:25:54 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: 175324 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4143466ill; Mon, 7 Oct 2019 04:26:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqx3ZOF/3EB6uosB7yS78bOFxN2ma6Rccn8GyOYn/0sG0YXS7l2e31TA/7GNQHVYmEqZdybA X-Received: by 2002:a17:90b:f11:: with SMTP id br17mr32823835pjb.80.1570447577741; Mon, 07 Oct 2019 04:26:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570447577; cv=none; d=google.com; s=arc-20160816; b=ZdvnvPp9fk7ougNKhOX5Z5nk3LERGvk+WguLiVwN4AaFhf86mEjog01jerdRU0CxJ7 zi7GeJPplrMLYEr0SbkDIoeIkZ6zTYdSm8Hc49R9P8wm9ehEZk0vk8lNlNDNB9btaL0L ZgUd31//mkypRK0fHPFDO41coDIPaZK0MG5YPOdQcqY9sif9L4Pqcwf+G4Y/+DpBijT7 016I2s3kraqftQV4hFr85Tpv/4P/BucU8rsYT+58+ddgE0izVGyEdwKmucj5ZV43QsJV px0IGHpeGHwSSJKI2g6VJZrztPhkh1yVUTj/4yEXuH82KWm+0f7V+u6BwN0V2SDdReF5 IA0w== 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=MbhFYFtXKYppCW9i69n//JrDd1pH4tT7gxLGMgw3RSc=; b=axfZuJweu7yeCipFdBPhaXy1b4O7Hy8wgsqmKZqyJwDoszYuYgwT4vuHo5PwqefS9L k2eW5f0oYx1Uj2N/65lCoLZ/uDF+sMlgHsr0D9ZbIVWNpJdhqyj5YlYf82ScEvq6mnS8 xUBzhjppwbP9mlXhDVxCrxAzijeHyIS+yzbh9/BXZe5s4Xnae2UCQDXr/iipo5qfRLIy g9oITmfqi/jyLslOQA6vFQvDhBULZu57pt3/4LvE1C55PRNcFES+Lq5WRik0BL33iw5E 7zVoZS2ucMEm945FTvqkdDOxjd+Hu6o4a15SNHbVqf50c/0iUy9/SPd5PVEXAWjLSg3E a9eQ== 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 r10si15629970pfl.141.2019.10.07.04.26.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Oct 2019 04:26:17 -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 6D36F6E56D; Mon, 7 Oct 2019 11:26:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by gabe.freedesktop.org (Postfix) with ESMTPS id 14F0C6E563 for ; Mon, 7 Oct 2019 11:26:11 +0000 (UTC) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x97BQ96o122326; Mon, 7 Oct 2019 06:26:09 -0500 Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x97BQ9pW122338 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 7 Oct 2019 06:26:09 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Mon, 7 Oct 2019 06:26:09 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE102.ent.ti.com (157.170.170.32) 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, 7 Oct 2019 06:26:07 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id x97BQ893059149; Mon, 7 Oct 2019 06:26:08 -0500 From: Jean-Jacques Hiblot To: , , Subject: [PATCH v3 7/8] drm/omap: add omap_gem_validate_flags() Date: Mon, 7 Oct 2019 13:25:54 +0200 Message-ID: <20191007112555.25278-8-jjhiblot@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191007112555.25278-1-jjhiblot@ti.com> References: <20191007112555.25278-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=1570447569; bh=pycRfH8VPF2OS9FSA4yi7t+1mn2Akj4iv8sbt8eEBUQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=crieUR4VTMHOBzx7HS/kyReSWohncGqXpJX3+C7qEvqEM2+PxvYwH8ffXaGYwp5HT NJ5Iykb9zdY+8c1wHhB9yVEERqCJIdMTq4K7bsN/aCwIaRtpOaAQ+w6/QADlN3w/+4 JMtvYtRAIDcM9a0qwnQRWoL9ZYFsNQfhbvaaAUI0= 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, dri-devel@lists.freedesktop.org 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 Reviewed-by: Jean-Jacques Hiblot --- 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 27e0a2f8508a..e518d93ca6df 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem.c +++ b/drivers/gpu/drm/omapdrm/omap_gem.c @@ -1133,6 +1133,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) @@ -1144,13 +1176,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.