staging: bcm2835-camera: free first element in array
Subsystems (5)
PATCH 1/1 staging: bcm2835-camera: free first element in array
We should free gdev[0] so the > should be >=.
drivers/staging/media/platform/bcm2835/bcm2835-camera.c +1 -1
@@ -1998,7 +1998,7 @@ static int __init bm2835_mmal_init(void) free_dev:kfree (dev); -for ( ; camera >0 ; camera--) { +for ( ; camera >=0 ; camera--) {bcm2835_cleanup_instance (gdev[camera]); gdev[camera] =NULL ; }
Am 15.02.2017 13:25, schrieb Dan Carpenter:
Quoted 10 lines
We should free gdev[0] so the > should be >=.
Fixes 7b3ad5abf027 ("staging: Import the BCM2835 MMAL-based V4L2 camera driver.")Signed-off-by Dan Carpenter <[email protected]>drivers/staging/media/platform/bcm2835/bcm2835-camera.c +0
-0
drivers/staging/media/platform/bcm2835/bcm2835-camera.c static int __init bm2835_mmal_init(void) · line 2004
Quoted 8 lines
drivers/staging/media/platform/bcm2835/bcm2835-camera.c +1
-1@@ -1998,7 +1998,7 @@ static int __init bm2835_mmal_init(void) free_dev:kfree (dev); -for ( ; camera >0 ; camera--) { +for ( ; camera >=0 ; camera--) {bcm2835_cleanup_instance (gdev[camera]); gdev[camera] =NULL ; }
since we already know that programmers are bad in counting backwards ...
is is possible to change that into std. loop like:
for(i=0, i< camera; i++ {
bcm2835_cleanup_instance(gdev[i]);
gdev[i] = NULL;}
this is way a much more common pattern.
just my 2 cents,
re,
wh
Quoted 24 lines · walter harms
Am 15.02.2017 13:25, schrieb Dan Carpenter:
Quoted 10 lines
We should free gdev[0] so the > should be >=.
Fixes 7b3ad5abf027 ("staging: Import the BCM2835 MMAL-based V4L2 camera driver.")Signed-off-by Dan Carpenter <[email protected]>drivers/staging/media/platform/bcm2835/bcm2835-camera.c +0
-0drivers/staging/media/platform/bcm2835/bcm2835-camera.c static int __init bm2835_mmal_init(void) · line 2004
Quoted 8 lines
drivers/staging/media/platform/bcm2835/bcm2835-camera.c +1
-1@@ -1998,7 +1998,7 @@ static int __init bm2835_mmal_init(void) free_dev:kfree (dev); -for ( ; camera >0 ; camera--) { +for ( ; camera >=0 ; camera--) {bcm2835_cleanup_instance (gdev[camera]); gdev[camera] =NULL ; }since we already know that programmers are bad in counting backwards ...
Quoted 8 lines
is is possible to change that into std. loop like:
for(i=0, i< camera; i++ { bcm2835_cleanup_instance(gdev[i]); gdev[i] = NULL;}
this is way a much more common pattern.
Hm... My patch is buggy. It frees the wong thing on the first iteration through the loop. I'll resend.
regards,
dan carpenter
PATCH v2 1/1 staging: bcm2835-camera: fix error handling in init
In reply to walter harmsThe unwinding here isn't right. We don't free gdev[0] and instead free 1 step past what was allocated. Also we can't allocate "dev" then we should unwind instead of returning directly.
---
v2: Change the style to make Walter Harms happy. Fix some additional
bugs I missed in the first patch.
drivers/staging/media/platform/bcm2835/bcm2835-camera.c +9 -5
@@ -1901,6 +1901,7 @@ static int __init bm2835_mmal_init(void)unsigned int num_cameras;struct vchiq_mmal_instance *instance;unsigned int resolutions[MAX_BCM2835_CAMERAS ][2 ]; +int i; ret =vchiq_mmal_init (&instance);if (ret <0 )
@@ -1914,8 +1915,10 @@ static int __init bm2835_mmal_init(void)for (camera =0 ; camera < num_cameras; camera++) { dev =kzalloc (sizeof (struct bm2835_mmal_dev ),GFP_KERNEL ); -if (!dev) -return -ENOMEM ; +if (!dev) { + ret = -ENOMEM ; + goto cleanup_gdev; + } dev->camera_num = camera; dev->max_width = resolutions[camera][0 ];
@@ -1998,9 +2001,10 @@ static int __init bm2835_mmal_init(void) free_dev:kfree (dev); -for ( ; camera >0 ; camera--) { -bcm2835_cleanup_instance (gdev[camera]); - gdev[camera] =NULL ; +cleanup_gdev: +for (i =0 ; i < camera; i++) { +bcm2835_cleanup_instance (gdev[i]); + gdev[i] =NULL ; }pr_info ("%s: error %d while loading driver\n" ,BM2835_MMAL_MODULE_NAME , ret);
Re: [patch v2] staging: bcm2835-camera: fix error handling in init
looks more readable now :)
Am 18.02.2017 00:20, schrieb Dan Carpenter:
Quoted 54 lines
The unwinding here isn't right. We don't free gdev[0] and instead free 1 step past what was allocated. Also we can't allocate "dev" then we should unwind instead of returning directly.
Fixes 7b3ad5abf027 ("staging: Import the BCM2835 MMAL-based V4L2 camera driver.")Signed-off-by Dan Carpenter <[email protected]>---
v2: Change the style to make Walter Harms happy. Fix some additional
bugs I missed in the first patch.drivers/staging/media/platform/bcm2835/bcm2835-camera.c +9
-6@@ -1901,6 +1901,7 @@ static int __init bm2835_mmal_init(void)unsigned int num_cameras;struct vchiq_mmal_instance *instance;unsigned int resolutions[MAX_BCM2835_CAMERAS ][2 ]; +int i; ret =vchiq_mmal_init (&instance);if (ret <0 )@@ -1914,8 +1915,10 @@ static int __init bm2835_mmal_init(void)for (camera =0 ; camera < num_cameras; camera++) { dev =kzalloc (sizeof (struct bm2835_mmal_dev ),GFP_KERNEL ); -if (!dev) -return -ENOMEM ; +if (!dev) { + ret = -ENOMEM ; + goto cleanup_gdev; + } dev->camera_num = camera; dev->max_width = resolutions[camera][0 ];@@ -1998,9 +2001,10 @@ static int __init bm2835_mmal_init(void) free_dev:kfree (dev); -for ( ; camera >0 ; camera--) { -bcm2835_cleanup_instance (gdev[camera]); - gdev[camera] =NULL ; +cleanup_gdev: +for (i =0 ; i < camera; i++) { +bcm2835_cleanup_instance (gdev[i]); + gdev[i] =NULL ; }pr_info ("%s: error %d while loading driver\n" ,BM2835_MMAL_MODULE_NAME , ret); --To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html