All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: st: use kzalloc_array
@ 2026-06-30  1:21 Rosen Penev
  2026-06-30  7:28 ` Damien Le Moal
  0 siblings, 1 reply; 5+ messages in thread
From: Rosen Penev @ 2026-06-30  1:21 UTC (permalink / raw)
  To: linux-scsi
  Cc: Kai Mäkisara, James E.J. Bottomley, Martin K. Petersen,
	Kees Cook, Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be|_ptr)?b

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/scsi/st.c | 12 +++---------
 drivers/scsi/st.h |  3 ++-
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index f1c3c4946637..31ae189b18e7 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -149,7 +149,7 @@ static struct st_dev_parm {
    mode counts */
 static const char *st_formats[] = {
 	"",  "r", "k", "s", "l", "t", "o", "u",
-	"m", "v", "p", "x", "a", "y", "q", "z"}; 
+	"m", "v", "p", "x", "a", "y", "q", "z"};
 
 /* The default definitions have been moved to st_options.h */
 
@@ -3973,21 +3973,15 @@ static struct st_buffer *new_tape_buffer(int max_sg)
 {
 	struct st_buffer *tb;
 
-	tb = kzalloc_obj(struct st_buffer);
+	tb = kzalloc_flex(*tb, reserved_pages, max_sg);
 	if (!tb) {
 		printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n");
 		return NULL;
 	}
-	tb->frp_segs = 0;
 	tb->use_sg = max_sg;
+	tb->frp_segs = 0;
 	tb->buffer_size = 0;
 
-	tb->reserved_pages = kzalloc_objs(struct page *, max_sg);
-	if (!tb->reserved_pages) {
-		kfree(tb);
-		return NULL;
-	}
-
 	return tb;
 }
 
diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h
index 0d7c4b8c2c8a..759f4c43d563 100644
--- a/drivers/scsi/st.h
+++ b/drivers/scsi/st.h
@@ -45,7 +45,6 @@ struct st_buffer {
 	int syscall_result;
 	struct st_request *last_SRpnt;
 	struct st_cmdstatus cmdstat;
-	struct page **reserved_pages;
 	int reserved_page_order;
 	struct page **mapped_pages;
 	struct rq_map_data map_data;
@@ -53,6 +52,8 @@ struct st_buffer {
 	unsigned short use_sg;	/* zero or max number of s/g segments for this adapter */
 	unsigned short sg_segs;		/* number of segments in s/g list */
 	unsigned short frp_segs;	/* number of buffer segments */
+
+	struct page *reserved_pages[] __counted_by(use_sg);
 };
 
 /* The tape mode definition */
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: st: use kzalloc_array
  2026-06-30  1:21 [PATCH] scsi: st: use kzalloc_array Rosen Penev
@ 2026-06-30  7:28 ` Damien Le Moal
  2026-07-03 19:06   ` Rosen Penev
  0 siblings, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2026-06-30  7:28 UTC (permalink / raw)
  To: Rosen Penev, linux-scsi
  Cc: Kai Mäkisara, James E.J. Bottomley, Martin K. Petersen,
	Kees Cook, Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be|_ptr)?b

On 6/30/26 10:21, Rosen Penev wrote:
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

No commit message ? Please explain your reasonning, because I find this patch
incorrect. See below.

> ---
>  drivers/scsi/st.c | 12 +++---------
>  drivers/scsi/st.h |  3 ++-
>  2 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> index f1c3c4946637..31ae189b18e7 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -149,7 +149,7 @@ static struct st_dev_parm {
>     mode counts */
>  static const char *st_formats[] = {
>  	"",  "r", "k", "s", "l", "t", "o", "u",
> -	"m", "v", "p", "x", "a", "y", "q", "z"}; 
> +	"m", "v", "p", "x", "a", "y", "q", "z"};
>  
>  /* The default definitions have been moved to st_options.h */
>  
> @@ -3973,21 +3973,15 @@ static struct st_buffer *new_tape_buffer(int max_sg)
>  {
>  	struct st_buffer *tb;
>  
> -	tb = kzalloc_obj(struct st_buffer);
> +	tb = kzalloc_flex(*tb, reserved_pages, max_sg);
>  	if (!tb) {
>  		printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n");
>  		return NULL;
>  	}
> -	tb->frp_segs = 0;
>  	tb->use_sg = max_sg;
> +	tb->frp_segs = 0;
>  	tb->buffer_size = 0;
>  
> -	tb->reserved_pages = kzalloc_objs(struct page *, max_sg);

reserve_pages is in the middle of struct st_buffer so you cannot use a flex array.

> -	if (!tb->reserved_pages) {
> -		kfree(tb);
> -		return NULL;
> -	}
> -
>  	return tb;
>  }
>  
> diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h
> index 0d7c4b8c2c8a..759f4c43d563 100644
> --- a/drivers/scsi/st.h
> +++ b/drivers/scsi/st.h
> @@ -45,7 +45,6 @@ struct st_buffer {
>  	int syscall_result;
>  	struct st_request *last_SRpnt;
>  	struct st_cmdstatus cmdstat;
> -	struct page **reserved_pages;
>  	int reserved_page_order;
>  	struct page **mapped_pages;
>  	struct rq_map_data map_data;
> @@ -53,6 +52,8 @@ struct st_buffer {
>  	unsigned short use_sg;	/* zero or max number of s/g segments for this adapter */
>  	unsigned short sg_segs;		/* number of segments in s/g list */
>  	unsigned short frp_segs;	/* number of buffer segments */
> +
> +	struct page *reserved_pages[] __counted_by(use_sg);
>  };
>  
>  /* The tape mode definition */


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: st: use kzalloc_array
  2026-06-30  7:28 ` Damien Le Moal
