linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] scsi: hisi_sas: Use devm_bitmap_zalloc() when applicable
@ 2021-11-26 21:15 Christophe JAILLET
  2021-11-26 21:18 ` [PATCH 2/3] scsi: hisi_sas: Remove some useless code in 'hisi_sas_alloc()' Christophe JAILLET
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Christophe JAILLET @ 2021-11-26 21:15 UTC (permalink / raw)
  To: john.garry, jejb, martin.petersen
  Cc: linux-scsi, linux-kernel, kernel-janitors, Christophe JAILLET

'hisi_hba->slot_index_tags' is a bitmap. So use 'devm_bitmap_zalloc()' to
simplify code, improve the semantic and avoid some open-coded arithmetic
in allocator arguments.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
The use of 's' is questionable here. I've left it because it looks more
consistent this way with the surrounding code.

Can it be an issue to have the length of the allocated bitmap not being
a multiple of sizeof(long)?
I guess that there is some kind of 'rounding' done by the memory allocator
to keep some alignment, so I think that the previous code is safe (but not
logical).
If this is not the case, there is a potential out of bound bug related to
the bitmap API that expect to access only longs (which is not necessarily
the case here).
---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index f206c433de32..6ecb42d5ce81 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -2516,9 +2516,8 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba)
 	if (!hisi_hba->breakpoint)
 		goto err_out;
 
-	hisi_hba->slot_index_count = max_command_entries;
-	s = hisi_hba->slot_index_count / BITS_PER_BYTE;
-	hisi_hba->slot_index_tags = devm_kzalloc(dev, s, GFP_KERNEL);
+	s = hisi_hba->slot_index_count = max_command_entries;
+	hisi_hba->slot_index_tags = devm_bitmap_zalloc(dev, s, GFP_KERNEL);
 	if (!hisi_hba->slot_index_tags)
 		goto err_out;
 
-- 
2.30.2


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

end of thread, other threads:[~2021-12-14  4:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 21:15 [PATCH 1/3] scsi: hisi_sas: Use devm_bitmap_zalloc() when applicable Christophe JAILLET
2021-11-26 21:18 ` [PATCH 2/3] scsi: hisi_sas: Remove some useless code in 'hisi_sas_alloc()' Christophe JAILLET
2021-12-06 13:23   ` John Garry
2021-11-26 21:18 ` [PATCH 3/3] scsi: hisi_sas: Use non-atomic bitmap functions when possible Christophe JAILLET
2021-12-06 14:30   ` John Garry
2021-12-06 13:22 ` [PATCH 1/3] scsi: hisi_sas: Use devm_bitmap_zalloc() when applicable John Garry
2021-12-07  3:13 ` Martin K. Petersen
2021-12-14  4:40 ` Martin K. Petersen

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).