Skip to content

Commit f675386

Browse files
Artem Shimkosudeep-holla
authored andcommitted
firmware: arm_scmi: Refactor reset domain handling
Introduce scmi_reset_domain_lookup() to centralize domain ID validation and unify error reporting behaviour across the SCMI reset protocol. All reset domain operations are updated to use the new helper, removing duplicated validation logic and ensuring consistent handling of invalid domain IDs and lookup failures. This simplifies the internal flow and improves robustness of the reset protocol implementation. Suggested-by: Cristian Marussi <cristian.marussi@arm.com> Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com> Message-Id: <20251123163557.230530-1-a.shimko.dev@gmail.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
1 parent 78b7413 commit f675386

1 file changed

Lines changed: 33 additions & 17 deletions

File tree

drivers/firmware/arm_scmi/reset.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ static int scmi_reset_attributes_get(const struct scmi_protocol_handle *ph,
9898
return ret;
9999
}
100100

101+
static struct reset_dom_info *
102+
scmi_reset_domain_lookup(const struct scmi_protocol_handle *ph, u32 domain)
103+
{
104+
struct scmi_reset_info *pi = ph->get_priv(ph);
105+
106+
if (domain >= pi->num_domains)
107+
return ERR_PTR(-EINVAL);
108+
109+
return pi->dom_info + domain;
110+
}
111+
101112
static int
102113
scmi_reset_domain_attributes_get(const struct scmi_protocol_handle *ph,
103114
struct scmi_reset_info *pinfo,
@@ -156,20 +167,25 @@ static int scmi_reset_num_domains_get(const struct scmi_protocol_handle *ph)
156167
static const char *
157168
scmi_reset_name_get(const struct scmi_protocol_handle *ph, u32 domain)
158169
{
159-
struct scmi_reset_info *pi = ph->get_priv(ph);
170+
struct reset_dom_info *dom_info;
160171

161-
struct reset_dom_info *dom = pi->dom_info + domain;
172+
dom_info = scmi_reset_domain_lookup(ph, domain);
173+
if (IS_ERR(dom_info))
174+
return "unknown";
162175

163-
return dom->name;
176+
return dom_info->name;
164177
}
165178

166179
static int scmi_reset_latency_get(const struct scmi_protocol_handle *ph,
167180
u32 domain)
168181
{
169-
struct scmi_reset_info *pi = ph->get_priv(ph);
170-
struct reset_dom_info *dom = pi->dom_info + domain;
182+
struct reset_dom_info *dom_info;
183+
184+
dom_info = scmi_reset_domain_lookup(ph, domain);
185+
if (IS_ERR(dom_info))
186+
return PTR_ERR(dom_info);
171187

172-
return dom->latency_us;
188+
return dom_info->latency_us;
173189
}
174190

175191
static int scmi_domain_reset(const struct scmi_protocol_handle *ph, u32 domain,
@@ -178,14 +194,13 @@ static int scmi_domain_reset(const struct scmi_protocol_handle *ph, u32 domain,
178194
int ret;
179195
struct scmi_xfer *t;
180196
struct scmi_msg_reset_domain_reset *dom;
181-
struct scmi_reset_info *pi = ph->get_priv(ph);
182-
struct reset_dom_info *rdom;
197+
struct reset_dom_info *dom_info;
183198

184-
if (domain >= pi->num_domains)
185-
return -EINVAL;
199+
dom_info = scmi_reset_domain_lookup(ph, domain);
200+
if (IS_ERR(dom_info))
201+
return PTR_ERR(dom_info);
186202

187-
rdom = pi->dom_info + domain;
188-
if (rdom->async_reset && flags & AUTONOMOUS_RESET)
203+
if (dom_info->async_reset && flags & AUTONOMOUS_RESET)
189204
flags |= ASYNCHRONOUS_RESET;
190205

191206
ret = ph->xops->xfer_get_init(ph, RESET, sizeof(*dom), 0, &t);
@@ -238,15 +253,16 @@ static const struct scmi_reset_proto_ops reset_proto_ops = {
238253
static bool scmi_reset_notify_supported(const struct scmi_protocol_handle *ph,
239254
u8 evt_id, u32 src_id)
240255
{
241-
struct reset_dom_info *dom;
242-
struct scmi_reset_info *pi = ph->get_priv(ph);
256+
struct reset_dom_info *dom_info;
243257

244-
if (evt_id != SCMI_EVENT_RESET_ISSUED || src_id >= pi->num_domains)
258+
if (evt_id != SCMI_EVENT_RESET_ISSUED)
245259
return false;
246260

247-
dom = pi->dom_info + src_id;
261+
dom_info = scmi_reset_domain_lookup(ph, src_id);
262+
if (IS_ERR(dom_info))
263+
return false;
248264

249-
return dom->reset_notify;
265+
return dom_info->reset_notify;
250266
}
251267

252268
static int scmi_reset_notify(const struct scmi_protocol_handle *ph,

0 commit comments

Comments
 (0)