* [PATCH 1/2] platform/chrome: cros_ec_proto: Update feature check @ 2021-08-02 18:47 Prashant Malani 2021-08-02 18:47 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Use existing " Prashant Malani 2021-08-23 17:30 ` [PATCH 1/2] platform/chrome: cros_ec_proto: Update " Benson Leung 0 siblings, 2 replies; 5+ messages in thread From: Prashant Malani @ 2021-08-02 18:47 UTC (permalink / raw) To: linux-kernel Cc: Prashant Malani, Benson Leung, Enric Balletbo i Serra, Guenter Roeck EC feature flags now require more than 32 bits to be represented. In order to make cros_ec_check_features() usable for more recent features, update it to account for the extra 32 bits of features. Signed-off-by: Prashant Malani <pmalani@chromium.org> --- drivers/platform/chrome/cros_ec_proto.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index a7404d69b2d3..772edad80593 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -813,6 +813,7 @@ EXPORT_SYMBOL(cros_ec_get_host_event); int cros_ec_check_features(struct cros_ec_dev *ec, int feature) { struct cros_ec_command *msg; + u32 mask; int ret; if (ec->features[0] == -1U && ec->features[1] == -1U) { @@ -839,7 +840,12 @@ int cros_ec_check_features(struct cros_ec_dev *ec, int feature) kfree(msg); } - return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature); + if (feature >= 32) + mask = EC_FEATURE_MASK_1(feature); + else + mask = EC_FEATURE_MASK_0(feature); + + return ec->features[feature / 32] & mask; } EXPORT_SYMBOL_GPL(cros_ec_check_features); -- 2.32.0.554.ge1b32706d8-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] platform/chrome: cros_ec_typec: Use existing feature check 2021-08-02 18:47 [PATCH 1/2] platform/chrome: cros_ec_proto: Update feature check Prashant Malani @ 2021-08-02 18:47 ` Prashant Malani 2021-08-03 10:09 ` Enric Balletbo i Serra 2021-08-23 17:30 ` [PATCH 1/2] platform/chrome: cros_ec_proto: Update " Benson Leung 1 sibling, 1 reply; 5+ messages in thread From: Prashant Malani @ 2021-08-02 18:47 UTC (permalink / raw) To: linux-kernel Cc: Prashant Malani, Benson Leung, Enric Balletbo i Serra, Guenter Roeck Replace the cros_typec_feature_supported() function with the pre-existing cros_ec_check_features() function which does the same thing. Signed-off-by: Prashant Malani <pmalani@chromium.org> --- drivers/platform/chrome/cros_ec_typec.c | 33 +++++++++---------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 27c068c4c38d..f96af8aa31b5 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -1054,24 +1054,6 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec) return 0; } -/* Check the EC feature flags to see if TYPEC_* features are supported. */ -static int cros_typec_feature_supported(struct cros_typec_data *typec, enum ec_feature_code feature) -{ - struct ec_response_get_features resp = {}; - int ret; - - ret = cros_typec_ec_command(typec, 0, EC_CMD_GET_FEATURES, NULL, 0, - &resp, sizeof(resp)); - if (ret < 0) { - dev_warn(typec->dev, - "Failed to get features, assuming typec feature=%d unsupported.\n", - feature); - return 0; - } - - return resp.flags[feature / 32] & EC_FEATURE_MASK_1(feature); -} - static void cros_typec_port_work(struct work_struct *work) { struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work); @@ -1113,6 +1095,7 @@ MODULE_DEVICE_TABLE(of, cros_typec_of_match); static int cros_typec_probe(struct platform_device *pdev) { + struct cros_ec_dev *ec_dev = NULL; struct device *dev = &pdev->dev; struct cros_typec_data *typec; struct ec_response_usb_pd_ports resp; @@ -1132,10 +1115,16 @@ static int cros_typec_probe(struct platform_device *pdev) return ret; } - typec->typec_cmd_supported = !!cros_typec_feature_supported(typec, - EC_FEATURE_TYPEC_CMD); - typec->needs_mux_ack = !!cros_typec_feature_supported(typec, - EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); + if (typec->ec->ec) + ec_dev = dev_get_drvdata(&typec->ec->ec->dev); + + if (ec_dev) { + typec->typec_cmd_supported = !!cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD); + typec->needs_mux_ack = !!cros_ec_check_features(ec_dev, + EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); + } else { + dev_warn(dev, "Invalid cros_ec_dev pointer; feature flags not checked.\n"); + } ret = cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_PORTS, NULL, 0, &resp, sizeof(resp)); -- 2.32.0.554.ge1b32706d8-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Use existing feature check 2021-08-02 18:47 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Use existing " Prashant Malani @ 2021-08-03 10:09 ` Enric Balletbo i Serra 2021-08-03 17:29 ` Prashant Malani 0 siblings, 1 reply; 5+ messages in thread From: Enric Balletbo i Serra @ 2021-08-03 10:09 UTC (permalink / raw) To: Prashant Malani, linux-kernel; +Cc: Benson Leung, Guenter Roeck Hi Prashant, Thank you for your patch. On 2/8/21 20:47, Prashant Malani wrote: > Replace the cros_typec_feature_supported() function with the > pre-existing cros_ec_check_features() function which does the same > thing. > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > --- > drivers/platform/chrome/cros_ec_typec.c | 33 +++++++++---------------- > 1 file changed, 11 insertions(+), 22 deletions(-) > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > index 27c068c4c38d..f96af8aa31b5 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -1054,24 +1054,6 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec) > return 0; > } > > -/* Check the EC feature flags to see if TYPEC_* features are supported. */ > -static int cros_typec_feature_supported(struct cros_typec_data *typec, enum ec_feature_code feature) > -{ > - struct ec_response_get_features resp = {}; > - int ret; > - > - ret = cros_typec_ec_command(typec, 0, EC_CMD_GET_FEATURES, NULL, 0, > - &resp, sizeof(resp)); > - if (ret < 0) { > - dev_warn(typec->dev, > - "Failed to get features, assuming typec feature=%d unsupported.\n", > - feature); > - return 0; > - } > - > - return resp.flags[feature / 32] & EC_FEATURE_MASK_1(feature); > -} > - > static void cros_typec_port_work(struct work_struct *work) > { > struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work); > @@ -1113,6 +1095,7 @@ MODULE_DEVICE_TABLE(of, cros_typec_of_match); > > static int cros_typec_probe(struct platform_device *pdev) > { > + struct cros_ec_dev *ec_dev = NULL; > struct device *dev = &pdev->dev; > struct cros_typec_data *typec; > struct ec_response_usb_pd_ports resp; > @@ -1132,10 +1115,16 @@ static int cros_typec_probe(struct platform_device *pdev) > return ret; > } > > - typec->typec_cmd_supported = !!cros_typec_feature_supported(typec, > - EC_FEATURE_TYPEC_CMD); > - typec->needs_mux_ack = !!cros_typec_feature_supported(typec, > - EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); > + if (typec->ec->ec) Is this check really needed. Can typec->ec->ec be NULL at this point? > + ec_dev = dev_get_drvdata(&typec->ec->ec->dev); > + > + if (ec_dev) { and this? > + typec->typec_cmd_supported = !!cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD); > + typec->needs_mux_ack = !!cros_ec_check_features(ec_dev, > + EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); > + } else { and this? > + dev_warn(dev, "Invalid cros_ec_dev pointer; feature flags not checked.\n"); Can't just be typec->typec_cmd_supported = !!cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD); typec->needs_mux_ack = !!cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); Thanks, Enric > + } > > ret = cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_PORTS, NULL, 0, > &resp, sizeof(resp)); > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Use existing feature check 2021-08-03 10:09 ` Enric Balletbo i Serra @ 2021-08-03 17:29 ` Prashant Malani 0 siblings, 0 replies; 5+ messages in thread From: Prashant Malani @ 2021-08-03 17:29 UTC (permalink / raw) To: Enric Balletbo i Serra; +Cc: linux-kernel, Benson Leung, Guenter Roeck Hi Enric, Thanks for reviewing the patch. On Tue, Aug 03, 2021 at 12:09:47PM +0200, Enric Balletbo i Serra wrote: > Hi Prashant, > > Thank you for your patch. > > On 2/8/21 20:47, Prashant Malani wrote: > > Replace the cros_typec_feature_supported() function with the > > pre-existing cros_ec_check_features() function which does the same > > thing. > > > > Signed-off-by: Prashant Malani <pmalani@chromium.org> > > --- > > drivers/platform/chrome/cros_ec_typec.c | 33 +++++++++---------------- > > 1 file changed, 11 insertions(+), 22 deletions(-) > > > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > > index 27c068c4c38d..f96af8aa31b5 100644 > > --- a/drivers/platform/chrome/cros_ec_typec.c > > +++ b/drivers/platform/chrome/cros_ec_typec.c > > @@ -1054,24 +1054,6 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec) > > return 0; > > } > > > > -/* Check the EC feature flags to see if TYPEC_* features are supported. */ > > -static int cros_typec_feature_supported(struct cros_typec_data *typec, enum ec_feature_code feature) > > -{ > > - struct ec_response_get_features resp = {}; > > - int ret; > > - > > - ret = cros_typec_ec_command(typec, 0, EC_CMD_GET_FEATURES, NULL, 0, > > - &resp, sizeof(resp)); > > - if (ret < 0) { > > - dev_warn(typec->dev, > > - "Failed to get features, assuming typec feature=%d unsupported.\n", > > - feature); > > - return 0; > > - } > > - > > - return resp.flags[feature / 32] & EC_FEATURE_MASK_1(feature); > > -} > > - > > static void cros_typec_port_work(struct work_struct *work) > > { > > struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work); > > @@ -1113,6 +1095,7 @@ MODULE_DEVICE_TABLE(of, cros_typec_of_match); > > > > static int cros_typec_probe(struct platform_device *pdev) > > { > > + struct cros_ec_dev *ec_dev = NULL; > > struct device *dev = &pdev->dev; > > struct cros_typec_data *typec; > > struct ec_response_usb_pd_ports resp; > > @@ -1132,10 +1115,16 @@ static int cros_typec_probe(struct platform_device *pdev) > > return ret; > > } > > > > - typec->typec_cmd_supported = !!cros_typec_feature_supported(typec, > > - EC_FEATURE_TYPEC_CMD); > > - typec->needs_mux_ack = !!cros_typec_feature_supported(typec, > > - EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); > > + if (typec->ec->ec) > > Is this check really needed. Can typec->ec->ec be NULL at this point? Looking at it closely, it looks like it can't be NULL (cros_ec_register() fails if the platform device registration fails). > > > + ec_dev = dev_get_drvdata(&typec->ec->ec->dev); > > + > > + if (ec_dev) { > > and this? I haven't been able to prove this solely by looking at the code, hence wanted to be defensive here. That said, in the ARM and x86 platforms I tested this change on, it wasn't NULL. > > > + typec->typec_cmd_supported = !!cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD); > > + typec->needs_mux_ack = !!cros_ec_check_features(ec_dev, > > + EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); > > + } else { > > and this? > > > + dev_warn(dev, "Invalid cros_ec_dev pointer; feature flags not checked.\n"); > > Can't just be > > typec->typec_cmd_supported = !!cros_ec_check_features(ec_dev, > EC_FEATURE_TYPEC_CMD); > typec->needs_mux_ack = !!cros_ec_check_features(ec_dev, > EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); Sure; I'll push another version with the NULL checks dropped. Thanks, -Prashant ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] platform/chrome: cros_ec_proto: Update feature check 2021-08-02 18:47 [PATCH 1/2] platform/chrome: cros_ec_proto: Update feature check Prashant Malani 2021-08-02 18:47 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Use existing " Prashant Malani @ 2021-08-23 17:30 ` Benson Leung 1 sibling, 0 replies; 5+ messages in thread From: Benson Leung @ 2021-08-23 17:30 UTC (permalink / raw) To: Prashant Malani Cc: linux-kernel, Benson Leung, Enric Balletbo i Serra, Guenter Roeck [-- Attachment #1: Type: text/plain, Size: 1629 bytes --] Hi Prashant, On Mon, Aug 02, 2021 at 11:47:10AM -0700, Prashant Malani wrote: > EC feature flags now require more than 32 bits to be represented. In > order to make cros_ec_check_features() usable for more recent features, > update it to account for the extra 32 bits of features. > > Signed-off-by: Prashant Malani <pmalani@chromium.org> FYI, as discussed, this patch was dropped from the series. > --- > drivers/platform/chrome/cros_ec_proto.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c > index a7404d69b2d3..772edad80593 100644 > --- a/drivers/platform/chrome/cros_ec_proto.c > +++ b/drivers/platform/chrome/cros_ec_proto.c > @@ -813,6 +813,7 @@ EXPORT_SYMBOL(cros_ec_get_host_event); > int cros_ec_check_features(struct cros_ec_dev *ec, int feature) > { > struct cros_ec_command *msg; > + u32 mask; > int ret; > > if (ec->features[0] == -1U && ec->features[1] == -1U) { > @@ -839,7 +840,12 @@ int cros_ec_check_features(struct cros_ec_dev *ec, int feature) > kfree(msg); > } > > - return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature); > + if (feature >= 32) > + mask = EC_FEATURE_MASK_1(feature); > + else > + mask = EC_FEATURE_MASK_0(feature); > + > + return ec->features[feature / 32] & mask; > } > EXPORT_SYMBOL_GPL(cros_ec_check_features); > > -- > 2.32.0.554.ge1b32706d8-goog > -- Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. bleung@google.com Chromium OS Project bleung@chromium.org [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-23 17:31 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-08-02 18:47 [PATCH 1/2] platform/chrome: cros_ec_proto: Update feature check Prashant Malani 2021-08-02 18:47 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Use existing " Prashant Malani 2021-08-03 10:09 ` Enric Balletbo i Serra 2021-08-03 17:29 ` Prashant Malani 2021-08-23 17:30 ` [PATCH 1/2] platform/chrome: cros_ec_proto: Update " Benson Leung
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox