From 7f93eab7c705527b0579b1bfd4d6e9f6acc9e5ca Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Thu, 30 Jun 2016 09:18:00 -0500 Subject: [PATCH] greybus: camera: Early update num_streams and flags In configure_streams Operation, when returning from the greybus operation call, we can assign the num_streams and flags variable earlier so that if the following stream configuration inspection fails, the caller receives the right number of configured streams anyway Testing Done: White camera module preview and capture. Triggering failure during stream configuration inspection makes configuration fails, but avoid segfaulting as was previously happening Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Signed-off-by: Alex Elder --- drivers/staging/greybus/camera.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c index c47e4244a132..584f85e7a02d 100644 --- a/drivers/staging/greybus/camera.c +++ b/drivers/staging/greybus/camera.c @@ -432,6 +432,9 @@ static int gb_camera_configure_streams(struct gb_camera *gcam, goto done; } + *flags = resp->flags; + *num_streams = resp->num_streams; + for (i = 0; i < nstreams; ++i) { struct gb_camera_stream_config_response *cfg = &resp->config[i]; @@ -451,11 +454,8 @@ static int gb_camera_configure_streams(struct gb_camera *gcam, } if ((resp->flags & GB_CAMERA_CONFIGURE_STREAMS_ADJUSTED) || - (*flags & GB_CAMERA_CONFIGURE_STREAMS_TEST_ONLY)) { - *flags = resp->flags; - *num_streams = resp->num_streams; + (req->flags & GB_CAMERA_CONFIGURE_STREAMS_TEST_ONLY)) goto done; - } if (gcam->state == GB_CAMERA_STATE_CONFIGURED) { gb_camera_teardown_data_connection(gcam); @@ -469,15 +469,14 @@ static int gb_camera_configure_streams(struct gb_camera *gcam, gb_operation_sync(gcam->connection, GB_CAMERA_TYPE_CONFIGURE_STREAMS, req, req_size, resp, resp_size); + *flags = 0; + *num_streams = 0; goto done; } gcam->state = GB_CAMERA_STATE_CONFIGURED; } - *flags = resp->flags; - *num_streams = resp->num_streams; - done: mutex_unlock(&gcam->mutex); kfree(req); -- 2.39.5