From patchwork Wed Mar 12 20:45:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 3821401 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 64F719F369 for ; Thu, 13 Mar 2014 00:29:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 443F820203 for ; Thu, 13 Mar 2014 00:29:02 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5BCAD20165 for ; Thu, 13 Mar 2014 00:29:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2AEE8FACC9; Wed, 12 Mar 2014 17:28:53 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 2845AFAC61 for ; Wed, 12 Mar 2014 13:44:09 -0700 (PDT) Received: by mail-wi0-f172.google.com with SMTP id hi5so2990617wib.11 for ; Wed, 12 Mar 2014 13:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=CvoK0SRAliZaRBOWBnFWyV7xlsVC5ewe+5yFuaxngZc=; b=mMp4EEf/wLXf4ixoYgtCoQcLJgDhri3kx+wQ2nLiA8svQgzzpFu1pKvP6baJJ+0WLr G0ddu67pXhNScjZ/OyRHYISc7yPClA0MCRLA44AUjhXcqPjOqymdYLY9JWh6cEMP0NCg dLC6+325FeyXjDRF+AS7NrW8/ajs9vHZtGmHnEKKVg4qEaXL9pbCX4MuR6K1VjAK6QJl 5aEiyUAqkFNEgigGap2LM+VVNYLLYTQjzjLSPh8Om32AP+uCHPlhyctRJvB19qwe59Iy oUHIjxWhep25Ik9pH70gO1UdAEa6qjKP9dhmzTRLeKnReqhsp6kN93lLA3QP9B/WkXUN cbXg== X-Received: by 10.180.12.115 with SMTP id x19mr9439724wib.19.1394657048328; Wed, 12 Mar 2014 13:44:08 -0700 (PDT) Received: from localhost.localdomain (cpc20-stap10-2-0-cust563.12-2.cable.virginm.net. [82.20.130.52]) by mx.google.com with ESMTPSA id f3sm1104689wiv.2.2014.03.12.13.44.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Mar 2014 13:44:07 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] nouveau: cleanup error handling during nouveau_device_wrap Date: Wed, 12 Mar 2014 20:45:43 +0000 Message-Id: <1394657145-2638-1-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 1.9.0 X-Mailman-Approved-At: Wed, 12 Mar 2014 17:28:51 -0700 Cc: emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In theory it's possible for any of the nouveau_getparam calls to fail whist the last one being successful. Thus at least one of the following (hard requirements) drmVersion, chipset and vram/gart memory size will be filled with garbage and sent to the userspace drivers. Signed-off-by: Emil Velikov --- nouveau/nouveau.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/nouveau/nouveau.c b/nouveau/nouveau.c index ee7893b..d6013db 100644 --- a/nouveau/nouveau.c +++ b/nouveau/nouveau.c @@ -88,27 +88,32 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev) nvdev->base.fd = fd; ver = drmGetVersion(fd); - if (ver) dev->drm_version = (ver->version_major << 24) | - (ver->version_minor << 8) | - ver->version_patchlevel; + if (!ver) { + ret = -errno; + goto error; + } + + dev->drm_version = (ver->version_major << 24) | + (ver->version_minor << 8) | + ver->version_patchlevel; drmFreeVersion(ver); if ( dev->drm_version != 0x00000010 && (dev->drm_version < 0x01000000 || dev->drm_version >= 0x02000000)) { - nouveau_device_del(&dev); - return -EINVAL; + ret = -EINVAL; + goto error; } ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_CHIPSET_ID, &chipset); - if (ret == 0) + if (ret) + goto error; ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_FB_SIZE, &vram); - if (ret == 0) + if (ret) + goto error; ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_AGP_SIZE, &gart); - if (ret) { - nouveau_device_del(&dev); - return ret; - } + if (ret) + goto error; ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_HAS_BO_USAGE, &bousage); if (ret == 0) @@ -139,6 +144,9 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev) *pdev = &nvdev->base; return 0; +error: + nouveau_device_del(&dev); + return -ret; } int