public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Rosen Penev <rosenp@gmail.com>, linux-atm-general@lists.sourceforge.net
Cc: Chas Williams <3chas3@gmail.com>, Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	"open list:ATM" <netdev@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	open "list:KERNEL" HARDENING "(not" covered by other
	"areas):Keyword:b__counted_by(_le|_be)?b"
	<linux-hardening@vger.kernel.org>
Subject: Re: [PATCHv3] atm: nicstar: simplify allocation
Date: Tue, 31 Mar 2026 09:35:14 -0600	[thread overview]
Message-ID: <ddb5961b-02f9-4956-b618-31aab836fce7@embeddedor.com> (raw)
In-Reply-To: <20260327192407.365369-1-rosenp@gmail.com>



On 3/27/26 13:24, Rosen Penev wrote:
> 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.

This is misinformation and should be phrased differently[1]

-Gustavo

[1] https://lore.kernel.org/linux-hardening/37378f49-437f-438b-ad6c-d60480feb306@embeddedor.com/

> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>   v3: reduce to 80 columns
>   v2: use kzalloc_flex
>   drivers/atm/nicstar.c | 18 ++++++------------
>   drivers/atm/nicstar.h |  5 +++--
>   2 files changed, 9 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
> index 24e51343df15..c0bed85daf96 100644
> --- a/drivers/atm/nicstar.c
> +++ b/drivers/atm/nicstar.c
> @@ -867,23 +867,18 @@ 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 = kzalloc_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 +923,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),
> diff --git a/drivers/atm/nicstar.h b/drivers/atm/nicstar.h
> index 1b7f1dfc1735..76635d46016e 100644
> --- a/drivers/atm/nicstar.h
> +++ b/drivers/atm/nicstar.h
> @@ -667,14 +667,15 @@ 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 {
> --
> 2.53.0
> 
> 


      reply	other threads:[~2026-03-31 15:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-27 19:24 [PATCHv3] atm: nicstar: simplify allocation Rosen Penev
2026-03-31 15:35 ` Gustavo A. R. Silva [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ddb5961b-02f9-4956-b618-31aab836fce7@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=3chas3@gmail.com \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-atm-general@lists.sourceforge.net \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rosenp@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox