From patchwork Mon Sep 7 09:53:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 7133381 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DCCC79F314 for ; Mon, 7 Sep 2015 09:48:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0979A206D4 for ; Mon, 7 Sep 2015 09:48:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D7A35206D6 for ; Mon, 7 Sep 2015 09:48:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ABF926E672; Mon, 7 Sep 2015 02:48:54 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by gabe.freedesktop.org (Postfix) with ESMTPS id 018E76E672 for ; Mon, 7 Sep 2015 02:48:52 -0700 (PDT) Received: by wiclk2 with SMTP id lk2so77867707wic.1 for ; Mon, 07 Sep 2015 02:48:51 -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:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=3P3FYQHkvcvBPGZGgvAcNFu8jTVgAy9BnKojzW1yV1o=; b=aBCF3tU+wbk8R9aHTcYd4lVNcg/6VGkHc5tLnB3Nj0U0k/3KHGqfpd0Ae+VauEqTMT DwTycO+g067WIkuVcc7CnqsAGaDxDV2bu0VBnhSHmdcj7hEjYJuuwB3Yapo6yFvpALG3 /Z8lS5pVsKJ0NCceKfnA2aPjArK2l1M11wqXFYmDf9TKe50B1PXr2RjBIltFDgQFBQwI RdUVVtlSFojNGnmu373NddLiHa63xPchymzXO9AG2IDtRirRj/4lU+uzZZAkX2/8p5VC h+O/kSeiwSHElPgHwx7CIMDzL5J6tPlUU3r4o2/V9OJwJ+EBjr3VqeuLmy0JPIOrLvvx N6sg== X-Received: by 10.194.110.37 with SMTP id hx5mr34248705wjb.149.1441619331233; Mon, 07 Sep 2015 02:48:51 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by smtp.gmail.com with ESMTPSA id m6sm1931027wje.6.2015.09.07.02.48.49 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Sep 2015 02:48:50 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 2/2] xf86drmMode: smoke-test the atomic API Date: Mon, 7 Sep 2015 10:53:06 +0100 Message-Id: <1441619586-12098-2-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1441619586-12098-1-git-send-email-emil.l.velikov@gmail.com> References: <1441619586-12098-1-git-send-email-emil.l.velikov@gmail.com> MIME-Version: 1.0 Cc: emil.l.velikov@gmail.com, Rob Clark , Daniel Stone X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 As going through the modetest patches for atomic support I've noticed that if we pass NULL for the drmModeAtomicReqPtr argument we'll crash. So let's handle things appropriately if the user forgot to check the return value of drmModeAtomicAlloc and drmModeAtomicDuplicate or made a typo somewhere along the way. Cc: Ville Syrjälä Cc: Rob Clark Cc: Daniel Stone Signed-off-by: Emil Velikov --- xf86drmMode.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/xf86drmMode.c b/xf86drmMode.c index 23800dd..ab6b519 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -1189,6 +1189,9 @@ drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old) { drmModeAtomicReqPtr new; + if (!old) + return NULL; + new = drmMalloc(sizeof *new); if (!new) return NULL; @@ -1213,6 +1216,9 @@ drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old) int drmModeAtomicMerge(drmModeAtomicReqPtr base, drmModeAtomicReqPtr augment) { + if (!base) + return -EINVAL; + if (!augment || augment->cursor == 0) return 0; @@ -1239,12 +1245,15 @@ int drmModeAtomicMerge(drmModeAtomicReqPtr base, drmModeAtomicReqPtr augment) int drmModeAtomicGetCursor(drmModeAtomicReqPtr req) { + if (!req) + return -EINVAL; return req->cursor; } void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor) { - req->cursor = cursor; + if (req) + req->cursor = cursor; } int drmModeAtomicAddProperty(drmModeAtomicReqPtr req, @@ -1252,6 +1261,9 @@ int drmModeAtomicAddProperty(drmModeAtomicReqPtr req, uint32_t property_id, uint64_t value) { + if (!req) + return -EINVAL; + if (req->cursor >= req->size_items) { drmModeAtomicReqItemPtr new; @@ -1309,6 +1321,9 @@ int drmModeAtomicCommit(int fd, drmModeAtomicReqPtr req, uint32_t flags, int obj_idx = -1; int ret = -1; + if (!req) + return -EINVAL; + if (req->cursor == 0) return 0;