From nobody Sun May 24 18:41:09 2026 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BFB82066DE for ; Sun, 24 May 2026 02:46:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779590794; cv=none; b=UasJWkga5/xIYIh4Opb6YwVRamCZ6ppYOK6vhCE7JIGsG3lqThRT1p+0dEOVJ9nMLFr32p8+HjD+6K8IE4Lcrr3ce0T/dr94oSldwiFgX0UK2H9NGav58WZtLq1s7ALSb/CtI1/ghihRCSaaRibfhjnnQ8yRjdDZOeEi7CbZ6mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779590794; c=relaxed/simple; bh=sd0brhKuTlvue1GF0dLTVV6+UoCkGinBIuinD5unjEQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BO9tfKfML9cg15Y/x7YTe00L3zn0LUBlmZ1Fn81w1m7/NDvqXEtKlJRYQNKDQMKqP7bXd7s78RomGdFCnMstP/FLOdgtsvdbKgPNf9xCmgNRP7ZJRwk8HyAmt2vUergYnILs7TT9CwlKRL11lij2ZmJljLBjQM+jqPyv6OFJXl0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XtEhhAgq; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XtEhhAgq" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-8413ac3d82fso3402831b3a.0 for ; Sat, 23 May 2026 19:46:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779590792; x=1780195592; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ciC6AwMqgRoG5tvc6gb6RBuyhx3t8/VvHt7IHCf9iAc=; b=XtEhhAgqYnOQmND9BxFvLocCL3b1cSimjJ1rIkNdPm4LBxFpcQeCXnr+VB6y+3e5MW vn/eNPIL5MTV/r+6LFiwsuYX1oJbpBQRwr5iB31DuJNIC8hDvVIQBzndtV12Xc4IHJlC JrBW95e6EkHxBmCN26uP5ARGk1rz0EKT6ry7WS4JlcnfFUojiZTXX53pbrMZd3TIVw7e e1hGOOwrYS1bM+wh75TZeZHQLoOdueLDo7b/OhDkVM73Y2/Fj/5MXgS6mzXYQ3W7yYYx yKBWVyqBHu88C6JZm0gzppjw6H2IBSsuHi0lsddlBC6Sg1Rf3BXtBE7CWyM7SKGtQrgv g74Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779590792; x=1780195592; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ciC6AwMqgRoG5tvc6gb6RBuyhx3t8/VvHt7IHCf9iAc=; b=srQfnR8KpPb7jIEjCHmzYt5pL71IMyeJWkWQuPDY/UQGnUe7OBZLDJ593WESvUgY79 4bTjH7EtltmbVCPDDr/cKJfM/ypAAucDetPqy4kwhRbKOLADC1Bu7kcS+RABI5sAXq9J y7luptEStDCglTcq9U4C+7FSqmZfACKhUrh/WxUvAbdT9POIDuR+6fPIQszIET2MPS4k WITnLUUneDBSH939pzTlNW9SMeq3IqpESXwmAvqVagC2ss025Hzvfj8acB98a8UKz9I+ nNuuJZRBip1f+mqcWSpasaZqtOrZKE1z6UI7Rl/GhJhcOCQD4rQ7RqYCrWn2R/PhfvvN zOAw== X-Forwarded-Encrypted: i=1; AFNElJ9Hd9V0hcf3L3v/YlcaCGDkZsRsa0Zn1RF1YkHNwk6YOkYaPNaxDFd5gs7mRZcH7+BU8PndqMLulN7DGNk=@vger.kernel.org X-Gm-Message-State: AOJu0YwOIqkDx0Y7OQJ5e3EaW7FH9vd70novUcCHEgAo/caz2Y7CjZnz F89v95rXWqXtcC5X8tp3sVkk0oZQI3ZR/2MGgF70jQqIveJq6OA5EtC+ X-Gm-Gg: Acq92OGkSuyoUsjbmR9xBhQlM5E9StpumGVirI1//dXCrwsCPRrMxd7bgWMuh7vdNzl sD63BvOYRE1+AuSdXQ4E8HrWPn/r0UCxk6DLr1RnsAIfITR6p6dSqyh7vhbTZlEwErOpJJOy9wU cEuWxq69Ww1UE6VbYBVPBRoQK/e05otsa8qZXp4E+82I1iqGmYBhlLzwKyYvIV3qoW5Dse+3Jgr 9oevhb+JgA4nanhF77zxcLfhJuBUt8m1pc4hDbEUihdi38ktHWyN28SI1RpdsA6wiOayLIgRfmw 1WGXd4XR7Eoswlyn39O/HNNUPKKlCvuoOKAmWnd9qc5pBEhL6OrzZL30hHNp3pn+Uh+c2Mffjjz Ei7wDVr7GurTKzvSMnbo0woD1UvFxYcvPvD1nCcyeCw7MN31FRW4TTtKt+4R1wr+igxp2wYezay MpTzrsATUUMq5mNIZH1rL8eIY93jUG3l0dWziVEl4OBBcwbVtORYm+3VlDPIQiP7GrSvCuMJ/mJ 96OY+SR2FinGSxSHn42RNkwz9NTgQDDEjQ= X-Received: by 2002:a05:6a00:4f94:b0:83d:b11f:796c with SMTP id d2e1a72fcca58-8415f3d3adbmr9102216b3a.49.1779590791854; Sat, 23 May 2026 19:46:31 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d:7285:c2ff:fe45:8a32]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84164fc6e8esm5490202b3a.47.2026.05.23.19.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2026 19:46:31 -0700 (PDT) From: Rosen Penev To: dmaengine@vger.kernel.org Cc: Peter Ujfalusi , linusw@kernel.org, Vinod Koul , Frank Li , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be|_ptr)?\b) Subject: [PATCH] dmaengine: ti: omap-dma: turn lch_map into a flexible array Date: Sat, 23 May 2026 19:46:14 -0700 Message-ID: <20260524024614.182126-1-rosenp@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert the separately-allocated lch_map pointer array to a C99 flexible array member at the end of struct omap_dmadev and annotate it with __counted_by(lch_count). The probe is reordered so platform_data lookup and the lch_count determination happen before the parent allocation, letting struct_size() size the FAM and the dedicated devm_kcalloc() for lch_map go away. Two allocations collapse into one and the runtime bounds checks from __counted_by now apply to every lch_map[] access. Assisted-by: Claude:Opus-4.7 Signed-off-by: Rosen Penev --- drivers/dma/ti/omap-dma.c | 68 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/drivers/dma/ti/omap-dma.c b/drivers/dma/ti/omap-dma.c index 55ece7fd0d99..901e38b08962 100644 --- a/drivers/dma/ti/omap-dma.c +++ b/drivers/dma/ti/omap-dma.c @@ -57,7 +57,7 @@ struct omap_dmadev { unsigned dma_requests; spinlock_t irq_lock; uint32_t irq_enable_mask; - struct omap_chan **lch_map; + struct omap_chan *lch_map[] __counted_by(lch_count); }; =20 struct omap_chan { @@ -1656,36 +1656,53 @@ static const struct omap_dma_config default_cfg; static int omap_dma_probe(struct platform_device *pdev) { const struct omap_dma_config *conf; + struct omap_system_dma_plat_info *plat; struct omap_dmadev *od; + int lch_count; int rc, i, irq; u32 val; =20 - od =3D devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL); - if (!od) - return -ENOMEM; - - od->base =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(od->base)) - return PTR_ERR(od->base); - conf =3D of_device_get_match_data(&pdev->dev); if (conf) { - od->cfg =3D conf; - od->plat =3D dev_get_platdata(&pdev->dev); - if (!od->plat) { + plat =3D dev_get_platdata(&pdev->dev); + if (!plat) { dev_err(&pdev->dev, "omap_system_dma_plat_info is missing"); return -ENODEV; } } else if (IS_ENABLED(CONFIG_ARCH_OMAP1)) { - od->cfg =3D &default_cfg; - - od->plat =3D omap_get_plat_info(); - if (!od->plat) + plat =3D omap_get_plat_info(); + if (!plat) return -EPROBE_DEFER; } else { return -ENODEV; } =20 + /* Number of available logical channels */ + if (!pdev->dev.of_node) { + lch_count =3D plat->dma_attr->lch_count; + if (unlikely(!lch_count)) + lch_count =3D OMAP_SDMA_CHANNELS; + } else if (of_property_read_u32(pdev->dev.of_node, "dma-channels", + &lch_count)) { + dev_info(&pdev->dev, + "Missing dma-channels property, using %u.\n", + OMAP_SDMA_CHANNELS); + lch_count =3D OMAP_SDMA_CHANNELS; + } + + od =3D devm_kzalloc(&pdev->dev, struct_size(od, lch_map, lch_count), + GFP_KERNEL); + if (!od) + return -ENOMEM; + + od->lch_count =3D lch_count; + od->plat =3D plat; + od->cfg =3D conf ? conf : &default_cfg; + + od->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(od->base)) + return PTR_ERR(od->base); + od->reg_map =3D od->plat->reg_map; =20 dma_cap_set(DMA_SLAVE, od->ddev.cap_mask); @@ -1730,19 +1747,6 @@ static int omap_dma_probe(struct platform_device *pd= ev) OMAP_SDMA_REQUESTS); } =20 - /* Number of available logical channels */ - if (!pdev->dev.of_node) { - od->lch_count =3D od->plat->dma_attr->lch_count; - if (unlikely(!od->lch_count)) - od->lch_count =3D OMAP_SDMA_CHANNELS; - } else if (of_property_read_u32(pdev->dev.of_node, "dma-channels", - &od->lch_count)) { - dev_info(&pdev->dev, - "Missing dma-channels property, using %u.\n", - OMAP_SDMA_CHANNELS); - od->lch_count =3D OMAP_SDMA_CHANNELS; - } - /* Mask of allowed logical channels */ if (pdev->dev.of_node && !of_property_read_u32(pdev->dev.of_node, "dma-channel-mask", @@ -1754,12 +1758,6 @@ static int omap_dma_probe(struct platform_device *pd= ev) if (od->plat->dma_attr->dev_caps & HS_CHANNELS_RESERVED) bitmap_set(od->lch_bitmap, 0, 2); =20 - od->lch_map =3D devm_kcalloc(&pdev->dev, od->lch_count, - sizeof(*od->lch_map), - GFP_KERNEL); - if (!od->lch_map) - return -ENOMEM; - for (i =3D 0; i < od->dma_requests; i++) { rc =3D omap_dma_chan_init(od); if (rc) { --=20 2.54.0