From patchwork Tue Apr 28 14:09:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 6289701 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5FB49BEEE1 for ; Tue, 28 Apr 2015 14:06:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6B09F2039E for ; Tue, 28 Apr 2015 14:06:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6E4782038A for ; Tue, 28 Apr 2015 14:06:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 700F86E5A0; Tue, 28 Apr 2015 07:06:44 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by gabe.freedesktop.org (Postfix) with ESMTP id E5DF66E08E for ; Tue, 28 Apr 2015 07:06:42 -0700 (PDT) Received: by wiun10 with SMTP id n10so30549354wiu.1 for ; Tue, 28 Apr 2015 07:06:42 -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; bh=iyI7Dly58qL3s5dxNqZMmw+QTbIxL0ovJr/tOcWXvI0=; b=06ChrrSV8wtepYc+2sAxKFd+/a6Ljv1kbQurJFBrFFz9vgHekLzMpXkHYFtwY969JR ZDBKOjP7UONEPeHmAU75eZEW/WWF5Tj8oO7Gjj3pFbNDfaO4xloW2xgDBOBG63xePs5+ wCMZATndYnEYtGIFt1ie16coIRXLgaN9oM11EVO01YKOvVrFe7rpB8PS7xSJVHcUepYe JtklNhPkGDx3rBPkqvT+2PN0xqqg0RVEIR0z1KETiNLYcawgujy7EmnnrLCP/eqDedT/ 6hf6Gx6CA9H+1ZIWLe6MldrGLN2AARECc9yb45v7WtsHjnS0aw9s0POW9bC8PnZa0VTK dogQ== X-Received: by 10.180.107.70 with SMTP id ha6mr29784732wib.20.1430230001951; Tue, 28 Apr 2015 07:06:41 -0700 (PDT) Received: from arch-x220.localdomain (cpc12-croy20-2-0-cust52.croy.cable.virginm.net. [82.44.54.53]) by mx.google.com with ESMTPSA id ju2sm16583819wid.12.2015.04.28.07.06.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Apr 2015 07:06:41 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 2/3] modetest: replace malloc + memset with calloc Date: Tue, 28 Apr 2015 15:09:58 +0100 Message-Id: <1430230199-3562-2-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1430230199-3562-1-git-send-email-emil.l.velikov@gmail.com> References: <1430230199-3562-1-git-send-email-emil.l.velikov@gmail.com> Cc: emil.l.velikov@gmail.com 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: , MIME-Version: 1.0 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 Signed-off-by: Emil Velikov --- tests/modetest/buffers.c | 2 +- tests/modetest/modetest.c | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tests/modetest/buffers.c b/tests/modetest/buffers.c index 878b64e..e887fb2 100644 --- a/tests/modetest/buffers.c +++ b/tests/modetest/buffers.c @@ -1022,7 +1022,7 @@ bo_create_dumb(int fd, unsigned int width, unsigned int height, unsigned int bpp struct bo *bo; int ret; - bo = malloc(sizeof(*bo)); + bo = calloc(1, sizeof(*bo)); if (bo == NULL) { fprintf(stderr, "failed to allocate buffer object\n"); return NULL; diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index e4a8bbc..57be810 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -561,12 +561,10 @@ static struct resources *get_resources(struct device *dev) struct resources *res; int i; - res = malloc(sizeof *res); + res = calloc(1, sizeof(*res)); if (res == 0) return NULL; - memset(res, 0, sizeof *res); - drmSetClientCap(dev->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); res->res = drmModeGetResources(dev->fd); @@ -576,19 +574,14 @@ static struct resources *get_resources(struct device *dev) goto error; } - res->crtcs = malloc(res->res->count_crtcs * sizeof *res->crtcs); - res->encoders = malloc(res->res->count_encoders * sizeof *res->encoders); - res->connectors = malloc(res->res->count_connectors * sizeof *res->connectors); - res->fbs = malloc(res->res->count_fbs * sizeof *res->fbs); + res->crtcs = calloc(res->res->count_crtcs, sizeof(*res->crtcs)); + res->encoders = calloc(res->res->count_encoders, sizeof(*res->encoders)); + res->connectors = calloc(res->res->count_connectors, sizeof(*res->connectors)); + res->fbs = calloc(res->res->count_fbs, sizeof(*res->fbs)); if (!res->crtcs || !res->encoders || !res->connectors || !res->fbs) goto error; - memset(res->crtcs , 0, res->res->count_crtcs * sizeof *res->crtcs); - memset(res->encoders, 0, res->res->count_encoders * sizeof *res->encoders); - memset(res->connectors, 0, res->res->count_connectors * sizeof *res->connectors); - memset(res->fbs, 0, res->res->count_fbs * sizeof *res->fbs); - #define get_resource(_res, __res, type, Type) \ do { \ int i; \ @@ -623,8 +616,8 @@ static struct resources *get_resources(struct device *dev) strerror(errno)); \ continue; \ } \ - obj->props_info = malloc(obj->props->count_props * \ - sizeof *obj->props_info); \ + obj->props_info = calloc(obj->props->count_props, \ + sizeof(*obj->props_info)); \ if (!obj->props_info) \ continue; \ for (j = 0; j < obj->props->count_props; ++j) \ @@ -646,12 +639,10 @@ static struct resources *get_resources(struct device *dev) return res; } - res->planes = malloc(res->plane_res->count_planes * sizeof *res->planes); + res->planes = calloc(res->plane_res->count_planes, sizeof(*res->planes)); if (!res->planes) goto error; - memset(res->planes, 0, res->plane_res->count_planes * sizeof *res->planes); - get_resource(res, plane_res, plane, Plane); get_properties(res, plane_res, plane, PLANE); @@ -1313,7 +1304,7 @@ static int parse_connector(struct pipe_arg *pipe, const char *arg) pipe->num_cons++; } - pipe->con_ids = malloc(pipe->num_cons * sizeof *pipe->con_ids); + pipe->con_ids = calloc(pipe->num_cons, sizeof(*pipe->con_ids)); if (pipe->con_ids == NULL) return -1;