scsi: st: use kzalloc_array()
Subsystems (2)
PATCH v2 1/1 scsi: st: use kzalloc_array()
Merge allocations to simpily memory management with kzalloc_array(). No need to kfree separately.
Add __counted_by for extra runtime analysis. Move counting variable assignment after allocation as kzalloc_flex() does this with newer compilers.
---
v2: remove the kfree and add a description.
drivers/scsi/st.c | 13 +++---------- drivers/scsi/st.h | 3 ++- 2 files changed, 5 insertions(+), 11 deletions(-)
drivers/scsi/st.c +3 -10
@@ -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; }
@@ -4533,7 +4527,6 @@ static void scsi_tape_release(struct kref *kref)if (tpnt->buffer) {normalize_buffer (tpnt->buffer); -kfree (tpnt->buffer->reserved_pages);kfree (tpnt->buffer); }
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 */
--
2.55.0
Quoted 4 lines · Rosen Penev
Merge allocations to simpily memory management with
kzalloc_array(). No need to kfree separately.
I fail to see what is the real problem this patch fixes? I am not in favor of rewiritng working code just because it can be done.
Quoted 1 line · Rosen Penev
Merge allocations to simpily memory management with
kzalloc_array(). No
s/simpily/simplify
Quoted 7 lines
need to kfree separately.
Add
__counted_byfor extra runtime analysis. Move counting variable assignment after allocation askzalloc_flex()does this with newer compilers.Signed-off-by Rosen Penev <[email protected]>
With the typo fixed, this looks OK to me.
Signature · 2 lines
Damien Le Moal Western Digital Research