Skip to content

Commit aa4330e

Browse files
committed
Merge tag 'devicetree-fixes-for-4.20-2' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux
Pull Devicetree fixes from Rob Herring: - Add validation of NUMA distance map to prevent crashes with bad map - Fix setting of dma_mask * tag 'devicetree-fixes-for-4.20-2' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux: of, numa: Validate some distance map rules of/device: Really only set bus DMA mask when appropriate
2 parents dc5db21 + 89c3842 commit aa4330e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

drivers/of/device.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
149149
* set by the driver.
150150
*/
151151
mask = DMA_BIT_MASK(ilog2(dma_addr + size - 1) + 1);
152-
dev->bus_dma_mask = mask;
153152
dev->coherent_dma_mask &= mask;
154153
*dev->dma_mask &= mask;
154+
/* ...but only set bus mask if we found valid dma-ranges earlier */
155+
if (!ret)
156+
dev->bus_dma_mask = mask;
155157

156158
coherent = of_dma_is_coherent(np);
157159
dev_dbg(dev, "device is%sdma coherent\n",

drivers/of/of_numa.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ static int __init of_numa_parse_distance_map_v1(struct device_node *map)
104104
distance = of_read_number(matrix, 1);
105105
matrix++;
106106

107+
if ((nodea == nodeb && distance != LOCAL_DISTANCE) ||
108+
(nodea != nodeb && distance <= LOCAL_DISTANCE)) {
109+
pr_err("Invalid distance[node%d -> node%d] = %d\n",
110+
nodea, nodeb, distance);
111+
return -EINVAL;
112+
}
113+
107114
numa_set_distance(nodea, nodeb, distance);
108-
pr_debug("distance[node%d -> node%d] = %d\n",
109-
nodea, nodeb, distance);
110115

111116
/* Set default distance of node B->A same as A->B */
112117
if (nodeb > nodea)

0 commit comments

Comments
 (0)