summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2015-04-28 13:25:24 +0100
committerEmil Velikov <emil.l.velikov@gmail.com>2015-05-28 15:40:16 +0100
commit128344c2cf22385dedece5a3d774d3a24527d2de (patch)
tree6dca103101b4833145dce656f4de3cf08c0ab58f
parentc78917ee4fe6c787a5de9aaccc5319fdffc9a354 (diff)
modetest: replace malloc + memset with calloc
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--tests/modetest/buffers.c2
-rw-r--r--tests/modetest/modetest.c27
2 files changed, 10 insertions, 19 deletions
diff --git a/tests/modetest/buffers.c b/tests/modetest/buffers.c
index 7e214e85..0b09cfc3 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 e4a8bbca..57be810b 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;