* [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes
@ 2022-06-08 9:55 Cristian Marussi
2022-06-08 9:55 ` [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported Cristian Marussi
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Cristian Marussi @ 2022-06-08 9:55 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel; +Cc: sudeep.holla, cristian.marussi
SCMI Base protocol agent_name/vendor_id/sub_vendor_id are defined by the
specification as NULL-terminated ASCII strings up to 16-bytes in length.
The underlying buffers and message descriptors are currently bigger than
needed; resize them to fit only the strictly needed 16 bytes.
While at that, convert Base protocol strings handling routines to use the
preferred strscpy.
Fixes: b260fccaebdc2 ("firmware: arm_scmi: Add SCMI v3.1 protocol extended names support")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/firmware/arm_scmi/base.c | 8 ++++----
drivers/firmware/arm_scmi/protocols.h | 2 --
include/linux/scmi_protocol.h | 9 +++++----
3 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c
index d0ac96da1ddf..a52f084a6a87 100644
--- a/drivers/firmware/arm_scmi/base.c
+++ b/drivers/firmware/arm_scmi/base.c
@@ -36,7 +36,7 @@ struct scmi_msg_resp_base_attributes {
struct scmi_msg_resp_base_discover_agent {
__le32 agent_id;
- u8 name[SCMI_MAX_STR_SIZE];
+ u8 name[SCMI_SHORT_NAME_MAX_SIZE];
};
@@ -119,7 +119,7 @@ scmi_base_vendor_id_get(const struct scmi_protocol_handle *ph, bool sub_vendor)
ret = ph->xops->do_xfer(ph, t);
if (!ret)
- memcpy(vendor_id, t->rx.buf, size);
+ strscpy(vendor_id, t->rx.buf, size);
ph->xops->xfer_put(ph, t);
@@ -276,7 +276,7 @@ static int scmi_base_discover_agent_get(const struct scmi_protocol_handle *ph,
ret = ph->xops->do_xfer(ph, t);
if (!ret) {
agent_info = t->rx.buf;
- strlcpy(name, agent_info->name, SCMI_MAX_STR_SIZE);
+ strscpy(name, agent_info->name, SCMI_SHORT_NAME_MAX_SIZE);
}
ph->xops->xfer_put(ph, t);
@@ -375,7 +375,7 @@ static int scmi_base_protocol_init(const struct scmi_protocol_handle *ph)
int id, ret;
u8 *prot_imp;
u32 version;
- char name[SCMI_MAX_STR_SIZE];
+ char name[SCMI_SHORT_NAME_MAX_SIZE];
struct device *dev = ph->dev;
struct scmi_revision_info *rev = scmi_revision_area_get(ph);
diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h
index 73304af5ec4a..c679f3fb8718 100644
--- a/drivers/firmware/arm_scmi/protocols.h
+++ b/drivers/firmware/arm_scmi/protocols.h
@@ -24,8 +24,6 @@
#include <asm/unaligned.h>
-#define SCMI_SHORT_NAME_MAX_SIZE 16
-
#define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0)
#define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16)
#define PROTOCOL_REV_MAJOR(x) ((u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x))))
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index 1c58646ba381..704111f63993 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -13,8 +13,9 @@
#include <linux/notifier.h>
#include <linux/types.h>
-#define SCMI_MAX_STR_SIZE 64
-#define SCMI_MAX_NUM_RATES 16
+#define SCMI_MAX_STR_SIZE 64
+#define SCMI_SHORT_NAME_MAX_SIZE 16
+#define SCMI_MAX_NUM_RATES 16
/**
* struct scmi_revision_info - version information structure
@@ -36,8 +37,8 @@ struct scmi_revision_info {
u8 num_protocols;
u8 num_agents;
u32 impl_ver;
- char vendor_id[SCMI_MAX_STR_SIZE];
- char sub_vendor_id[SCMI_MAX_STR_SIZE];
+ char vendor_id[SCMI_SHORT_NAME_MAX_SIZE];
+ char sub_vendor_id[SCMI_SHORT_NAME_MAX_SIZE];
};
struct scmi_clock_info {
--
2.32.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported
2022-06-08 9:55 [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Cristian Marussi
@ 2022-06-08 9:55 ` Cristian Marussi
2022-06-08 15:19 ` Peter Hilber
2022-06-08 16:40 ` [PATCH v2 " Cristian Marussi
2022-06-08 9:55 ` [PATCH 3/3] firmware: arm_scmi: Use preferred strscpy to handle strings Cristian Marussi
2022-06-10 16:59 ` [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Sudeep Holla
2 siblings, 2 replies; 9+ messages in thread
From: Cristian Marussi @ 2022-06-08 9:55 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: sudeep.holla, cristian.marussi, Peter Hilber
Avoid to invoke SENSOR_AXIS_NAME_GET on sensors that have not declared at
least one of their axes as supporting extended names.
Since the returned list of axes supporting extended names is not
necessarily comprising all the existing axes of the specified sensor,
take care also to properly pick the ax descriptor from the id embedded
in the reply.
Cc: Peter Hilber <peter.hilber@opensynergy.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Fixes: 802b0bed011e ("firmware: arm_scmi: Add SCMI v3.1 SENSOR_AXIS_NAME_GET support")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/firmware/arm_scmi/sensors.c | 55 +++++++++++++++++++++++------
1 file changed, 45 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
index 75b9d716508e..58fe4f0175be 100644
--- a/drivers/firmware/arm_scmi/sensors.c
+++ b/drivers/firmware/arm_scmi/sensors.c
@@ -358,15 +358,20 @@ static int scmi_sensor_update_intervals(const struct scmi_protocol_handle *ph,
return ph->hops->iter_response_run(iter);
}
+struct scmi_apriv {
+ bool any_axes_support_extended_names;
+ struct scmi_sensor_info *s;
+};
+
static void iter_axes_desc_prepare_message(void *message,
const unsigned int desc_index,
const void *priv)
{
struct scmi_msg_sensor_axis_description_get *msg = message;
- const struct scmi_sensor_info *s = priv;
+ const struct scmi_apriv *apriv = priv;
/* Set the number of sensors to be skipped/already read */
- msg->id = cpu_to_le32(s->id);
+ msg->id = cpu_to_le32(apriv->s->id);
msg->axis_desc_index = cpu_to_le32(desc_index);
}
@@ -393,12 +398,14 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
u32 attrh, attrl;
struct scmi_sensor_axis_info *a;
size_t dsize = SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ;
- struct scmi_sensor_info *s = priv;
+ struct scmi_apriv *apriv = priv;
const struct scmi_axis_descriptor *adesc = st->priv;
attrl = le32_to_cpu(adesc->attributes_low);
+ if (SUPPORTS_EXTENDED_AXIS_NAMES(attrl))
+ apriv->any_axes_support_extended_names = true;
- a = &s->axis[st->desc_index + st->loop_idx];
+ a = &apriv->s->axis[st->desc_index + st->loop_idx];
a->id = le32_to_cpu(adesc->id);
a->extended_attrs = SUPPORTS_EXTEND_ATTRS(attrl);
@@ -444,10 +451,18 @@ iter_axes_extended_name_process_response(const struct scmi_protocol_handle *ph,
void *priv)
{
struct scmi_sensor_axis_info *a;
- const struct scmi_sensor_info *s = priv;
+ const struct scmi_apriv *apriv = priv;
struct scmi_sensor_axis_name_descriptor *adesc = st->priv;
- a = &s->axis[st->desc_index + st->loop_idx];
+ if (adesc->axis_id >= st->max_resources)
+ return -EPROTO;
+
+ /*
+ * Pick the corresponding descriptor based on the axis_id embedded
+ * in the reply since the list of axes supporting extended names
+ * can be a subset of all the axes.
+ */
+ a = &apriv->s->axis[adesc->axis_id];
strscpy(a->name, adesc->name, SCMI_MAX_STR_SIZE);
st->priv = ++adesc;
@@ -458,21 +473,36 @@ static int
scmi_sensor_axis_extended_names_get(const struct scmi_protocol_handle *ph,
struct scmi_sensor_info *s)
{
+ int ret;
void *iter;
struct scmi_iterator_ops ops = {
.prepare_message = iter_axes_desc_prepare_message,
.update_state = iter_axes_extended_name_update_state,
.process_response = iter_axes_extended_name_process_response,
};
+ struct scmi_apriv apriv = {
+ .any_axes_support_extended_names = false,
+ .s = s,
+ };
iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
SENSOR_AXIS_NAME_GET,
sizeof(struct scmi_msg_sensor_axis_description_get),
- s);
+ &apriv);
if (IS_ERR(iter))
return PTR_ERR(iter);
- return ph->hops->iter_response_run(iter);
+ /*
+ * Do not cause whole protocol initialization failure when failing to
+ * get extended names for axes.
+ */
+ ret = ph->hops->iter_response_run(iter);
+ if (ret)
+ dev_warn(ph->dev,
+ "Failed to get axes extended names for %s (ret:%d).\n",
+ s->name, ret);
+
+ return 0;
}
static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
@@ -486,6 +516,10 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
.update_state = iter_axes_desc_update_state,
.process_response = iter_axes_desc_process_response,
};
+ struct scmi_apriv apriv = {
+ .any_axes_support_extended_names = false,
+ .s = s,
+ };
s->axis = devm_kcalloc(ph->dev, s->num_axis,
sizeof(*s->axis), GFP_KERNEL);
@@ -495,7 +529,7 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
SENSOR_AXIS_DESCRIPTION_GET,
sizeof(struct scmi_msg_sensor_axis_description_get),
- s);
+ &apriv);
if (IS_ERR(iter))
return PTR_ERR(iter);
@@ -503,7 +537,8 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
if (ret)
return ret;
- if (PROTOCOL_REV_MAJOR(version) >= 0x3)
+ if (PROTOCOL_REV_MAJOR(version) >= 0x3 &&
+ apriv.any_axes_support_extended_names)
ret = scmi_sensor_axis_extended_names_get(ph, s);
return ret;
--
2.32.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] firmware: arm_scmi: Use preferred strscpy to handle strings
2022-06-08 9:55 [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Cristian Marussi
2022-06-08 9:55 ` [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported Cristian Marussi
@ 2022-06-08 9:55 ` Cristian Marussi
2022-06-08 15:19 ` Peter Hilber
2022-06-10 16:59 ` [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Sudeep Holla
2 siblings, 1 reply; 9+ messages in thread
From: Cristian Marussi @ 2022-06-08 9:55 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: sudeep.holla, cristian.marussi, Peter Hilber
Remove strlcpy calls used to collect short domain names of SCMI resources
in favour of the preferred strscpy; while doing that change also the used
count argument of strscpy to make always use of SCMI_SHORT_NAME_MAX_SIZE
while dealing with short domain names, so as to limit the possibility that
an ill-formed non-NULL terminated short reply from the SCMI platform
firmware can leak stale content laying in the underlying transport shared
memory area.
Cc: Peter Hilber <peter.hilber@opensynergy.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Fixes: ca64b719a1e66 ("firmware: arm_scmi: use strlcpy to ensure NULL-terminated strings")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
drivers/firmware/arm_scmi/clock.c | 2 +-
drivers/firmware/arm_scmi/perf.c | 2 +-
drivers/firmware/arm_scmi/power.c | 2 +-
drivers/firmware/arm_scmi/reset.c | 2 +-
drivers/firmware/arm_scmi/sensors.c | 4 ++--
drivers/firmware/arm_scmi/voltage.c | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
index 1a718faa4192..c7a83f6e38e5 100644
--- a/drivers/firmware/arm_scmi/clock.c
+++ b/drivers/firmware/arm_scmi/clock.c
@@ -153,7 +153,7 @@ static int scmi_clock_attributes_get(const struct scmi_protocol_handle *ph,
if (!ret) {
u32 latency = 0;
attributes = le32_to_cpu(attr->attributes);
- strlcpy(clk->name, attr->name, SCMI_MAX_STR_SIZE);
+ strscpy(clk->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
/* clock_enable_latency field is present only since SCMI v3.1 */
if (PROTOCOL_REV_MAJOR(version) >= 0x2)
latency = le32_to_cpu(attr->clock_enable_latency);
diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
index c1f701623058..bbb0331801ff 100644
--- a/drivers/firmware/arm_scmi/perf.c
+++ b/drivers/firmware/arm_scmi/perf.c
@@ -252,7 +252,7 @@ scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
dom_info->mult_factor =
(dom_info->sustained_freq_khz * 1000) /
dom_info->sustained_perf_level;
- strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
+ strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
}
ph->xops->xfer_put(ph, t);
diff --git a/drivers/firmware/arm_scmi/power.c b/drivers/firmware/arm_scmi/power.c
index 964882cc8747..356e83631664 100644
--- a/drivers/firmware/arm_scmi/power.c
+++ b/drivers/firmware/arm_scmi/power.c
@@ -122,7 +122,7 @@ scmi_power_domain_attributes_get(const struct scmi_protocol_handle *ph,
dom_info->state_set_notify = SUPPORTS_STATE_SET_NOTIFY(flags);
dom_info->state_set_async = SUPPORTS_STATE_SET_ASYNC(flags);
dom_info->state_set_sync = SUPPORTS_STATE_SET_SYNC(flags);
- strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
+ strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
}
ph->xops->xfer_put(ph, t);
diff --git a/drivers/firmware/arm_scmi/reset.c b/drivers/firmware/arm_scmi/reset.c
index a420a9102094..673f3eb498f4 100644
--- a/drivers/firmware/arm_scmi/reset.c
+++ b/drivers/firmware/arm_scmi/reset.c
@@ -116,7 +116,7 @@ scmi_reset_domain_attributes_get(const struct scmi_protocol_handle *ph,
dom_info->latency_us = le32_to_cpu(attr->latency);
if (dom_info->latency_us == U32_MAX)
dom_info->latency_us = 0;
- strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
+ strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
}
ph->xops->xfer_put(ph, t);
diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
index 58fe4f0175be..42efaee27b7c 100644
--- a/drivers/firmware/arm_scmi/sensors.c
+++ b/drivers/firmware/arm_scmi/sensors.c
@@ -412,7 +412,7 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
attrh = le32_to_cpu(adesc->attributes_high);
a->scale = S32_EXT(SENSOR_SCALE(attrh));
a->type = SENSOR_TYPE(attrh);
- strscpy(a->name, adesc->name, SCMI_MAX_STR_SIZE);
+ strscpy(a->name, adesc->name, SCMI_SHORT_NAME_MAX_SIZE);
if (a->extended_attrs) {
unsigned int ares = le32_to_cpu(adesc->resolution);
@@ -633,7 +633,7 @@ iter_sens_descr_process_response(const struct scmi_protocol_handle *ph,
SUPPORTS_AXIS(attrh) ?
SENSOR_AXIS_NUMBER(attrh) : 0,
SCMI_MAX_NUM_SENSOR_AXIS);
- strscpy(s->name, sdesc->name, SCMI_MAX_STR_SIZE);
+ strscpy(s->name, sdesc->name, SCMI_SHORT_NAME_MAX_SIZE);
/*
* If supported overwrite short name with the extended
diff --git a/drivers/firmware/arm_scmi/voltage.c b/drivers/firmware/arm_scmi/voltage.c
index 97df6d3dd131..5de93f637bd4 100644
--- a/drivers/firmware/arm_scmi/voltage.c
+++ b/drivers/firmware/arm_scmi/voltage.c
@@ -233,7 +233,7 @@ static int scmi_voltage_descriptors_get(const struct scmi_protocol_handle *ph,
v = vinfo->domains + dom;
v->id = dom;
attributes = le32_to_cpu(resp_dom->attr);
- strlcpy(v->name, resp_dom->name, SCMI_MAX_STR_SIZE);
+ strscpy(v->name, resp_dom->name, SCMI_SHORT_NAME_MAX_SIZE);
/*
* If supported overwrite short name with the extended one;
--
2.32.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported
2022-06-08 9:55 ` [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported Cristian Marussi
@ 2022-06-08 15:19 ` Peter Hilber
2022-06-08 16:26 ` Cristian Marussi
2022-06-08 16:40 ` [PATCH v2 " Cristian Marussi
1 sibling, 1 reply; 9+ messages in thread
From: Peter Hilber @ 2022-06-08 15:19 UTC (permalink / raw)
To: Cristian Marussi, linux-kernel, linux-arm-kernel
Cc: sudeep.holla, Peter Hilber
Hi Cristian,
I think I found two missing endianness conversions, see below.
Best regards,
Peter
On 08.06.22 11:55, Cristian Marussi wrote:
> Avoid to invoke SENSOR_AXIS_NAME_GET on sensors that have not declared at
> least one of their axes as supporting extended names.
>
> Since the returned list of axes supporting extended names is not
> necessarily comprising all the existing axes of the specified sensor,
> take care also to properly pick the ax descriptor from the id embedded
> in the reply.
>
> Cc: Peter Hilber <peter.hilber@opensynergy.com>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Fixes: 802b0bed011e ("firmware: arm_scmi: Add SCMI v3.1 SENSOR_AXIS_NAME_GET support")
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> ---
> drivers/firmware/arm_scmi/sensors.c | 55 +++++++++++++++++++++++------
> 1 file changed, 45 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
> index 75b9d716508e..58fe4f0175be 100644
> --- a/drivers/firmware/arm_scmi/sensors.c
> +++ b/drivers/firmware/arm_scmi/sensors.c
> @@ -358,15 +358,20 @@ static int scmi_sensor_update_intervals(const struct scmi_protocol_handle *ph,
> return ph->hops->iter_response_run(iter);
> }
>
> +struct scmi_apriv {
> + bool any_axes_support_extended_names;
> + struct scmi_sensor_info *s;
> +};
> +
> static void iter_axes_desc_prepare_message(void *message,
> const unsigned int desc_index,
> const void *priv)
> {
> struct scmi_msg_sensor_axis_description_get *msg = message;
> - const struct scmi_sensor_info *s = priv;
> + const struct scmi_apriv *apriv = priv;
>
> /* Set the number of sensors to be skipped/already read */
> - msg->id = cpu_to_le32(s->id);
> + msg->id = cpu_to_le32(apriv->s->id);
> msg->axis_desc_index = cpu_to_le32(desc_index);
> }
>
> @@ -393,12 +398,14 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
> u32 attrh, attrl;
> struct scmi_sensor_axis_info *a;
> size_t dsize = SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ;
> - struct scmi_sensor_info *s = priv;
> + struct scmi_apriv *apriv = priv;
> const struct scmi_axis_descriptor *adesc = st->priv;
>
> attrl = le32_to_cpu(adesc->attributes_low);
> + if (SUPPORTS_EXTENDED_AXIS_NAMES(attrl))
> + apriv->any_axes_support_extended_names = true;
>
> - a = &s->axis[st->desc_index + st->loop_idx];
> + a = &apriv->s->axis[st->desc_index + st->loop_idx];
> a->id = le32_to_cpu(adesc->id);
> a->extended_attrs = SUPPORTS_EXTEND_ATTRS(attrl);
>
> @@ -444,10 +451,18 @@ iter_axes_extended_name_process_response(const struct scmi_protocol_handle *ph,
> void *priv)
> {
> struct scmi_sensor_axis_info *a;
> - const struct scmi_sensor_info *s = priv;
> + const struct scmi_apriv *apriv = priv;
> struct scmi_sensor_axis_name_descriptor *adesc = st->priv;
>
> - a = &s->axis[st->desc_index + st->loop_idx];
> + if (adesc->axis_id >= st->max_resources)
I think adesc->axis_id uses in this function need to be wrapped with
le32_to_cpu() (here and below as well).
> + return -EPROTO;
> +
> + /*
> + * Pick the corresponding descriptor based on the axis_id embedded
> + * in the reply since the list of axes supporting extended names
> + * can be a subset of all the axes.
> + */
> + a = &apriv->s->axis[adesc->axis_id];
> strscpy(a->name, adesc->name, SCMI_MAX_STR_SIZE);
> st->priv = ++adesc;
>
> @@ -458,21 +473,36 @@ static int
> scmi_sensor_axis_extended_names_get(const struct scmi_protocol_handle *ph,
> struct scmi_sensor_info *s)
> {
> + int ret;
> void *iter;
> struct scmi_iterator_ops ops = {
> .prepare_message = iter_axes_desc_prepare_message,
> .update_state = iter_axes_extended_name_update_state,
> .process_response = iter_axes_extended_name_process_response,
> };
> + struct scmi_apriv apriv = {
> + .any_axes_support_extended_names = false,
> + .s = s,
> + };
>
> iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
> SENSOR_AXIS_NAME_GET,
> sizeof(struct scmi_msg_sensor_axis_description_get),
> - s);
> + &apriv);
> if (IS_ERR(iter))
> return PTR_ERR(iter);
>
> - return ph->hops->iter_response_run(iter);
> + /*
> + * Do not cause whole protocol initialization failure when failing to
> + * get extended names for axes.
> + */
> + ret = ph->hops->iter_response_run(iter);
> + if (ret)
> + dev_warn(ph->dev,
> + "Failed to get axes extended names for %s (ret:%d).\n",
> + s->name, ret);
> +
> + return 0;
> }
>
> static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> @@ -486,6 +516,10 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> .update_state = iter_axes_desc_update_state,
> .process_response = iter_axes_desc_process_response,
> };
> + struct scmi_apriv apriv = {
> + .any_axes_support_extended_names = false,
> + .s = s,
> + };
>
> s->axis = devm_kcalloc(ph->dev, s->num_axis,
> sizeof(*s->axis), GFP_KERNEL);
> @@ -495,7 +529,7 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
> SENSOR_AXIS_DESCRIPTION_GET,
> sizeof(struct scmi_msg_sensor_axis_description_get),
> - s);
> + &apriv);
> if (IS_ERR(iter))
> return PTR_ERR(iter);
>
> @@ -503,7 +537,8 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> if (ret)
> return ret;
>
> - if (PROTOCOL_REV_MAJOR(version) >= 0x3)
> + if (PROTOCOL_REV_MAJOR(version) >= 0x3 &&
> + apriv.any_axes_support_extended_names)
> ret = scmi_sensor_axis_extended_names_get(ph, s);
>
> return ret;
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] firmware: arm_scmi: Use preferred strscpy to handle strings
2022-06-08 9:55 ` [PATCH 3/3] firmware: arm_scmi: Use preferred strscpy to handle strings Cristian Marussi
@ 2022-06-08 15:19 ` Peter Hilber
0 siblings, 0 replies; 9+ messages in thread
From: Peter Hilber @ 2022-06-08 15:19 UTC (permalink / raw)
To: Cristian Marussi, linux-kernel, linux-arm-kernel; +Cc: sudeep.holla
On 08.06.22 11:55, Cristian Marussi wrote:
> Remove strlcpy calls used to collect short domain names of SCMI resources
> in favour of the preferred strscpy; while doing that change also the used
> count argument of strscpy to make always use of SCMI_SHORT_NAME_MAX_SIZE
> while dealing with short domain names, so as to limit the possibility that
> an ill-formed non-NULL terminated short reply from the SCMI platform
> firmware can leak stale content laying in the underlying transport shared
> memory area.
>
> Cc: Peter Hilber <peter.hilber@opensynergy.com>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Fixes: ca64b719a1e66 ("firmware: arm_scmi: use strlcpy to ensure NULL-terminated strings")
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Reviewed-by: Peter Hilber <peter.hilber@opensynergy.com>
> ---
> drivers/firmware/arm_scmi/clock.c | 2 +-
> drivers/firmware/arm_scmi/perf.c | 2 +-
> drivers/firmware/arm_scmi/power.c | 2 +-
> drivers/firmware/arm_scmi/reset.c | 2 +-
> drivers/firmware/arm_scmi/sensors.c | 4 ++--
> drivers/firmware/arm_scmi/voltage.c | 2 +-
> 6 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
> index 1a718faa4192..c7a83f6e38e5 100644
> --- a/drivers/firmware/arm_scmi/clock.c
> +++ b/drivers/firmware/arm_scmi/clock.c
> @@ -153,7 +153,7 @@ static int scmi_clock_attributes_get(const struct scmi_protocol_handle *ph,
> if (!ret) {
> u32 latency = 0;
> attributes = le32_to_cpu(attr->attributes);
> - strlcpy(clk->name, attr->name, SCMI_MAX_STR_SIZE);
> + strscpy(clk->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
> /* clock_enable_latency field is present only since SCMI v3.1 */
> if (PROTOCOL_REV_MAJOR(version) >= 0x2)
> latency = le32_to_cpu(attr->clock_enable_latency);
> diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
> index c1f701623058..bbb0331801ff 100644
> --- a/drivers/firmware/arm_scmi/perf.c
> +++ b/drivers/firmware/arm_scmi/perf.c
> @@ -252,7 +252,7 @@ scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
> dom_info->mult_factor =
> (dom_info->sustained_freq_khz * 1000) /
> dom_info->sustained_perf_level;
> - strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
> + strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
> }
>
> ph->xops->xfer_put(ph, t);
> diff --git a/drivers/firmware/arm_scmi/power.c b/drivers/firmware/arm_scmi/power.c
> index 964882cc8747..356e83631664 100644
> --- a/drivers/firmware/arm_scmi/power.c
> +++ b/drivers/firmware/arm_scmi/power.c
> @@ -122,7 +122,7 @@ scmi_power_domain_attributes_get(const struct scmi_protocol_handle *ph,
> dom_info->state_set_notify = SUPPORTS_STATE_SET_NOTIFY(flags);
> dom_info->state_set_async = SUPPORTS_STATE_SET_ASYNC(flags);
> dom_info->state_set_sync = SUPPORTS_STATE_SET_SYNC(flags);
> - strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
> + strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
> }
> ph->xops->xfer_put(ph, t);
>
> diff --git a/drivers/firmware/arm_scmi/reset.c b/drivers/firmware/arm_scmi/reset.c
> index a420a9102094..673f3eb498f4 100644
> --- a/drivers/firmware/arm_scmi/reset.c
> +++ b/drivers/firmware/arm_scmi/reset.c
> @@ -116,7 +116,7 @@ scmi_reset_domain_attributes_get(const struct scmi_protocol_handle *ph,
> dom_info->latency_us = le32_to_cpu(attr->latency);
> if (dom_info->latency_us == U32_MAX)
> dom_info->latency_us = 0;
> - strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
> + strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
> }
>
> ph->xops->xfer_put(ph, t);
> diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
> index 58fe4f0175be..42efaee27b7c 100644
> --- a/drivers/firmware/arm_scmi/sensors.c
> +++ b/drivers/firmware/arm_scmi/sensors.c
> @@ -412,7 +412,7 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
> attrh = le32_to_cpu(adesc->attributes_high);
> a->scale = S32_EXT(SENSOR_SCALE(attrh));
> a->type = SENSOR_TYPE(attrh);
> - strscpy(a->name, adesc->name, SCMI_MAX_STR_SIZE);
> + strscpy(a->name, adesc->name, SCMI_SHORT_NAME_MAX_SIZE);
>
> if (a->extended_attrs) {
> unsigned int ares = le32_to_cpu(adesc->resolution);
> @@ -633,7 +633,7 @@ iter_sens_descr_process_response(const struct scmi_protocol_handle *ph,
> SUPPORTS_AXIS(attrh) ?
> SENSOR_AXIS_NUMBER(attrh) : 0,
> SCMI_MAX_NUM_SENSOR_AXIS);
> - strscpy(s->name, sdesc->name, SCMI_MAX_STR_SIZE);
> + strscpy(s->name, sdesc->name, SCMI_SHORT_NAME_MAX_SIZE);
>
> /*
> * If supported overwrite short name with the extended
> diff --git a/drivers/firmware/arm_scmi/voltage.c b/drivers/firmware/arm_scmi/voltage.c
> index 97df6d3dd131..5de93f637bd4 100644
> --- a/drivers/firmware/arm_scmi/voltage.c
> +++ b/drivers/firmware/arm_scmi/voltage.c
> @@ -233,7 +233,7 @@ static int scmi_voltage_descriptors_get(const struct scmi_protocol_handle *ph,
> v = vinfo->domains + dom;
> v->id = dom;
> attributes = le32_to_cpu(resp_dom->attr);
> - strlcpy(v->name, resp_dom->name, SCMI_MAX_STR_SIZE);
> + strscpy(v->name, resp_dom->name, SCMI_SHORT_NAME_MAX_SIZE);
>
> /*
> * If supported overwrite short name with the extended one;
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported
2022-06-08 15:19 ` Peter Hilber
@ 2022-06-08 16:26 ` Cristian Marussi
0 siblings, 0 replies; 9+ messages in thread
From: Cristian Marussi @ 2022-06-08 16:26 UTC (permalink / raw)
To: Peter Hilber; +Cc: linux-kernel, linux-arm-kernel, sudeep.holla
On Wed, Jun 08, 2022 at 05:19:02PM +0200, Peter Hilber wrote:
> Hi Cristian,
>
> I think I found two missing endianness conversions, see below.
>
> Best regards,
>
> Peter
[snip]
> > @@ -393,12 +398,14 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
> > u32 attrh, attrl;
> > struct scmi_sensor_axis_info *a;
> > size_t dsize = SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ;
> > - struct scmi_sensor_info *s = priv;
> > + struct scmi_apriv *apriv = priv;
> > const struct scmi_axis_descriptor *adesc = st->priv;
> >
> > attrl = le32_to_cpu(adesc->attributes_low);
> > + if (SUPPORTS_EXTENDED_AXIS_NAMES(attrl))
> > + apriv->any_axes_support_extended_names = true;
> >
> > - a = &s->axis[st->desc_index + st->loop_idx];
> > + a = &apriv->s->axis[st->desc_index + st->loop_idx];
> > a->id = le32_to_cpu(adesc->id);
> > a->extended_attrs = SUPPORTS_EXTEND_ATTRS(attrl);
> >
> > @@ -444,10 +451,18 @@ iter_axes_extended_name_process_response(const struct scmi_protocol_handle *ph,
> > void *priv)
> > {
> > struct scmi_sensor_axis_info *a;
> > - const struct scmi_sensor_info *s = priv;
> > + const struct scmi_apriv *apriv = priv;
> > struct scmi_sensor_axis_name_descriptor *adesc = st->priv;
> >
> > - a = &s->axis[st->desc_index + st->loop_idx];
> > + if (adesc->axis_id >= st->max_resources)
>
> I think adesc->axis_id uses in this function need to be wrapped with
> le32_to_cpu() (here and below as well).
>
...damn, my bad ... I'm posting a V2.
Thanks for the review !
Cristian
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported
2022-06-08 9:55 ` [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported Cristian Marussi
2022-06-08 15:19 ` Peter Hilber
@ 2022-06-08 16:40 ` Cristian Marussi
2022-06-08 16:49 ` Peter Hilber
1 sibling, 1 reply; 9+ messages in thread
From: Cristian Marussi @ 2022-06-08 16:40 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel
Cc: sudeep.holla, cristian.marussi, Peter Hilber
Avoid to invoke SENSOR_AXIS_NAME_GET on sensors that have not declared at
least one of their axes as supporting extended names.
Since the returned list of axes supporting extended names is not
necessarily comprising all the existing axes of the specified sensor,
take care also to properly pick the ax descriptor from the id embedded
in the reply.
Cc: Peter Hilber <peter.hilber@opensynergy.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Fixes: 802b0bed011e ("firmware: arm_scmi: Add SCMI v3.1 SENSOR_AXIS_NAME_GET support")
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
V1 --> v2
- fixed missing endianity conversion
---
drivers/firmware/arm_scmi/sensors.c | 56 +++++++++++++++++++++++------
1 file changed, 46 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
index 75b9d716508e..8a93dd944c49 100644
--- a/drivers/firmware/arm_scmi/sensors.c
+++ b/drivers/firmware/arm_scmi/sensors.c
@@ -358,15 +358,20 @@ static int scmi_sensor_update_intervals(const struct scmi_protocol_handle *ph,
return ph->hops->iter_response_run(iter);
}
+struct scmi_apriv {
+ bool any_axes_support_extended_names;
+ struct scmi_sensor_info *s;
+};
+
static void iter_axes_desc_prepare_message(void *message,
const unsigned int desc_index,
const void *priv)
{
struct scmi_msg_sensor_axis_description_get *msg = message;
- const struct scmi_sensor_info *s = priv;
+ const struct scmi_apriv *apriv = priv;
/* Set the number of sensors to be skipped/already read */
- msg->id = cpu_to_le32(s->id);
+ msg->id = cpu_to_le32(apriv->s->id);
msg->axis_desc_index = cpu_to_le32(desc_index);
}
@@ -393,12 +398,14 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
u32 attrh, attrl;
struct scmi_sensor_axis_info *a;
size_t dsize = SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ;
- struct scmi_sensor_info *s = priv;
+ struct scmi_apriv *apriv = priv;
const struct scmi_axis_descriptor *adesc = st->priv;
attrl = le32_to_cpu(adesc->attributes_low);
+ if (SUPPORTS_EXTENDED_AXIS_NAMES(attrl))
+ apriv->any_axes_support_extended_names = true;
- a = &s->axis[st->desc_index + st->loop_idx];
+ a = &apriv->s->axis[st->desc_index + st->loop_idx];
a->id = le32_to_cpu(adesc->id);
a->extended_attrs = SUPPORTS_EXTEND_ATTRS(attrl);
@@ -444,10 +451,19 @@ iter_axes_extended_name_process_response(const struct scmi_protocol_handle *ph,
void *priv)
{
struct scmi_sensor_axis_info *a;
- const struct scmi_sensor_info *s = priv;
+ const struct scmi_apriv *apriv = priv;
struct scmi_sensor_axis_name_descriptor *adesc = st->priv;
+ u32 axis_id = le32_to_cpu(adesc->axis_id);
+
+ if (axis_id >= st->max_resources)
+ return -EPROTO;
- a = &s->axis[st->desc_index + st->loop_idx];
+ /*
+ * Pick the corresponding descriptor based on the axis_id embedded
+ * in the reply since the list of axes supporting extended names
+ * can be a subset of all the axes.
+ */
+ a = &apriv->s->axis[axis_id];
strscpy(a->name, adesc->name, SCMI_MAX_STR_SIZE);
st->priv = ++adesc;
@@ -458,21 +474,36 @@ static int
scmi_sensor_axis_extended_names_get(const struct scmi_protocol_handle *ph,
struct scmi_sensor_info *s)
{
+ int ret;
void *iter;
struct scmi_iterator_ops ops = {
.prepare_message = iter_axes_desc_prepare_message,
.update_state = iter_axes_extended_name_update_state,
.process_response = iter_axes_extended_name_process_response,
};
+ struct scmi_apriv apriv = {
+ .any_axes_support_extended_names = false,
+ .s = s,
+ };
iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
SENSOR_AXIS_NAME_GET,
sizeof(struct scmi_msg_sensor_axis_description_get),
- s);
+ &apriv);
if (IS_ERR(iter))
return PTR_ERR(iter);
- return ph->hops->iter_response_run(iter);
+ /*
+ * Do not cause whole protocol initialization failure when failing to
+ * get extended names for axes.
+ */
+ ret = ph->hops->iter_response_run(iter);
+ if (ret)
+ dev_warn(ph->dev,
+ "Failed to get axes extended names for %s (ret:%d).\n",
+ s->name, ret);
+
+ return 0;
}
static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
@@ -486,6 +517,10 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
.update_state = iter_axes_desc_update_state,
.process_response = iter_axes_desc_process_response,
};
+ struct scmi_apriv apriv = {
+ .any_axes_support_extended_names = false,
+ .s = s,
+ };
s->axis = devm_kcalloc(ph->dev, s->num_axis,
sizeof(*s->axis), GFP_KERNEL);
@@ -495,7 +530,7 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
SENSOR_AXIS_DESCRIPTION_GET,
sizeof(struct scmi_msg_sensor_axis_description_get),
- s);
+ &apriv);
if (IS_ERR(iter))
return PTR_ERR(iter);
@@ -503,7 +538,8 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
if (ret)
return ret;
- if (PROTOCOL_REV_MAJOR(version) >= 0x3)
+ if (PROTOCOL_REV_MAJOR(version) >= 0x3 &&
+ apriv.any_axes_support_extended_names)
ret = scmi_sensor_axis_extended_names_get(ph, s);
return ret;
--
2.32.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported
2022-06-08 16:40 ` [PATCH v2 " Cristian Marussi
@ 2022-06-08 16:49 ` Peter Hilber
0 siblings, 0 replies; 9+ messages in thread
From: Peter Hilber @ 2022-06-08 16:49 UTC (permalink / raw)
To: Cristian Marussi, linux-kernel, linux-arm-kernel; +Cc: sudeep.holla
On 08.06.22 18:40, Cristian Marussi wrote:
> Avoid to invoke SENSOR_AXIS_NAME_GET on sensors that have not declared at
> least one of their axes as supporting extended names.
>
> Since the returned list of axes supporting extended names is not
> necessarily comprising all the existing axes of the specified sensor,
> take care also to properly pick the ax descriptor from the id embedded
> in the reply.
>
> Cc: Peter Hilber <peter.hilber@opensynergy.com>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Fixes: 802b0bed011e ("firmware: arm_scmi: Add SCMI v3.1 SENSOR_AXIS_NAME_GET support")
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Reviewed-by: Peter Hilber <peter.hilber@opensynergy.com>
> ---
> V1 --> v2
> - fixed missing endianity conversion
> ---
> drivers/firmware/arm_scmi/sensors.c | 56 +++++++++++++++++++++++------
> 1 file changed, 46 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
> index 75b9d716508e..8a93dd944c49 100644
> --- a/drivers/firmware/arm_scmi/sensors.c
> +++ b/drivers/firmware/arm_scmi/sensors.c
> @@ -358,15 +358,20 @@ static int scmi_sensor_update_intervals(const struct scmi_protocol_handle *ph,
> return ph->hops->iter_response_run(iter);
> }
>
> +struct scmi_apriv {
> + bool any_axes_support_extended_names;
> + struct scmi_sensor_info *s;
> +};
> +
> static void iter_axes_desc_prepare_message(void *message,
> const unsigned int desc_index,
> const void *priv)
> {
> struct scmi_msg_sensor_axis_description_get *msg = message;
> - const struct scmi_sensor_info *s = priv;
> + const struct scmi_apriv *apriv = priv;
>
> /* Set the number of sensors to be skipped/already read */
> - msg->id = cpu_to_le32(s->id);
> + msg->id = cpu_to_le32(apriv->s->id);
> msg->axis_desc_index = cpu_to_le32(desc_index);
> }
>
> @@ -393,12 +398,14 @@ iter_axes_desc_process_response(const struct scmi_protocol_handle *ph,
> u32 attrh, attrl;
> struct scmi_sensor_axis_info *a;
> size_t dsize = SCMI_MSG_RESP_AXIS_DESCR_BASE_SZ;
> - struct scmi_sensor_info *s = priv;
> + struct scmi_apriv *apriv = priv;
> const struct scmi_axis_descriptor *adesc = st->priv;
>
> attrl = le32_to_cpu(adesc->attributes_low);
> + if (SUPPORTS_EXTENDED_AXIS_NAMES(attrl))
> + apriv->any_axes_support_extended_names = true;
>
> - a = &s->axis[st->desc_index + st->loop_idx];
> + a = &apriv->s->axis[st->desc_index + st->loop_idx];
> a->id = le32_to_cpu(adesc->id);
> a->extended_attrs = SUPPORTS_EXTEND_ATTRS(attrl);
>
> @@ -444,10 +451,19 @@ iter_axes_extended_name_process_response(const struct scmi_protocol_handle *ph,
> void *priv)
> {
> struct scmi_sensor_axis_info *a;
> - const struct scmi_sensor_info *s = priv;
> + const struct scmi_apriv *apriv = priv;
> struct scmi_sensor_axis_name_descriptor *adesc = st->priv;
> + u32 axis_id = le32_to_cpu(adesc->axis_id);
> +
> + if (axis_id >= st->max_resources)
> + return -EPROTO;
>
> - a = &s->axis[st->desc_index + st->loop_idx];
> + /*
> + * Pick the corresponding descriptor based on the axis_id embedded
> + * in the reply since the list of axes supporting extended names
> + * can be a subset of all the axes.
> + */
> + a = &apriv->s->axis[axis_id];
> strscpy(a->name, adesc->name, SCMI_MAX_STR_SIZE);
> st->priv = ++adesc;
>
> @@ -458,21 +474,36 @@ static int
> scmi_sensor_axis_extended_names_get(const struct scmi_protocol_handle *ph,
> struct scmi_sensor_info *s)
> {
> + int ret;
> void *iter;
> struct scmi_iterator_ops ops = {
> .prepare_message = iter_axes_desc_prepare_message,
> .update_state = iter_axes_extended_name_update_state,
> .process_response = iter_axes_extended_name_process_response,
> };
> + struct scmi_apriv apriv = {
> + .any_axes_support_extended_names = false,
> + .s = s,
> + };
>
> iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
> SENSOR_AXIS_NAME_GET,
> sizeof(struct scmi_msg_sensor_axis_description_get),
> - s);
> + &apriv);
> if (IS_ERR(iter))
> return PTR_ERR(iter);
>
> - return ph->hops->iter_response_run(iter);
> + /*
> + * Do not cause whole protocol initialization failure when failing to
> + * get extended names for axes.
> + */
> + ret = ph->hops->iter_response_run(iter);
> + if (ret)
> + dev_warn(ph->dev,
> + "Failed to get axes extended names for %s (ret:%d).\n",
> + s->name, ret);
> +
> + return 0;
> }
>
> static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> @@ -486,6 +517,10 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> .update_state = iter_axes_desc_update_state,
> .process_response = iter_axes_desc_process_response,
> };
> + struct scmi_apriv apriv = {
> + .any_axes_support_extended_names = false,
> + .s = s,
> + };
>
> s->axis = devm_kcalloc(ph->dev, s->num_axis,
> sizeof(*s->axis), GFP_KERNEL);
> @@ -495,7 +530,7 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> iter = ph->hops->iter_response_init(ph, &ops, s->num_axis,
> SENSOR_AXIS_DESCRIPTION_GET,
> sizeof(struct scmi_msg_sensor_axis_description_get),
> - s);
> + &apriv);
> if (IS_ERR(iter))
> return PTR_ERR(iter);
>
> @@ -503,7 +538,8 @@ static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph,
> if (ret)
> return ret;
>
> - if (PROTOCOL_REV_MAJOR(version) >= 0x3)
> + if (PROTOCOL_REV_MAJOR(version) >= 0x3 &&
> + apriv.any_axes_support_extended_names)
> ret = scmi_sensor_axis_extended_names_get(ph, s);
>
> return ret;
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes
2022-06-08 9:55 [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Cristian Marussi
2022-06-08 9:55 ` [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported Cristian Marussi
2022-06-08 9:55 ` [PATCH 3/3] firmware: arm_scmi: Use preferred strscpy to handle strings Cristian Marussi
@ 2022-06-10 16:59 ` Sudeep Holla
2 siblings, 0 replies; 9+ messages in thread
From: Sudeep Holla @ 2022-06-10 16:59 UTC (permalink / raw)
To: linux-kernel, Cristian Marussi, linux-arm-kernel; +Cc: Sudeep Holla
On Wed, 8 Jun 2022 10:55:28 +0100, Cristian Marussi wrote:
> SCMI Base protocol agent_name/vendor_id/sub_vendor_id are defined by the
> specification as NULL-terminated ASCII strings up to 16-bytes in length.
>
> The underlying buffers and message descriptors are currently bigger than
> needed; resize them to fit only the strictly needed 16 bytes.
>
> While at that, convert Base protocol strings handling routines to use the
> preferred strscpy.
>
> [...]
Applied to sudeep.holla/linux (for-next/scmi), thanks!
[1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes
https://git.kernel.org/sudeep.holla/c/4314f9f4f8
[2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported
https://git.kernel.org/sudeep.holla/c/8e60294c80
[3/3] firmware: arm_scmi: Use preferred strscpy to handle strings
Merged in 1/3 to avoid any possible bisection issues, since they both
deal with the same issue.
--
Regards,
Sudeep
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-06-10 17:01 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-08 9:55 [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Cristian Marussi
2022-06-08 9:55 ` [PATCH 2/3] firmware: arm_scmi: Fix SENSOR_AXIS_NAME_GET behaviour when unsupported Cristian Marussi
2022-06-08 15:19 ` Peter Hilber
2022-06-08 16:26 ` Cristian Marussi
2022-06-08 16:40 ` [PATCH v2 " Cristian Marussi
2022-06-08 16:49 ` Peter Hilber
2022-06-08 9:55 ` [PATCH 3/3] firmware: arm_scmi: Use preferred strscpy to handle strings Cristian Marussi
2022-06-08 15:19 ` Peter Hilber
2022-06-10 16:59 ` [PATCH 1/3] firmware: arm_scmi: Review BASE protocol string-buffers sizes Sudeep Holla
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).