of_dma_set_restricted_buffer fails to handle negative return values from of_property_count_elems_of_size, e.g. when the property does not exist. This results in an attempt to assign a non-existent reserved memory region to the device and a warning being printed. Fix the condition to take negative values into account.
Unified · Split
| @@ -85,7 +85,11 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) · 84 unmodified lines | ||
| 85 | 85 | break; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | − if (i != count && of_reserved_mem_device_init_by_idx(dev, of_node, i)) | |
| 88 | + /* | |
| 89 | + * Attempt to initialize a restricted-dma-pool region if one was found. | |
| 90 | + * Note that count can hold a negative error code. | |
| 91 | + */ | |
| 92 | + if (i < count && of_reserved_mem_device_init_by_idx(dev, of_node, i)) | |
| 89 | 93 | dev_warn(dev, "failed to initialise \"restricted-dma-pool\" memory node\n"); |
| 90 | 94 | } |
| 91 | 95 | |