staging: bcm2835-camera: prefer allocating memory using sizeof(*ptr) instead of sizeof(struct type name)
Subsystems (3)
PATCH 1/1 staging: bcm2835-camera: prefer allocating memory using sizeof(*ptr) instead of sizeof(struct type name)
Using sizeof(*ptr) instead of sizeof(struct type name) is more robust to errors.
--- drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +1 -1
@@ -1911,7 +1911,7 @@ static int __init bm2835_mmal_init(void) num_cameras =MAX_BCM2835_CAMERAS ;for (camera =0 ; camera < num_cameras; camera++) { - dev =kzalloc (sizeof (struct bm2835_mmal_dev ),GFP_KERNEL ); + dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) { ret = -ENOMEM ; goto cleanup_gdev;
Signature · 1 line
2.7.4
Quoted 2 lines · Aishwarya Pant
Using
sizeof(*ptr)instead of sizeof(struct type name) is more robust to errors.
Just for future reference, many developers don't seem to care about this, and prefer the struct version.
julia
Quoted 29 lines
Signed-off-by Aishwarya Pant <[email protected]>--- drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +1
-2@@ -1911,7 +1911,7 @@ static int __init bm2835_mmal_init(void) num_cameras =MAX_BCM2835_CAMERAS ;for (camera =0 ; camera < num_cameras; camera++) { - dev =kzalloc (sizeof (struct bm2835_mmal_dev ),GFP_KERNEL ); + dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev) { ret = -ENOMEM ; goto cleanup_gdev; --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20170301182401.GA15456%40aishwarya.
For more options, visit https://groups.google.com/d/optout.