util/sconfig: Fix illogical override rule for resource

The old logic only uses the type to identify resources, which makes a
resource in override tree overriding the first resource with the same
type (but possibly different index) in base tree, and resources with
same type (but again different index) in override tree overriding each
other.

Resources had better be identified with both their type and index.

Change-Id: I7cd88905a8d6d1c7c6c03833835df2fba83047ea
Signed-off-by: Bill XIE <persmule@hardenedlinux.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37109
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Bill XIE 2019-11-21 18:16:12 +08:00 committed by Nico Huber
parent 2b297d92a7
commit c61d415701
1 changed files with 14 additions and 5 deletions

View File

@ -1072,6 +1072,16 @@ static int device_match(struct device *a, struct device *b)
b->chip_instance->chip)); b->chip_instance->chip));
} }
/*
* Match resource nodes from base and override tree to see if they are the same
* node.
*/
static int res_match(struct resource *a, struct resource *b)
{
return ((a->type == b->type) &&
(a->index == b->index));
}
/* /*
* Walk through the override subtree in breadth-first manner starting at node to * Walk through the override subtree in breadth-first manner starting at node to
* see if chip_instance pointer of the node is same as chip_instance pointer of * see if chip_instance pointer of the node is same as chip_instance pointer of
@ -1104,8 +1114,7 @@ static void update_resource(struct device *dev, struct resource *res)
struct resource *base_res = dev->res; struct resource *base_res = dev->res;
while (base_res) { while (base_res) {
if (base_res->type == res->type) { if (res_match(base_res, res)) {
base_res->index = res->index;
base_res->base = res->base; base_res->base = res->base;
return; return;
} }
@ -1195,9 +1204,9 @@ static void override_devicetree(struct bus *base_parent,
* | | | * | | |
* | res | Each resource that is present in override | * | res | Each resource that is present in override |
* | | device is copied over to base device: | * | | device is copied over to base device: |
* | | 1. If resource of same type is present in | * | | 1. If resource of same type and index is |
* | | base device, then index and base of the | * | | present in base device, then base of |
* | | resource is copied. | * | | the resource is copied. |
* | | 2. If not, then a new resource is allocated| * | | 2. If not, then a new resource is allocated|
* | | under the base device using type, index | * | | under the base device using type, index |
* | | and base from override res. | * | | and base from override res. |