diff options
author | Cristian Marussi <cristian.marussi@arm.com> | 2022-05-03 14:10:47 +0200 |
---|---|---|
committer | Sudeep Holla <sudeep.holla@arm.com> | 2022-05-03 15:23:02 +0200 |
commit | c7f8852d4216f7dc061f0bc02dda5af396048861 (patch) | |
tree | 823400565d092469c786d7db59e2028f3d5255ae /drivers/firmware | |
parent | firmware: arm_scmi: Support optee shared memory in the optee transport (diff) | |
download | linux-c7f8852d4216f7dc061f0bc02dda5af396048861.tar.xz linux-c7f8852d4216f7dc061f0bc02dda5af396048861.zip |
firmware: arm_scmi: Fix late checks on pointer dereference
A few dereferences could happen before the iterator pointer argument was
checked for NULL, causing the following smatch warnings:
drivers/firmware/arm_scmi/driver.c:1214 scmi_iterator_run() warn: variable
dereferenced before check 'i' (see line 1210)
Fix by moving the checks early and dropping some unneeded local references.
No functional change.
Link: https://lore.kernel.org/r/20220503121047.3590340-1-cristian.marussi@arm.com
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
Diffstat (limited to 'drivers/firmware')
-rw-r--r-- | drivers/firmware/arm_scmi/driver.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index c4960fd3df75..c1922bd650ae 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1205,18 +1205,21 @@ static void *scmi_iterator_init(const struct scmi_protocol_handle *ph, static int scmi_iterator_run(void *iter) { int ret = -EINVAL; + struct scmi_iterator_ops *iops; + const struct scmi_protocol_handle *ph; + struct scmi_iterator_state *st; struct scmi_iterator *i = iter; - struct scmi_iterator_state *st = &i->state; - struct scmi_iterator_ops *iops = i->ops; - const struct scmi_protocol_handle *ph = i->ph; - const struct scmi_xfer_ops *xops = ph->xops; - if (!i) + if (!i || !i->ops || !i->ph) return ret; + iops = i->ops; + ph = i->ph; + st = &i->state; + do { iops->prepare_message(i->msg, st->desc_index, i->priv); - ret = xops->do_xfer(ph, i->t); + ret = ph->xops->do_xfer(ph, i->t); if (ret) break; @@ -1240,7 +1243,7 @@ static int scmi_iterator_run(void *iter) } st->desc_index += st->num_returned; - xops->reset_rx_to_maxsz(ph, i->t); + ph->xops->reset_rx_to_maxsz(ph, i->t); /* * check for both returned and remaining to avoid infinite * loop due to buggy firmware @@ -1249,7 +1252,7 @@ static int scmi_iterator_run(void *iter) out: /* Finalize and destroy iterator */ - xops->xfer_put(ph, i->t); + ph->xops->xfer_put(ph, i->t); devm_kfree(ph->dev, i); return ret; |