OSDN Git Service

STPK-1429 Disable a sensor if its character device can't be opened
authorPatrick Porlan <patrick.porlan@intel.com>
Thu, 3 Apr 2014 11:52:00 +0000 (13:52 +0200)
committersuyyala <sridhar.uyyala@intel.com>
Mon, 28 Apr 2014 02:40:39 +0000 (19:40 -0700)
It's an abnormal situation to have a sensor operating while its
associated character device couldn't be opened (the underlying
hardware may not be powered on). Reconciliate the HAL level state
with the underlying driver state in this case by reverting to
disabled state.

Issue: STPK-1429

Change-Id: I16ce2889b7be644a33a79fe04ddba9cf574bfde9
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
control.c

index 2ae437c..7edd8db 100644 (file)
--- a/control.c
+++ b/control.c
@@ -345,15 +345,16 @@ int sensor_activate(int s, int enabled)
                        sprintf(device_name, DEV_FILE_PATH, dev_num);
                        dev_fd = open(device_name, O_RDONLY | O_NONBLOCK);
 
+                       device_fd[dev_num] = dev_fd;
+
                        if (dev_fd == -1) {
                                ALOGE("Could not open fd on %s (%s)\n",
                                      device_name, strerror(errno));
+                               adjust_counters(s, 0);
                                return -1;
                        }
 
                        ALOGV("Opened %s: fd=%d\n", device_name, dev_fd);
-
-                       device_fd[dev_num] = dev_fd;
                        break;
 
                default: