From patchwork Wed Apr 24 13:13:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 10914715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D79DE13B5 for ; Wed, 24 Apr 2019 13:14:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8AEA289B5 for ; Wed, 24 Apr 2019 13:14:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD35C28ADE; Wed, 24 Apr 2019 13:14:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BF98028A84 for ; Wed, 24 Apr 2019 13:14:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 64C4F892CB; Wed, 24 Apr 2019 13:14:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B193892CB for ; Wed, 24 Apr 2019 13:14:11 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id q16so4527170wmj.3 for ; Wed, 24 Apr 2019 06:14:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=J8qWjC17CdJYRqhzFhIPuaKkf1U3hmYPn8JGqQcjU8M=; b=PebgwndLP/ez7j5MzFxHNQJeohx+ws+Z01TmpxH//HlMCdfHvjfIyoH3pT0nYU19JQ tq7vPVVB4lYTCm5G6/lgi1OthdGyvVjlX8cyScxnatc+tfTCa7OlxCQajdVd9VJXwp38 Q16FUMBPyM/iogGGc+Cl2PlMhFZG840n9znSRxzsQlnhnXoAffh5tAsFBY0npt5rDEEc lDk6Toy2FnF7Mic3uDMbfl116RpnDDzAnzWiZWE0CndfIF8yMacDsfFwG7xHOEvM44In oGQ0xqk9uPSCtXU/L3veSZhgpqLHFTufN0zyT1sfS57Xm/b46ZonPO9IvVLmF+I3+EPP X7MQ== X-Gm-Message-State: APjAAAU+ikpDj5YnSfwnxUAZeHtkCfH5xTzSI8aCctThEGDd6skF9zTw +CwfQwOJrgEt/Hj8Xd6qCa86FcTF X-Google-Smtp-Source: APXvYqw2Z0RbIoNJ2Ur+pO1IOhimFPUfVaa5hdKE8ZWejg92xSfiWkO/pE0ACDVCsCuB0sk2LAIkFg== X-Received: by 2002:a1c:cb0f:: with SMTP id b15mr6475340wmg.88.1556111650088; Wed, 24 Apr 2019 06:14:10 -0700 (PDT) Received: from cizrna.cbg.collabora.co.uk ([109.72.12.5]) by smtp.gmail.com with ESMTPSA id r18sm29355218wme.18.2019.04.24.06.14.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 06:14:09 -0700 (PDT) From: Tomeu Vizoso To: linux-kernel@vger.kernel.org Subject: [PATCH] drm/panfrost: Add sanity checks to submit IOCTL Date: Wed, 24 Apr 2019 15:13:53 +0200 Message-Id: <20190424131355.62817-1-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J8qWjC17CdJYRqhzFhIPuaKkf1U3hmYPn8JGqQcjU8M=; b=CaRl0vtcX8Mf/mRrkgyrA7GRkjr0zmIm9LhtwWG8n0aoChBVa9TpXaO7On3qoK1CeN ismOcNcJqgCrMJBdKN88zcyRVuzmb1hyeaS00DeM0Xgb0Igy+fek7D7IYhiR3LXTzHI7 KTxHGMPDsxdJnai54FQ3++LDjVr2CDUmhvpDMbjw/hhAa6Yf4AXqmWr2+0TMjfFY1y4K /XKJ/I69XI+n2TJdPkxVxwOh5B9VOhjbgtQDJF/pMjJ61m2xEt3IamAOXFItUEd5Bv5A ziPYdtv5CYyDRDn/JLdq2pEGw4ju66N0AZypVVns7BxHD6Rg1Bmg72ZpcNWfdfJZEMso hHgA== 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: David Airlie , dri-devel@lists.freedesktop.org, Tomeu Vizoso Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP So userspace can get feedback on any error conditions, instead of going ahead and things breaking later. Signed-off-by: Tomeu Vizoso --- drivers/gpu/drm/panfrost/panfrost_drv.c | 35 +++++++++++++++++-------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index c06af78ab833..0f2863cb8077 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -172,13 +172,27 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data, { struct panfrost_device *pfdev = dev->dev_private; struct drm_panfrost_submit *args = data; - struct drm_syncobj *sync_out; + struct drm_syncobj *sync_out = NULL; struct panfrost_job *job; int ret = 0; + if (!args->jc) + return -EINVAL; + + if (args->requirements && args->requirements != PANFROST_JD_REQ_FS) + return -EINVAL; + + if (args->out_sync > 0) { + sync_out = drm_syncobj_find(file, args->out_sync); + if (!sync_out) + return -ENODEV; + } + job = kzalloc(sizeof(*job), GFP_KERNEL); - if (!job) - return -ENOMEM; + if (!job) { + ret = -ENOMEM; + goto fail_out_sync; + } kref_init(&job->refcount); @@ -190,25 +204,24 @@ static int panfrost_ioctl_submit(struct drm_device *dev, void *data, ret = panfrost_copy_in_sync(dev, file, args, job); if (ret) - goto fail; + goto fail_job; ret = panfrost_lookup_bos(dev, file, args, job); if (ret) - goto fail; + goto fail_job; ret = panfrost_job_push(job); if (ret) - goto fail; + goto fail_job; /* Update the return sync object for the job */ - sync_out = drm_syncobj_find(file, args->out_sync); - if (sync_out) { + if (sync_out) drm_syncobj_replace_fence(sync_out, job->render_done_fence); - drm_syncobj_put(sync_out); - } -fail: +fail_job: panfrost_job_put(job); +fail_out_sync: + drm_syncobj_put(sync_out); return ret; }