linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: fnic: Use kmalloc instead of vmalloc for a small memory allocation
@ 2020-04-23 20:46 Christophe JAILLET
  2020-04-24  9:30 ` Dan Carpenter
  2020-05-06 12:27 ` Hannes Reinecke
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2020-04-23 20:46 UTC (permalink / raw)
  To: satishkh, sebaddel, kartilak, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

'struct fc_trace_flag_type' is just a few bytes long. There is no need
to allocate such a structure with vmalloc. Using kmalloc instead.

While at it, axe a useless test when freeing the memory.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/scsi/fnic/fnic_debugfs.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/fnic/fnic_debugfs.c b/drivers/scsi/fnic/fnic_debugfs.c
index 13f7d88d6e57..8d6ce3470594 100644
--- a/drivers/scsi/fnic/fnic_debugfs.c
+++ b/drivers/scsi/fnic/fnic_debugfs.c
@@ -58,8 +58,7 @@ int fnic_debugfs_init(void)
 						fnic_trace_debugfs_root);
 
 	/* Allocate memory to structure */
-	fc_trc_flag = (struct fc_trace_flag_type *)
-		vmalloc(sizeof(struct fc_trace_flag_type));
+	fc_trc_flag = kmalloc(sizeof(*fc_trc_flag), GFP_KERNEL);
 
 	if (fc_trc_flag) {
 		fc_trc_flag->fc_row_file = 0;
@@ -87,8 +86,7 @@ void fnic_debugfs_terminate(void)
 	debugfs_remove(fnic_trace_debugfs_root);
 	fnic_trace_debugfs_root = NULL;
 
-	if (fc_trc_flag)
-		vfree(fc_trc_flag);
+	kfree(fc_trc_flag);
 }
 
 /*
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: fnic: Use kmalloc instead of vmalloc for a small memory allocation
@ 2020-04-24 14:50 Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2020-04-24 14:50 UTC (permalink / raw)
  To: Christophe Jaillet, linux-scsi
  Cc: kernel-janitors, linux-kernel, Dan Carpenter,
	James E. J. Bottomley, Karan Tilak Kumar, Martin K. Petersen,
	Satish Kharat, Sesidhar Baddela

> 'struct fc_trace_flag_type' is just a few bytes long. There is no need
> to allocate such a structure with vmalloc. Using kmalloc instead.

Can such an adjustment be relevant for the specification of the tag “Fixes”?


> While at it, axe a useless test when freeing the memory.

I find it more appropriate to provide this source code improvement
by a separate update step.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=b4f633221f0aeac102e463a4be46a643b2e3b819#n138

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/coccinelle/free/ifnullfree.cocci?id=b4f633221f0aeac102e463a4be46a643b2e3b819#n4

Regards,
Markus

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

end of thread, other threads:[~2020-05-06 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 20:46 [PATCH] scsi: fnic: Use kmalloc instead of vmalloc for a small memory allocation Christophe JAILLET
2020-04-24  9:30 ` Dan Carpenter
2020-05-06 12:27 ` Hannes Reinecke
2020-04-24 14:50 Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).