diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-06-06 16:59:44 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2020-06-06 16:59:44 +0000 |
commit | 7487a718c27525156c91c65f134d9b51ef0250d7 (patch) | |
tree | 6017e2b0be2fe250f6bf38ffa85d15c93e59305d /sys/dev | |
parent | d71045bb947b01e306aef84e1f2b51594dfffe56 (diff) |
Some devices have no phandle since they are not referenced in the
device tree, but they are still registered in our OFW framework.
These then tend to have a phandle 0. If we are trying to lookup
a device by phandle, we should explicitly check for phandle 0 and
bail, since otherwise it is possible that we falsely match that
phandle and return a device.
ok kettenis@
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ofw/ofw_misc.c | 20 | ||||
-rw-r--r-- | sys/dev/ofw/ofw_pinctrl.c | 5 | ||||
-rw-r--r-- | sys/dev/ofw/ofw_regulator.c | 17 |
3 files changed, 39 insertions, 3 deletions
diff --git a/sys/dev/ofw/ofw_misc.c b/sys/dev/ofw/ofw_misc.c index 84fc5dcb6a5..b23851e951c 100644 --- a/sys/dev/ofw/ofw_misc.c +++ b/sys/dev/ofw/ofw_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_misc.c,v 1.19 2020/04/07 09:08:15 kettenis Exp $ */ +/* $OpenBSD: ofw_misc.c,v 1.20 2020/06/06 16:59:43 patrick Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -88,6 +88,9 @@ regmap_byphandle(uint32_t phandle) { struct regmap *rm; + if (phandle == 0) + return NULL; + LIST_FOREACH(rm, ®maps, rm_list) { if (rm->rm_phandle == phandle) return rm; @@ -273,6 +276,9 @@ i2c_byphandle(uint32_t phandle) { struct i2c_bus *ib; + if (phandle == 0) + return NULL; + LIST_FOREACH(ib, &i2c_busses, ib_list) { if (ib->ib_phandle == phandle) return ib->ib_ic; @@ -303,6 +309,9 @@ sfp_get_sffpage(uint32_t phandle, struct if_sffpage *sff) { struct sfp_device *sd; + if (phandle == 0) + return ENXIO; + LIST_FOREACH(sd, &sfp_devices, sd_list) { if (sd->sd_phandle == phandle) return sd->sd_get_sffpage(sd->sd_cookie, sff); @@ -436,6 +445,9 @@ nvmem_read(uint32_t phandle, bus_addr_t addr, void *data, bus_size_t size) { struct nvmem_device *nd; + if (phandle == 0) + return ENXIO; + LIST_FOREACH(nd, &nvmem_devices, nd_list) { if (nd->nd_phandle == phandle) return nd->nd_read(nd->nd_cookie, addr, data, size); @@ -545,6 +557,9 @@ endpoint_byphandle(uint32_t phandle) { struct endpoint *ep; + if (phandle == 0) + return NULL; + LIST_FOREACH(ep, &endpoints, ep_list) { if (ep->ep_phandle == phandle) return ep; @@ -612,6 +627,9 @@ device_port_activate(uint32_t phandle, void *arg) int count; int error; + if (phandle == 0) + return ENXIO; + LIST_FOREACH(ep, &endpoints, ep_list) { if (ep->ep_port->dp_phandle == phandle) { dp = ep->ep_port; diff --git a/sys/dev/ofw/ofw_pinctrl.c b/sys/dev/ofw/ofw_pinctrl.c index 75f75785ca6..f186b8afbc5 100644 --- a/sys/dev/ofw/ofw_pinctrl.c +++ b/sys/dev/ofw/ofw_pinctrl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_pinctrl.c,v 1.2 2017/03/12 11:44:42 kettenis Exp $ */ +/* $OpenBSD: ofw_pinctrl.c,v 1.3 2020/06/06 16:59:43 patrick Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -65,6 +65,9 @@ pinctrl_byphandle(uint32_t phandle) { struct pinctrl *pc; + if (phandle == 0) + return -1; + LIST_FOREACH(pc, &pinctrls, pc_list) { if (pc->pc_phandle == phandle) return pc->pc_pinctrl(pc->pc_phandle, pc->pc_cookie); diff --git a/sys/dev/ofw/ofw_regulator.c b/sys/dev/ofw/ofw_regulator.c index 6fe0723509f..645c3d0136e 100644 --- a/sys/dev/ofw/ofw_regulator.c +++ b/sys/dev/ofw/ofw_regulator.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ofw_regulator.c,v 1.13 2019/04/30 19:53:27 patrick Exp $ */ +/* $OpenBSD: ofw_regulator.c,v 1.14 2020/06/06 16:59:43 patrick Exp $ */ /* * Copyright (c) 2016 Mark Kettenis * @@ -129,6 +129,9 @@ regulator_set(uint32_t phandle, int enable) struct regulator_device *rd; int node; + if (phandle == 0) + return ENODEV; + node = OF_getnodebyphandle(phandle); if (node == 0) return ENODEV; @@ -169,6 +172,9 @@ regulator_get_voltage(uint32_t phandle) struct regulator_device *rd; int node; + if (phandle == 0) + return 0; + LIST_FOREACH(rd, ®ulator_devices, rd_list) { if (rd->rd_phandle == phandle) break; @@ -198,6 +204,9 @@ regulator_set_voltage(uint32_t phandle, uint32_t voltage) uint32_t old, delta; int error, node; + if (phandle == 0) + return ENODEV; + LIST_FOREACH(rd, ®ulator_devices, rd_list) { if (rd->rd_phandle == phandle) break; @@ -238,6 +247,9 @@ regulator_get_current(uint32_t phandle) struct regulator_device *rd; int node; + if (phandle == 0) + return 0; + LIST_FOREACH(rd, ®ulator_devices, rd_list) { if (rd->rd_phandle == phandle) break; @@ -267,6 +279,9 @@ regulator_set_current(uint32_t phandle, uint32_t current) uint32_t old, delta; int error, node; + if (phandle == 0) + return ENODEV; + LIST_FOREACH(rd, ®ulator_devices, rd_list) { if (rd->rd_phandle == phandle) break; |