Message ID | 20190414013506.10515-2-niklas.soderlund@ragnatech.se |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Niklas, Thank you for the patch. On Sun, Apr 14, 2019 at 03:34:56AM +0200, Niklas Söderlund wrote: > In preparation of adding more responsibility to MediaDevice::acquire() > make sure all callers checks and acts properly to its return value. > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > src/libcamera/pipeline/ipu3/ipu3.cpp | 10 ++++------ > src/libcamera/pipeline/uvcvideo.cpp | 3 ++- > src/libcamera/pipeline/vimc.cpp | 3 ++- > test/media_device/media_device_link_test.cpp | 6 +++++- > test/v4l2_device/v4l2_device_test.cpp | 3 ++- > test/v4l2_subdevice/v4l2_subdevice_test.cpp | 6 +++++- > 6 files changed, 20 insertions(+), 11 deletions(-) > > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp > index ca09da753b908448..d8de6b3c36314fc0 100644 > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp > @@ -451,21 +451,19 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) > imgu_dm.add("ipu3-imgu 1 viewfinder"); > imgu_dm.add("ipu3-imgu 1 3a stat"); > > - /* > - * It is safe to acquire both media devices at this point as > - * DeviceEnumerator::search() skips the busy ones for us. > - */ > cio2MediaDev_ = enumerator->search(cio2_dm); > if (!cio2MediaDev_) > return false; > > - cio2MediaDev_->acquire(); > + if (!cio2MediaDev_->acquire()) > + return false; > > imguMediaDev_ = enumerator->search(imgu_dm); > if (!imguMediaDev_) > return false; > > - imguMediaDev_->acquire(); > + if (!imguMediaDev_->acquire()) > + return false; > > /* > * Disable all links that are enabled by default on CIO2, as camera > diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp > index cd472cfadd86b7ba..5214bfd3097b8217 100644 > --- a/src/libcamera/pipeline/uvcvideo.cpp > +++ b/src/libcamera/pipeline/uvcvideo.cpp > @@ -184,7 +184,8 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) > if (!media_) > return false; > > - media_->acquire(); > + if (!media_->acquire()) > + return false; > > std::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(this); > > diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp > index c8bbe2a19847ba1e..e5e78ccedd59ae66 100644 > --- a/src/libcamera/pipeline/vimc.cpp > +++ b/src/libcamera/pipeline/vimc.cpp > @@ -194,7 +194,8 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) > if (!media_) > return false; > > - media_->acquire(); > + if (!media_->acquire()) > + return false; > > std::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this); > > diff --git a/test/media_device/media_device_link_test.cpp b/test/media_device/media_device_link_test.cpp > index 58a55cdfee634c0b..4b8de3bee722e912 100644 > --- a/test/media_device/media_device_link_test.cpp > +++ b/test/media_device/media_device_link_test.cpp > @@ -51,7 +51,11 @@ class MediaDeviceLinkTest : public Test > return TestSkip; > } > > - dev_->acquire(); > + if (!dev_->acquire()) { > + cerr << "Unable to acquire media device: " I'd drop the colon ':'. > + << dev_->deviceNode() << endl; > + return TestSkip; > + } > > if (dev_->open()) { > cerr << "Failed to open media device at " > diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp > index 4225291bbb6e23f0..90e5f7a3ee0c0f2f 100644 > --- a/test/v4l2_device/v4l2_device_test.cpp > +++ b/test/v4l2_device/v4l2_device_test.cpp > @@ -46,7 +46,8 @@ int V4L2DeviceTest::init() > if (!media_) > return TestSkip; > > - media_->acquire(); > + if (!media_->acquire()) > + return TestSkip; > > MediaEntity *entity = media_->getEntityByName("vivid-000-vid-cap"); > if (!entity) > diff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp > index 06582969eb45f658..21335efbad4d5668 100644 > --- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp > +++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp > @@ -45,7 +45,11 @@ int V4L2SubdeviceTest::init() > return TestSkip; > } > > - media_->acquire(); > + if (!media_->acquire()) { > + cerr << "Unable to acquire media device: " Same here. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > + << media_->deviceNode() << endl; > + return TestSkip; > + } > > int ret = media_->open(); > if (ret) {
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index ca09da753b908448..d8de6b3c36314fc0 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -451,21 +451,19 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator) imgu_dm.add("ipu3-imgu 1 viewfinder"); imgu_dm.add("ipu3-imgu 1 3a stat"); - /* - * It is safe to acquire both media devices at this point as - * DeviceEnumerator::search() skips the busy ones for us. - */ cio2MediaDev_ = enumerator->search(cio2_dm); if (!cio2MediaDev_) return false; - cio2MediaDev_->acquire(); + if (!cio2MediaDev_->acquire()) + return false; imguMediaDev_ = enumerator->search(imgu_dm); if (!imguMediaDev_) return false; - imguMediaDev_->acquire(); + if (!imguMediaDev_->acquire()) + return false; /* * Disable all links that are enabled by default on CIO2, as camera diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index cd472cfadd86b7ba..5214bfd3097b8217 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -184,7 +184,8 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) if (!media_) return false; - media_->acquire(); + if (!media_->acquire()) + return false; std::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(this); diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index c8bbe2a19847ba1e..e5e78ccedd59ae66 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -194,7 +194,8 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) if (!media_) return false; - media_->acquire(); + if (!media_->acquire()) + return false; std::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this); diff --git a/test/media_device/media_device_link_test.cpp b/test/media_device/media_device_link_test.cpp index 58a55cdfee634c0b..4b8de3bee722e912 100644 --- a/test/media_device/media_device_link_test.cpp +++ b/test/media_device/media_device_link_test.cpp @@ -51,7 +51,11 @@ class MediaDeviceLinkTest : public Test return TestSkip; } - dev_->acquire(); + if (!dev_->acquire()) { + cerr << "Unable to acquire media device: " + << dev_->deviceNode() << endl; + return TestSkip; + } if (dev_->open()) { cerr << "Failed to open media device at " diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp index 4225291bbb6e23f0..90e5f7a3ee0c0f2f 100644 --- a/test/v4l2_device/v4l2_device_test.cpp +++ b/test/v4l2_device/v4l2_device_test.cpp @@ -46,7 +46,8 @@ int V4L2DeviceTest::init() if (!media_) return TestSkip; - media_->acquire(); + if (!media_->acquire()) + return TestSkip; MediaEntity *entity = media_->getEntityByName("vivid-000-vid-cap"); if (!entity) diff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp index 06582969eb45f658..21335efbad4d5668 100644 --- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp +++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp @@ -45,7 +45,11 @@ int V4L2SubdeviceTest::init() return TestSkip; } - media_->acquire(); + if (!media_->acquire()) { + cerr << "Unable to acquire media device: " + << media_->deviceNode() << endl; + return TestSkip; + } int ret = media_->open(); if (ret) {
In preparation of adding more responsibility to MediaDevice::acquire() make sure all callers checks and acts properly to its return value. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> --- src/libcamera/pipeline/ipu3/ipu3.cpp | 10 ++++------ src/libcamera/pipeline/uvcvideo.cpp | 3 ++- src/libcamera/pipeline/vimc.cpp | 3 ++- test/media_device/media_device_link_test.cpp | 6 +++++- test/v4l2_device/v4l2_device_test.cpp | 3 ++- test/v4l2_subdevice/v4l2_subdevice_test.cpp | 6 +++++- 6 files changed, 20 insertions(+), 11 deletions(-)