Signed-off-by: Emil Velikov <emil.l.velikov@xxxxxxxxx> --- 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; -- 2.3.5 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/dri-devel