It is a waste of resources to load the camera driver in case there isn't
a camera actually connected to the Raspberry Pi. This solution also
avoids a NULL ptr dereference of mmal instance on driver unload.
Fixes:
7b3ad5abf027 ("staging: Import the BCM2835 MMAL-based V4L2 camera driver.")
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
num_cameras = get_num_cameras(instance,
resolutions,
MAX_BCM2835_CAMERAS);
+
+ if (num_cameras < 1) {
+ ret = -ENODEV;
+ goto cleanup_mmal;
+ }
+
if (num_cameras > MAX_BCM2835_CAMERAS)
num_cameras = MAX_BCM2835_CAMERAS;
gdev[i] = NULL;
}
+cleanup_mmal:
+ vchiq_mmal_finalise(instance);
+
return ret;
}