klte-common: camera: How about doing our NULL checks before crashing?

Current we cleverly deference "device" as part of a log message
and then immediately afterward we bother to check whether or not "device"
was NULL and whether or not it was safe to have just dereferenced it...

Change-Id: Ifcc38fbac54654fd2c6eca894af9a2a794a95f2a
This commit is contained in:
Christopher R. Palmer 2016-07-10 09:28:20 +02:00 committed by Kevin Haggerty
parent e8c6837bb7
commit 9ac995b901
1 changed files with 60 additions and 63 deletions

View File

@ -206,12 +206,12 @@ static int camera_set_parameters(struct camera_device *device, const char *param
static int camera_set_preview_window(struct camera_device *device, static int camera_set_preview_window(struct camera_device *device,
struct preview_stream_ops *window) struct preview_stream_ops *window)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, set_preview_window, window); return VENDOR_CALL(device, set_preview_window, window);
} }
@ -222,104 +222,104 @@ static void camera_set_callbacks(struct camera_device *device,
camera_request_memory get_memory, camera_request_memory get_memory,
void *user) void *user)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return; return;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
VENDOR_CALL(device, set_callbacks, notify_cb, data_cb, data_cb_timestamp, get_memory, user); VENDOR_CALL(device, set_callbacks, notify_cb, data_cb, data_cb_timestamp, get_memory, user);
} }
static void camera_enable_msg_type(struct camera_device *device, static void camera_enable_msg_type(struct camera_device *device,
int32_t msg_type) int32_t msg_type)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return; return;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
VENDOR_CALL(device, enable_msg_type, msg_type); VENDOR_CALL(device, enable_msg_type, msg_type);
} }
static void camera_disable_msg_type(struct camera_device *device, static void camera_disable_msg_type(struct camera_device *device,
int32_t msg_type) int32_t msg_type)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return; return;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
VENDOR_CALL(device, disable_msg_type, msg_type); VENDOR_CALL(device, disable_msg_type, msg_type);
} }
static int camera_msg_type_enabled(struct camera_device *device, static int camera_msg_type_enabled(struct camera_device *device,
int32_t msg_type) int32_t msg_type)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return 0; return 0;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, msg_type_enabled, msg_type); return VENDOR_CALL(device, msg_type_enabled, msg_type);
} }
static int camera_start_preview(struct camera_device *device) static int camera_start_preview(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, start_preview); return VENDOR_CALL(device, start_preview);
} }
static void camera_stop_preview(struct camera_device *device) static void camera_stop_preview(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return; return;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
VENDOR_CALL(device, stop_preview); VENDOR_CALL(device, stop_preview);
} }
static int camera_preview_enabled(struct camera_device *device) static int camera_preview_enabled(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, preview_enabled); return VENDOR_CALL(device, preview_enabled);
} }
static int camera_store_meta_data_in_buffers(struct camera_device *device, static int camera_store_meta_data_in_buffers(struct camera_device *device,
int enable) int enable)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, store_meta_data_in_buffers, enable); return VENDOR_CALL(device, store_meta_data_in_buffers, enable);
} }
static int camera_start_recording(struct camera_device *device) static int camera_start_recording(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return EINVAL; return EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
CameraParameters parameters; CameraParameters parameters;
parameters.unflatten(String8(camera_get_parameters(device))); parameters.unflatten(String8(camera_get_parameters(device)));
@ -334,90 +334,90 @@ static int camera_start_recording(struct camera_device *device)
static void camera_stop_recording(struct camera_device *device) static void camera_stop_recording(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return; return;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
VENDOR_CALL(device, stop_recording); VENDOR_CALL(device, stop_recording);
} }
static int camera_recording_enabled(struct camera_device *device) static int camera_recording_enabled(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, recording_enabled); return VENDOR_CALL(device, recording_enabled);
} }
static void camera_release_recording_frame(struct camera_device *device, static void camera_release_recording_frame(struct camera_device *device,
const void *opaque) const void *opaque)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return; return;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
VENDOR_CALL(device, release_recording_frame, opaque); VENDOR_CALL(device, release_recording_frame, opaque);
} }
static int camera_auto_focus(struct camera_device *device) static int camera_auto_focus(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, auto_focus); return VENDOR_CALL(device, auto_focus);
} }
static int camera_cancel_auto_focus(struct camera_device *device) static int camera_cancel_auto_focus(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, cancel_auto_focus); return VENDOR_CALL(device, cancel_auto_focus);
} }
static int camera_take_picture(struct camera_device *device) static int camera_take_picture(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, take_picture); return VENDOR_CALL(device, take_picture);
} }
static int camera_cancel_picture(struct camera_device *device) static int camera_cancel_picture(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, cancel_picture); return VENDOR_CALL(device, cancel_picture);
} }
static int camera_set_parameters(struct camera_device *device, const char *params) static int camera_set_parameters(struct camera_device *device, const char *params)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
char *tmp = NULL; char *tmp = NULL;
tmp = camera_fixup_setparams(CAMERA_ID(device), params); tmp = camera_fixup_setparams(CAMERA_ID(device), params);
@ -427,12 +427,12 @@ static int camera_set_parameters(struct camera_device *device, const char *param
static char *camera_get_parameters(struct camera_device *device) static char *camera_get_parameters(struct camera_device *device)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return NULL; return NULL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
char *params = VENDOR_CALL(device, get_parameters); char *params = VENDOR_CALL(device, get_parameters);
char *tmp = camera_fixup_getparams(CAMERA_ID(device), params); char *tmp = camera_fixup_getparams(CAMERA_ID(device), params);
@ -444,9 +444,6 @@ static char *camera_get_parameters(struct camera_device *device)
static void camera_put_parameters(struct camera_device *device, char *params) static void camera_put_parameters(struct camera_device *device, char *params)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (params) if (params)
free(params); free(params);
} }
@ -454,12 +451,12 @@ static void camera_put_parameters(struct camera_device *device, char *params)
static int camera_send_command(struct camera_device *device, static int camera_send_command(struct camera_device *device,
int32_t cmd, int32_t arg1, int32_t arg2) int32_t cmd, int32_t arg1, int32_t arg2)
{ {
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
if (!device) if (!device)
return -EINVAL; return -EINVAL;
ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device,
(uintptr_t)(((wrapper_camera_device_t*)device)->vendor));
return VENDOR_CALL(device, send_command, cmd, arg1, arg2); return VENDOR_CALL(device, send_command, cmd, arg1, arg2);
} }