]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mfd: cros_ec: Register cros_ec_lid_angle driver when presented
authorGwendal Grignou <gwendal@chromium.org>
Fri, 17 May 2019 23:38:55 +0000 (16:38 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Jul 2019 05:24:44 +0000 (07:24 +0200)
[ Upstream commit 1bb407f17c5316888c3c446e26cb2bb78943f236 ]

Register driver when EC indicates has precise lid angle calculation code
running.
Fix incorrect extra resource allocation in cros_ec_sensors_register().

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mfd/cros_ec_dev.c

index a5391f96eafd14c2b3b7f1b93fb82ce82523807c..607383b67cf15c9392ae0f802f1a93b587406ac9 100644 (file)
@@ -285,13 +285,15 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
 
        resp = (struct ec_response_motion_sense *)msg->data;
        sensor_num = resp->dump.sensor_count;
-       /* Allocate 1 extra sensors in FIFO are needed */
-       sensor_cells = kcalloc(sensor_num + 1, sizeof(struct mfd_cell),
+       /*
+        * Allocate 2 extra sensors if lid angle sensor and/or FIFO are needed.
+        */
+       sensor_cells = kcalloc(sensor_num + 2, sizeof(struct mfd_cell),
                               GFP_KERNEL);
        if (sensor_cells == NULL)
                goto error;
 
-       sensor_platforms = kcalloc(sensor_num + 1,
+       sensor_platforms = kcalloc(sensor_num,
                                   sizeof(struct cros_ec_sensor_platform),
                                   GFP_KERNEL);
        if (sensor_platforms == NULL)
@@ -351,6 +353,11 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
                sensor_cells[id].name = "cros-ec-ring";
                id++;
        }
+       if (cros_ec_check_features(ec,
+                               EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS)) {
+               sensor_cells[id].name = "cros-ec-lid-angle";
+               id++;
+       }
 
        ret = mfd_add_devices(ec->dev, 0, sensor_cells, id,
                              NULL, 0, NULL);