Message ID | 1540481375-15952-2-git-send-email-stefan.wahren@i2se.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | staging: vc04_services: Improve driver load/unload | expand |
On Thu, Oct 25, 2018 at 4:30 PM Stefan Wahren <stefan.wahren@i2se.com> wrote: > > Abort the probing of 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> Tested-by: Peter Robinson <pbrobinson@gmail.com> In testing this both with and without a camera module attached it appears to still load the entire v4l stack even if there's no camera attached and it remains post probe, the /dev/video0 interface doesn't appear, which is what I'd expect, and from the dmesg output with/without a camera module it certainly seems to do less. I'm not sure if it's possible to detect whether we have a camera module before we start up the full media/v4l stack and exit the process and unload the module but I suspect having all the v4l bits loaded without various interfaces might cause confusion. # lsmod| grep v4l bcm2835_v4l2 61440 0 videobuf2_vmalloc 20480 1 bcm2835_v4l2 videobuf2_v4l2 24576 1 bcm2835_v4l2 videobuf2_common 49152 2 bcm2835_v4l2,videobuf2_v4l2 v4l2_common 16384 1 bcm2835_v4l2 videodev 180224 4 v4l2_common,videobuf2_common,bcm2835_v4l2,videobuf2_v4l2 media 49152 3 videobuf2_common,videodev,videobuf2_v4l2 vchiq 237568 2 bcm2835_v4l2,snd_bcm2835 Peter > --- > drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c > index c04bdf0..d6fbef7 100644 > --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c > +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c > @@ -1841,6 +1841,12 @@ static int bcm2835_mmal_probe(struct platform_device *pdev) > 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; > > @@ -1940,6 +1946,9 @@ static int bcm2835_mmal_probe(struct platform_device *pdev) > pr_info("%s: error %d while loading driver\n", > BM2835_MMAL_MODULE_NAME, ret); > > +cleanup_mmal: > + vchiq_mmal_finalise(instance); > + > return ret; > } > > -- > 2.7.4 >
diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c index c04bdf0..d6fbef7 100644 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c @@ -1841,6 +1841,12 @@ static int bcm2835_mmal_probe(struct platform_device *pdev) 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; @@ -1940,6 +1946,9 @@ static int bcm2835_mmal_probe(struct platform_device *pdev) pr_info("%s: error %d while loading driver\n", BM2835_MMAL_MODULE_NAME, ret); +cleanup_mmal: + vchiq_mmal_finalise(instance); + return ret; }
Abort the probing of 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> --- drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 9 +++++++++ 1 file changed, 9 insertions(+)