atm: nicstar: simplify allocation
Subsystems (3)
PATCH 1/1 atm: nicstar: simplify allocation
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.
--- drivers/atm/nicstar.c | 17 +++++------------ drivers/atm/nicstar.h | 4 ++-- 2 files changed, 7 insertions(+), 14 deletions(-)
drivers/atm/nicstar.c +5 -12
@@ -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 ; scq->base =PTR_ALIGN (scq->org, size); scq->next = scq->base; scq->last = scq->base + (scq->num_entries -1 );
@@ -928,7 +922,6 @@ static void free_scq(ns_dev *card, scq_info *scq, struct atm_vcc *vcc) } } } -kfree (scq->skb); dma_free_coherent(&card->pcidev->dev, 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ? VBR_SCQSIZE : CBR_SCQSIZE),
drivers/atm/nicstar.h +2 -2
@@ -667,14 +667,14 @@ typedef struct scq_info {ns_scqe *next;volatile ns_scqe *tail;/* Not related to the nicstar register */ unsigned num_entries; -struct sk_buff **skb;/* Pointer to an array of pointers -to the sk_buffs used for tx */ u32 scd;/* SRAM address of the corresponding SCD */ int tbd_count;/* Only meaningful on variable rate */ wait_queue_head_t scqfull_waitq;volatile char full;/* SCQ full indicator */ spinlock_t lock;/* SCQ spinlock */ + struct sk_buff *skb[] __counted_by(num_entries); /* Pointer to an array of pointers +to the sk_buffs used for tx */ } scq_info; typedef struct rsq_info {
Signature · 1 line
2.53.0
Simon Horman
reviewerQuoted 7 lines · Rosen Penev
Use a flexible array member with
kzalloc_flexto combine allocations into one.Add
__counted_byfor extra runtime analysis. Move counting variable assignment to right after allocation as required by__counted_by.Signed-off-by Rosen Penev <[email protected]>
To be honest I'd prefer that we discussed deprecating and removing ATM rather than cleaning it up. Is anyone using it?
Quoted 25 lines
--- drivers/atm/nicstar.c | 17 +++++------------ drivers/atm/nicstar.h | 4 ++-- 2 files changed, 7 insertions(+), 14 deletions(-)drivers/atm/nicstar.c +5
-3@@ -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);
drivers/atm/nicstar.c static scq_info *get_scq(ns_dev *card, int size, u32 scd) · line 886
Quoted 10 lines
drivers/atm/nicstar.c +0
-8return 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.
Signature · 1 line
pw-bot: changes requested
Quoted 5 lines · Simon Horman
Quoted 3 lines · Rosen Penev
Use a flexible array member with
kzalloc_flexto combine allocations into one.
Quoted 7 lines
Quoted 4 lines
Add
__counted_byfor extra runtime analysis. Move counting variable assignment to right after allocation as required by__counted_by.Signed-off-by Rosen Penev <[email protected]>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 31 lines
Quoted 31 lines
--- drivers/atm/nicstar.c | 17 +++++------------ drivers/atm/nicstar.h | 4 ++-- 2 files changed, 7 insertions(+), 14 deletions(-)drivers/atm/nicstar.c +5
-6@@ -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,
Quoted 8 lines
drivers/atm/nicstar.c static scq_info *get_scq(ns_dev *card, int size, u32 scd) · line 886
Quoted 5 lines
drivers/atm/nicstar.c +0
-5- 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.
Quoted 3 lines
--
pw-bot: changes requested