@ 2026-07-03 19:06   ` Rosen Penev
  2026-07-05  1:08     ` Damien Le Moal
  0 siblings, 1 reply; 5+ messages in thread
From: Rosen Penev @ 2026-07-03 19:06 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: linux-scsi, Kai Mäkisara, James E.J. Bottomley,
	Martin K. Petersen, Kees Cook, Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be|_ptr)?b

On Tue, Jun 30, 2026 at 12:28 AM Damien Le Moal <dlemoal@kernel.org> wrote:
>
> On 6/30/26 10:21, Rosen Penev wrote:
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
>
> No commit message ? Please explain your reasonning, because I find this patch
> incorrect. See below.
>
> > ---
> >  drivers/scsi/st.c | 12 +++---------
> >  drivers/scsi/st.h |  3 ++-
> >  2 files changed, 5 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> > index f1c3c4946637..31ae189b18e7 100644
> > --- a/drivers/scsi/st.c
> > +++ b/drivers/scsi/st.c
> > @@ -149,7 +149,7 @@ static struct st_dev_parm {
> >     mode counts */
> >  static const char *st_formats[] = {
> >       "",  "r", "k", "s", "l", "t", "o", "u",
> > -     "m", "v", "p", "x", "a", "y", "q", "z"};
> > +     "m", "v", "p", "x", "a", "y", "q", "z"};
> >
> >  /* The default definitions have been moved to st_options.h */
> >
> > @@ -3973,21 +3973,15 @@ static struct st_buffer *new_tape_buffer(int max_sg)
> >  {
> >       struct st_buffer *tb;
> >
> > -     tb = kzalloc_obj(struct st_buffer);
> > +     tb = kzalloc_flex(*tb, reserved_pages, max_sg);
> >       if (!tb) {
> >               printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n");
> >               return NULL;
> >       }
> > -     tb->frp_segs = 0;
> >       tb->use_sg = max_sg;
> > +     tb->frp_segs = 0;
> >       tb->buffer_size = 0;
> >
> > -     tb->reserved_pages = kzalloc_objs(struct page *, max_sg);
>
> reserve_pages is in the middle of struct st_buffer so you cannot use a flex array.
This patch moves it, no?
>
> > -     if (!tb->reserved_pages) {
> > -             kfree(tb);
> > -             return NULL;
> > -     }
> > -
> >       return tb;
> >  }
> >
> > diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h
> > index 0d7c4b8c2c8a..759f4c43d563 100644
> > --- a/drivers/scsi/st.h
> > +++ b/drivers/scsi/st.h
> > @@ -45,7 +45,6 @@ struct st_buffer {
> >       int syscall_result;
> >       struct st_request *last_SRpnt;
> >       struct st_cmdstatus cmdstat;
> > -     struct page **reserved_pages;
> >       int reserved_page_order;
> >       struct page **mapped_pages;
> >       struct rq_map_data map_data;
> > @@ -53,6 +52,8 @@ struct st_buffer {
> >       unsigned short use_sg;  /* zero or max number of s/g segments for this adapter */
> >       unsigned short sg_segs;         /* number of segments in s/g list */
> >       unsigned short frp_segs;        /* number of buffer segments */
> > +
> > +     struct page *reserved_pages[] __counted_by(use_sg);
> >  };
> >
> >  /* The tape mode definition */
>
>
> --
> Damien Le Moal
> Western Digital Research

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: st: use kzalloc_array
  2026-07-03 19:06   ` Rosen Penev
@ 2026-07-05  1:08     ` Damien Le Moal
  2026-07-05  1:15       ` Rosen Penev
  0 siblings, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2026-07-05  1:08 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-scsi, Kai Mäkisara, James E.J. Bottomley,
	Martin K. Petersen, Kees Cook, Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be|_ptr)?b

On 7/4/26 04:06, Rosen Penev wrote:
> On Tue, Jun 30, 2026 at 12:28 AM Damien Le Moal <dlemoal@kernel.org> wrote:
>>
>> On 6/30/26 10:21, Rosen Penev wrote:
>>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>>
>> No commit message ? Please explain your reasonning, because I find this patch
>> incorrect. See below.
>>
>>> ---
>>>  drivers/scsi/st.c | 12 +++---------
>>>  drivers/scsi/st.h |  3 ++-
>>>  2 files changed, 5 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
>>> index f1c3c4946637..31ae189b18e7 100644
>>> --- a/drivers/scsi/st.c
>>> +++ b/drivers/scsi/st.c
>>> @@ -149,7 +149,7 @@ static struct st_dev_parm {
>>>     mode counts */
>>>  static const char *st_formats[] = {
>>>       "",  "r", "k", "s", "l", "t", "o", "u",
>>> -     "m", "v", "p", "x", "a", "y", "q", "z"};
>>> +     "m", "v", "p", "x", "a", "y", "q", "z"};
>>>
>>>  /* The default definitions have been moved to st_options.h */
>>>
>>> @@ -3973,21 +3973,15 @@ static struct st_buffer *new_tape_buffer(int max_sg)
>>>  {
>>>       struct st_buffer *tb;
>>>
>>> -     tb = kzalloc_obj(struct st_buffer);
>>> +     tb = kzalloc_flex(*tb, reserved_pages, max_sg);
>>>       if (!tb) {
>>>               printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n");
>>>               return NULL;
>>>       }
>>> -     tb->frp_segs = 0;
>>>       tb->use_sg = max_sg;
>>> +     tb->frp_segs = 0;
>>>       tb->buffer_size = 0;
>>>
>>> -     tb->reserved_pages = kzalloc_objs(struct page *, max_sg);
>>
>> reserve_pages is in the middle of struct st_buffer so you cannot use a flex array.
> This patch moves it, no?

Do! Completely missed that. Looks good then, but please write a commit message.

-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: st: use kzalloc_array
  2026-07-05  1:08     ` Damien Le Moal
@ 2026-07-05  1:15       ` Rosen Penev
  0 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2026-07-05  1:15 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: linux-scsi, Kai Mäkisara, James E.J. Bottomley,
	Martin K. Petersen, Kees Cook, Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be|_ptr)?b

On Sat, Jul 4, 2026 at 6:08 PM Damien Le Moal <dlemoal@kernel.org> wrote:
>
> On 7/4/26 04:06, Rosen Penev wrote:
> > On Tue, Jun 30, 2026 at 12:28 AM Damien Le Moal <dlemoal@kernel.org> wrote:
> >>
> >> On 6/30/26 10:21, Rosen Penev wrote:
> >>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> >>
> >> No commit message ? Please explain your reasonning, because I find this patch
> >> incorrect. See below.
> >>
> >>> ---
> >>>  drivers/scsi/st.c | 12 +++---------
> >>>  drivers/scsi/st.h |  3 ++-
> >>>  2 files changed, 5 insertions(+), 10 deletions(-)
> >>>
> >>> diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
> >>> index f1c3c4946637..31ae189b18e7 100644
> >>> --- a/drivers/scsi/st.c
> >>> +++ b/drivers/scsi/st.c
> >>> @@ -149,7 +149,7 @@ static struct st_dev_parm {
> >>>     mode counts */
> >>>  static const char *st_formats[] = {
> >>>       "",  "r", "k", "s", "l", "t", "o", "u",
> >>> -     "m", "v", "p", "x", "a", "y", "q", "z"};
> >>> +     "m", "v", "p", "x", "a", "y", "q", "z"};
> >>>
> >>>  /* The default definitions have been moved to st_options.h */
> >>>
> >>> @@ -3973,21 +3973,15 @@ static struct st_buffer *new_tape_buffer(int max_sg)
> >>>  {
> >>>       struct st_buffer *tb;
> >>>
> >>> -     tb = kzalloc_obj(struct st_buffer);
> >>> +     tb = kzalloc_flex(*tb, reserved_pages, max_sg);
> >>>       if (!tb) {
> >>>               printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n");
> >>>               return NULL;
> >>>       }
> >>> -     tb->frp_segs = 0;
> >>>       tb->use_sg = max_sg;
> >>> +     tb->frp_segs = 0;
> >>>       tb->buffer_size = 0;
> >>>
> >>> -     tb->reserved_pages = kzalloc_objs(struct page *, max_sg);
> >>
> >> reserve_pages is in the middle of struct st_buffer so you cannot use a flex array.
> > This patch moves it, no?
>
> Do! Completely missed that. Looks good then, but please write a commit message.
I sent a v2. One bug with this was I forgot to remove the kfree call.
>
> --
> Damien Le Moal
> Western Digital Research

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-05  1:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30  1:21 [PATCH] scsi: st: use kzalloc_array Rosen Penev
2026-06-30  7:28 ` Damien Le Moal
2026-07-03 19:06   ` Rosen Penev
2026-07-05  1:08     ` Damien Le Moal
2026-07-05  1:15       ` Rosen Penev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.