Re: [PATCH v2 2/6] ACPI: scan: Extract CSI-2 connection graph from _CRS

Sakari Ailus
2023-10-31T08:48:04Z

Hi Rafael,

On Fri, Oct 20, 2023 at 04:36:28PM +0200, Rafael J. Wysocki wrote:
> +#define NO_CSI2_PORT (UINT_MAX - 1)
> +
> +static void alloc_crs_csi2_swnodes(struct crs_csi2 *csi2)
> +{
> + size_t port_count = csi2->port_count;
> + struct acpi_device_software_nodes *swnodes;
> + size_t alloc_size;
> + unsigned int i;
> +
> + /*
> + * Allocate memory for ports, node pointers (number of nodes +
> + * 1 (guardian), nodes (root + number of ports * 2 (because for
> + * every port there is an endpoint)).
> + */
> + if (check_mul_overflow(sizeof(*swnodes->ports) +
> + sizeof(*swnodes->nodes) * 2 +
> + sizeof(*swnodes->nodeptrs) * 2,
> + port_count, &alloc_size))
> + goto overflow;
> +
> + if (check_add_overflow(sizeof(*swnodes) +
> + sizeof(*swnodes->nodes) +
> + sizeof(*swnodes->nodeptrs) * 2,
> + alloc_size, &alloc_size))
> + goto overflow;
> +
> + swnodes = kmalloc(alloc_size, GFP_KERNEL);
> + if (!swnodes)
> + return;
> +
> + swnodes->ports = (struct acpi_device_software_node_port *)(swnodes + 1);
> + swnodes->nodes = (struct software_node *)(swnodes->ports + port_count);
> + swnodes->nodeptrs = (const struct software_node **)(swnodes->nodes + 1 +
> + 2 * port_count);
> + swnodes->num_ports = port_count;
> +
> + for (i = 0; i < 2 * port_count + 1; i++)
> + swnodes->nodeptrs[i] = &swnodes->nodes[i];
> +
> + swnodes->nodeptrs[i] = NULL;
> +
> + for (i = 0; i < port_count; i++)
> + swnodes->ports[i].port_nr = NO_CSI2_PORT;
> +
> + csi2->swnodes = swnodes;
> + return;
> +
> +overflow:
> + acpi_handle_info(csi2->handle, "too many _CRS CSI-2 resource handles (%zu)",
> + port_count);

I'd move this to where the conditions are, they can be merged.

--
Regards,

Sakari Ailus