Thread (3 messages) flat view 3 messages, 2 authors, 2026-03-26

Re: [PATCH] atm: nicstar: simplify allocation

From: Rosen Penev <hidden>
Date: 2026-03-26 02:23:34
Also in: linux-hardening, lkml

On Wed, Mar 25, 2026 at 10:27 AM Simon Horman [off-list ref] wrote:
On Mon, Mar 23, 2026 at 08:22:43PM -0700, Rosen Penev wrote:
quoted
Use a flexible array member with kzalloc_flex to combine allocations
into one.

Add __counted_by for extra runtime analysis. Move counting variable
assignment to right after allocation as required by __counted_by.

Signed-off-by: Rosen Penev <redacted>
To be honest I'd prefer that we discussed deprecating and removing ATM
rather than cleaning it up. Is anyone using it?
Beats me.
quoted
---
 drivers/atm/nicstar.c | 17 +++++------------
 drivers/atm/nicstar.h |  4 ++--
 2 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
index 24e51343df15..2f6a3637aeab 100644
--- a/drivers/atm/nicstar.c
+++ b/drivers/atm/nicstar.c
@@ -867,23 +867,17 @@ static scq_info *get_scq(ns_dev *card, int size, u32 scd)
      if (size != VBR_SCQSIZE && size != CBR_SCQSIZE)
              return NULL;

-     scq = kmalloc_obj(*scq);
+     scq = kmalloc_flex(*scq, skb, size / NS_SCQE_SIZE);
      if (!scq)
              return NULL;
-        scq->org = dma_alloc_coherent(&card->pcidev->dev,
-                                   2 * size,  &scq->dma, GFP_KERNEL);
+
+     scq->num_entries = size / NS_SCQE_SIZE;
+
+     scq->org = dma_alloc_coherent(&card->pcidev->dev, 2 * size, &scq->dma, GFP_KERNEL);
      if (!scq->org) {
              kfree(scq);
              return NULL;
      }
-     scq->skb = kzalloc_objs(*scq->skb, size / NS_SCQE_SIZE);
-     if (!scq->skb) {
-             dma_free_coherent(&card->pcidev->dev,
-                               2 * size, scq->org, scq->dma);
-             kfree(scq);
-             return NULL;
-     }
-     scq->num_entries = size / NS_SCQE_SIZE;
AI review points out that previously the skb array was zeroed on allocation,
which is relied on by the code. But that is no longer the case.
Will fix.
--
pw-bot: changes requested
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help