Skip to content

Commit 7ff2278

Browse files
Prashant Malanibleungatchromium
authored andcommitted
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. Signed-off-by: Prashant Malani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benson Leung <[email protected]>
1 parent 3119c28 commit 7ff2278

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

drivers/mfd/cros_ec_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ static int ec_device_probe(struct platform_device *pdev)
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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,36 +812,37 @@ EXPORT_SYMBOL(cros_ec_get_host_event);
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct cros_ec_dev {
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)

0 commit comments

Comments
 (0)