Skip to content

Commit

Permalink
platform/chrome: cros_ec_proto: Use EC struct for features
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20211004170716.86601-1-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
  • Loading branch information
Prashant Malani authored and Benson Leung committed Oct 31, 2021
1 parent 3119c28 commit 7ff2278
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions drivers/mfd/cros_ec_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ static int ec_device_probe(struct platform_device *pdev)
ec->ec_dev = dev_get_drvdata(dev->parent);
ec->dev = dev;
ec->cmd_offset = ec_platform->cmd_offset;
ec->features[0] = -1U; /* Not cached yet */
ec->features[1] = -1U; /* Not cached yet */
ec->features.flags[0] = -1U; /* Not cached yet */
ec->features.flags[1] = -1U; /* Not cached yet */
device_initialize(&ec->class_dev);

for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) {
Expand Down
15 changes: 8 additions & 7 deletions drivers/platform/chrome/cros_ec_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,36 +812,37 @@ EXPORT_SYMBOL(cros_ec_get_host_event);
*/
bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
{
struct ec_response_get_features *features = &ec->features;
struct cros_ec_command *msg;
int ret;

if (ec->features[0] == -1U && ec->features[1] == -1U) {
if (features->flags[0] == -1U && features->flags[1] == -1U) {
/* features bitmap not read yet */
msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
msg = kzalloc(sizeof(*msg) + sizeof(*features), GFP_KERNEL);
if (!msg) {
dev_err(ec->dev, "failed to allocate memory to get EC features\n");
return false;
}

msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
msg->insize = sizeof(ec->features);
msg->insize = sizeof(*features);

ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) {
dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
ret, msg->result);
memset(ec->features, 0, sizeof(ec->features));
memset(features, 0, sizeof(*features));
} else {
memcpy(ec->features, msg->data, sizeof(ec->features));
memcpy(features, msg->data, sizeof(*features));
}

dev_dbg(ec->dev, "EC features %08x %08x\n",
ec->features[0], ec->features[1]);
features->flags[0], features->flags[1]);

kfree(msg);
}

return !!(ec->features[feature / 32] & EC_FEATURE_MASK_0(feature));
return !!(features->flags[feature / 32] & EC_FEATURE_MASK_0(feature));
}
EXPORT_SYMBOL_GPL(cros_ec_check_features);

Expand Down
2 changes: 1 addition & 1 deletion include/linux/platform_data/cros_ec_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct cros_ec_dev {
struct cros_ec_debugfs *debug_info;
bool has_kb_wake_angle;
u16 cmd_offset;
u32 features[2];
struct ec_response_get_features features;
};

#define to_cros_ec_dev(dev) container_of(dev, struct cros_ec_dev, class_dev)
Expand Down

0 comments on commit 7ff2278

Please sign in to comment.