History

platform/chrome: cros_ec_proto: Use EC struct for features

The Chrome EC's features are returned through an ec_response_get_features struct, but they are stored in an independent array. Although the two are effectively the same at present (2 unsigned 32 bit ints), there is the possibility that they could go out of sync. Avoid this by only using the EC struct to store the features.

Prashant Malani committed 5 years ago

Commit 7ff22781 parent 3119c283 files · +11 −10Browse files

Unified · Split

3 files
  1. drivers/mfd/cros_ec_dev.c +2 −2
  2. drivers/platform/chrome/cros_ec_proto.c +8 −7
  3. include/linux/platform_data/cros_ec_proto.h +1 −1
drivers/mfd/cros_ec_dev.c+2−2
@@ -146,8 +146,8 @@ static int ec_device_probe(struct platform_device *pdev) · 145 unmodified lines
146 ec->ec_dev = dev_get_drvdata(dev->parent);146 ec->ec_dev = dev_get_drvdata(dev->parent);
147 ec->dev = dev;147 ec->dev = dev;
148 ec->cmd_offset = ec_platform->cmd_offset;148 ec->cmd_offset = ec_platform->cmd_offset;
149 ec->features[0] = -1U; /* Not cached yet */149 ec->features.flags[0] = -1U; /* Not cached yet */
150 ec->features[1] = -1U; /* Not cached yet */150 ec->features.flags[1] = -1U; /* Not cached yet */
151 device_initialize(&ec->class_dev);151 device_initialize(&ec->class_dev);
152 152
153 for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) {153 for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) {
drivers/platform/chrome/cros_ec_proto.c+8−7
@@ -812,36 +812,37 @@ EXPORT_SYMBOL(cros_ec_get_host_event); · 811 unmodified lines
812 */812 */
813bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)813bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
814{814{
815 struct ec_response_get_features *features = &ec->features;
815 struct cros_ec_command *msg;816 struct cros_ec_command *msg;
816 int ret;817 int ret;
817 818
818 if (ec->features[0] == -1U && ec->features[1] == -1U) {819 if (features->flags[0] == -1U && features->flags[1] == -1U) {
819 /* features bitmap not read yet */820 /* features bitmap not read yet */
820 msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);821 msg = kzalloc(sizeof(*msg) + sizeof(*features), GFP_KERNEL);
821 if (!msg) {822 if (!msg) {
822 dev_err(ec->dev, "failed to allocate memory to get EC features\n");823 dev_err(ec->dev, "failed to allocate memory to get EC features\n");
823 return false;824 return false;
824 }825 }
825 826
826 msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;827 msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
827 msg->insize = sizeof(ec->features);828 msg->insize = sizeof(*features);
828 829
829 ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);830 ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
830 if (ret < 0) {831 if (ret < 0) {
831 dev_warn(ec->dev, "cannot get EC features: %d/%d\n",832 dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
832 ret, msg->result);833 ret, msg->result);
833 memset(ec->features, 0, sizeof(ec->features));834 memset(features, 0, sizeof(*features));
834 } else {835 } else {
835 memcpy(ec->features, msg->data, sizeof(ec->features));836 memcpy(features, msg->data, sizeof(*features));
836 }837 }
837 838
838 dev_dbg(ec->dev, "EC features %08x %08x\n",839 dev_dbg(ec->dev, "EC features %08x %08x\n",
839 ec->features[0], ec->features[1]);840 features->flags[0], features->flags[1]);
840 841
841 kfree(msg);842 kfree(msg);
842 }843 }
843 844
844 return !!(ec->features[feature / 32] & EC_FEATURE_MASK_0(feature));845 return !!(features->flags[feature / 32] & EC_FEATURE_MASK_0(feature));
845}846}
846EXPORT_SYMBOL_GPL(cros_ec_check_features);847EXPORT_SYMBOL_GPL(cros_ec_check_features);
847 848
include/linux/platform_data/cros_ec_proto.h+1−1
@@ -205,7 +205,7 @@ struct cros_ec_dev { · 204 unmodified lines
205 struct cros_ec_debugfs *debug_info;205 struct cros_ec_debugfs *debug_info;
206 bool has_kb_wake_angle;206 bool has_kb_wake_angle;
207 u16 cmd_offset;207 u16 cmd_offset;
208 u32 features[2];208 struct ec_response_get_features features;
209};209};
210 210
211#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)211#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t