modetest: explicitly zero the newly allocated memory
PATCH 1/3 modetest: explicitly zero the newly allocated memory
--- tests/modetest/modetest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/modetest/modetest.c +3 -3
@@ -1368,8 +1368,6 @@ static int parse_plane(struct plane_arg *plane, const char *p) {char *end; -memset (plane,0 ,sizeof *plane); - plane->crtc_id =strtoul (p, &end,10 );if (*end !=':' )return -EINVAL ;
@@ -1541,11 +1539,11 @@ int main(int argc, char **argv)fprintf (stderr,"memory allocation failed\n" );return 1 ; } +memset (&plane_args[plane_count],0 ,sizeof (*plane_args));if (parse_plane (&plane_args[plane_count], optarg) <0 )usage (argv[0 ]); - plane_args[plane_count].fb_id =0 ; plane_count++;break ;case 'p' :
@@ -1559,6 +1557,7 @@ int main(int argc, char **argv)fprintf (stderr,"memory allocation failed\n" );return 1 ; } +memset (&pipe_args[count],0 ,sizeof (*pipe_args));if (parse_connector (&pipe_args[count], optarg) <0 )usage (argv[0 ]);
@@ -1578,6 +1577,7 @@ int main(int argc, char **argv)fprintf (stderr,"memory allocation failed\n" );return 1 ; } +memset (&prop_args[prop_count],0 ,sizeof (*prop_args));if (parse_property (&prop_args[prop_count], optarg) <0 )usage (argv[0 ]);
Signature · 6 lines
2.3.5 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 modetest: replace malloc + memset with calloc
--- tests/modetest/buffers.c | 2 +- tests/modetest/modetest.c | 27 +++++++++------------------ 2 files changed, 10 insertions(+), 19 deletions(-)
tests/modetest/buffers.c +1 -1
@@ -1022,7 +1022,7 @@ bo_create_dumb(int fd, unsigned int width, unsigned int height, unsigned int bppstruct 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 ;
tests/modetest/modetest.c +9 -18
@@ -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 ;
Signature · 6 lines
2.3.5 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 xf86drm: simplify drmMalloc/drmFree
In reply to Emil Velikov--- xf86drm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
xf86drm.c +2 -6
@@ -140,16 +140,12 @@ void *drmGetHashTable(void)void *drmMalloc (int size) { -void *pt; -if ((pt =malloc (size))) -memset (pt,0 , size); -return pt; +return calloc (1 , size); }void drmFree (void *pt) { -if (pt) -free (pt); +free (pt); }/**
Signature · 6 lines
2.3.5 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH libdrm 3/3] xf86drm: simplify drmMalloc/drmFree
Quoted 1 line · Emil Velikov
Signed-off-by Emil Velikov <[email protected]>
For the series:
Quoted 30 lines
--- xf86drm.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)xf86drm.c +2
-7@@ -140,16 +140,12 @@ void *drmGetHashTable(void)void *drmMalloc (int size) { -void *pt; -if ((pt =malloc (size))) -memset (pt,0 , size); -return pt; +return calloc (1 , size); }void drmFree (void *pt) { -if (pt) -free (pt); +free (pt); }/** -- 2.3.5
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH libdrm 3/3] xf86drm: simplify drmMalloc/drmFree
Quoted 6 lines · Alex Deucher
Quoted 1 line · Emil Velikov
Signed-off-by Emil Velikov <[email protected]>For the series:
Reviewed-by Alex Deucher <[email protected]>
Thank you. I'll give it another day or two before pushing (just in case).
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel