96236f36d5157099f31f5b81a47f8cbe6c152c2a
[openwrt/staging/thess.git] /
1 From b0ebcf556b543b0b509ad071584ca6b41076a2da Mon Sep 17 00:00:00 2001
2 From: Stefan Wahren <stefan.wahren@i2se.com>
3 Date: Mon, 22 Oct 2018 11:09:18 +0200
4 Subject: [PATCH] staging: bcm2835: Don't probe if no camera is
5 detected
6
7 It is a waste of resources to load the camera driver in case there isn't
8 a camera actually connected to the Raspberry Pi. This solution also
9 avoids a NULL ptr dereference of mmal instance on driver unload.
10
11 Fixes: 7b3ad5abf027 ("staging: Import the BCM2835 MMAL-based V4L2 camera driver.")
12 Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
13 ---
14 .../vc04_services/bcm2835-camera/bcm2835-camera.c | 9 +++++++++
15 1 file changed, 9 insertions(+)
16
17 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
18 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
19 @@ -1860,6 +1860,12 @@ static int bcm2835_mmal_probe(struct pla
20 num_cameras = get_num_cameras(instance,
21 resolutions,
22 MAX_BCM2835_CAMERAS);
23 +
24 + if (num_cameras < 1) {
25 + ret = -ENODEV;
26 + goto cleanup_mmal;
27 + }
28 +
29 if (num_cameras > MAX_BCM2835_CAMERAS)
30 num_cameras = MAX_BCM2835_CAMERAS;
31
32 @@ -1968,6 +1974,9 @@ cleanup_gdev:
33 gdev[i] = NULL;
34 }
35
36 +cleanup_mmal:
37 + vchiq_mmal_finalise(instance);
38 +
39 return ret;
40 }
41