scsi: st: use kzalloc_array
Subsystems (2)
PATCH 1/1 scsi: st: use kzalloc_array
--- drivers/scsi/st.c | 12 +++--------- drivers/scsi/st.h | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-)
drivers/scsi/st.c +3 -9
@@ -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; }
drivers/scsi/st.h +2 -1
@@ -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 */
Signature · 1 line
2.54.0
Quoted 1 line · Rosen Penev
Signed-off-by Rosen Penev <[email protected]>
No commit message ? Please explain your reasonning, because I find this patch incorrect. See below.
Quoted 24 lines
--- drivers/scsi/st.c | 12 +++--------- drivers/scsi/st.h | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-)drivers/scsi/st.c +2
-2@@ -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);
drivers/scsi/st.c static struct st_buffer *new_tape_buffer(int max_sg) · line 3985
Quoted 10 lines
drivers/scsi/st.c +1
-2if (!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.
Quoted 29 lines
drivers/scsi/st.c +0
-5-if (!tb->reserved_pages) { -kfree (tb); -return NULL ; - } -return tb; }drivers/scsi/st.h +2
-1@@ -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 */
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 40 lines · Damien Le Moal
Quoted 1 line · Rosen Penev
Signed-off-by Rosen Penev <[email protected]>No commit message ? Please explain your reasonning, because I find this patch incorrect. See below.
Quoted 33 lines
--- drivers/scsi/st.c | 12 +++--------- drivers/scsi/st.h | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-)drivers/scsi/st.c +3
-3@@ -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 ;
Quoted 3 lines
drivers/scsi/st.c static struct st_buffer *new_tape_buffer(int max_sg) · line 3985
Quoted 1 line
drivers/scsi/st.c +0
-1- tb->reserved_pages = kzalloc_objs(struct page *, max_sg);
reserve_pagesis in the middle of structst_bufferso you cannot use a flex array.
This patch moves it, no?
Quoted 35 lines
Quoted 22 lines
drivers/scsi/st.c +0
-5-if (!tb->reserved_pages) { -kfree (tb); -return NULL ; - } -return tb; }drivers/scsi/st.h +0
-1@@ -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;drivers/scsi/st.h struct st_buffer { · line 59
Quoted 8 lines
drivers/scsi/st.h +2
-0@@ -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
Quoted 41 lines · Rosen Penev
Quoted 40 lines · Damien Le Moal
Quoted 1 line · Rosen Penev
Signed-off-by Rosen Penev <[email protected]>No commit message ? Please explain your reasonning, because I find this patch incorrect. See below.
Quoted 33 lines
--- drivers/scsi/st.c | 12 +++--------- drivers/scsi/st.h | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-)drivers/scsi/st.c +3
-3@@ -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 ;
Quoted 4 lines
Quoted 3 lines
drivers/scsi/st.c static struct st_buffer *new_tape_buffer(int max_sg) · line 3985
Quoted 1 line
drivers/scsi/st.c +0
-1- tb->reserved_pages = kzalloc_objs(struct page *, max_sg);
reserve_pagesis in the middle of structst_bufferso you cannot use a flex array.This patch moves it, no?
Do! Completely missed that. Looks good then, but please write a commit message.
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 43 lines · Damien Le Moal
Quoted 41 lines · Rosen Penev
Quoted 40 lines · Damien Le Moal
Quoted 1 line · Rosen Penev
Signed-off-by Rosen Penev <[email protected]>No commit message ? Please explain your reasonning, because I find this patch incorrect. See below.
Quoted 33 lines
--- drivers/scsi/st.c | 12 +++--------- drivers/scsi/st.h | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-)drivers/scsi/st.c +3
-3@@ -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 ;
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
drivers/scsi/st.c static struct st_buffer *new_tape_buffer(int max_sg) · line 3985
Quoted 1 line
drivers/scsi/st.c +0
-1- tb->reserved_pages = kzalloc_objs(struct page *, max_sg);
reserve_pagesis in the middle of structst_bufferso 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.
Quoted 4 lines
--
Damien Le Moal
Western Digital Research