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
146146 ec->ec_dev = dev_get_drvdata(dev->parent);
147147 ec->dev = dev;
148148 ec->cmd_offset = ec_platform->cmd_offset;
149− ec->features[0] = -1U; /* Not cached yet */
150− ec->features[1] = -1U; /* Not cached yet */
149+ ec->features.flags[0] = -1U; /* Not cached yet */
150+ ec->features.flags[1] = -1U; /* Not cached yet */
151151 device_initialize(&ec->class_dev);
152152
153153 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
812812 */
813813 bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
814814 {
815+ struct ec_response_get_features *features = &ec->features;
815816 struct cros_ec_command *msg;
816817 int ret;
817818
818− if (ec->features[0] == -1U && ec->features[1] == -1U) {
819+ if (features->flags[0] == -1U && features->flags[1] == -1U) {
819820 /* features bitmap not read yet */
820− msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
821+ msg = kzalloc(sizeof(*msg) + sizeof(*features), GFP_KERNEL);
821822 if (!msg) {
822823 dev_err(ec->dev, "failed to allocate memory to get EC features\n");
823824 return false;
824825 }
825826
826827 msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
827− msg->insize = sizeof(ec->features);
828+ msg->insize = sizeof(*features);
828829
829830 ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
830831 if (ret < 0) {
831832 dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
832833 ret, msg->result);
833− memset(ec->features, 0, sizeof(ec->features));
834+ memset(features, 0, sizeof(*features));
834835 } else {
835− memcpy(ec->features, msg->data, sizeof(ec->features));
836+ memcpy(features, msg->data, sizeof(*features));
836837 }
837838
838839 dev_dbg(ec->dev, "EC features %08x %08x\n",
839− ec->features[0], ec->features[1]);
840+ features->flags[0], features->flags[1]);
840841
841842 kfree(msg);
842843 }
843844
844− return !!(ec->features[feature / 32] & EC_FEATURE_MASK_0(feature));
845+ return !!(features->flags[feature / 32] & EC_FEATURE_MASK_0(feature));
845846 }
846847 EXPORT_SYMBOL_GPL(cros_ec_check_features);
847848
include/linux/platform_data/cros_ec_proto.h+1−1
@@ -205,7 +205,7 @@ struct cros_ec_dev { · 204 unmodified lines
205205 struct cros_ec_debugfs *debug_info;
206206 bool has_kb_wake_angle;
207207 u16 cmd_offset;
208− u32 features[2];
208+ struct ec_response_get_features features;
209209 };
210210
211211 #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