All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ufs: mediatek: Use ARRAY_SIZE() instead of open-coding it
@ 2026-11-20  0:49 Bart Van Assche
  2026-11-20  2:47 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2026-11-20  0:49 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Bart Van Assche, kernel test robot, Peter Wang,
	Chaotian Jing, James E.J. Bottomley, Martin K. Petersen,
	Matthias Brugger, AngeloGioacchino Del Regno

The kernel test robot reported the following Coccinelle warning:

drivers/ufs/host/ufs-mediatek.c:1351:32-33: WARNING: Use ARRAY_SIZE

Derive array bounds from the arrays themselves such that these bounds
remain correct if array elements are added or removed.

In ufs_mtk_adjust_sync_length(), replace the open-coded
sizeof(pa_min_sync_length) / sizeof(struct attr_min) computation with
ARRAY_SIZE(pa_min_sync_length) and remove the local variable 'cnt' since
it is no longer needed. This fixes the reported warning.

Additionally, in ufs_mtk_setup_clk_gating(), replace the hard-coded
upper bound in the range check on the scale_us[] index by
ARRAY_SIZE(scale_us). This has not been reported by the kernel test
robot. Since scale_us[] has six elements, 'ah_scale <= 5' is equivalent
to 'ah_scale < ARRAY_SIZE(scale_us)'.

No functionality has been changed.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202611170300.dsQhfOB9-lkp@intel.com/
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/ufs/host/ufs-mediatek.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/ufs/host/ufs-mediatek.c b/drivers/ufs/host/ufs-mediatek.c
index 5b6bff2cf9a2..14d1fcbd3661 100644
--- a/drivers/ufs/host/ufs-mediatek.c
+++ b/drivers/ufs/host/ufs-mediatek.c
@@ -1132,7 +1132,7 @@ static void ufs_mtk_setup_clk_gating(struct ufs_hba *hba)
 					  hba->ahit);
 			ah_timer = FIELD_GET(UFSHCI_AHIBERN8_TIMER_MASK,
 					  hba->ahit);
-			if (ah_scale <= 5)
+			if (ah_scale < ARRAY_SIZE(scale_us))
 				ah_ms = ah_timer * scale_us[ah_scale] / 1000;
 		}
 
@@ -1376,7 +1376,7 @@ static void ufs_mtk_adjust_sync_length(struct ufs_hba *hba)
 {
 	int i;
 	u32 value;
-	u32 cnt, att, min;
+	u32 att, min;
 	struct attr_min {
 		u32 attr;
 		u32 min_value;
@@ -1388,8 +1388,7 @@ static void ufs_mtk_adjust_sync_length(struct ufs_hba *hba)
 		{PA_TXHSG5SYNCLENGTH, 0x48}
 	};
 
-	cnt = sizeof(pa_min_sync_length) / sizeof(struct attr_min);
-	for (i = 0; i < cnt; i++) {
+	for (i = 0; i < ARRAY_SIZE(pa_min_sync_length); i++) {
 		att = pa_min_sync_length[i].attr;
 		min = pa_min_sync_length[i].min_value;
 		ufshcd_dme_get(hba, UIC_ARG_MIB(att), &value);

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

* Re: [PATCH] ufs: mediatek: Use ARRAY_SIZE() instead of open-coding it
  2026-11-20  0:49 [PATCH] ufs: mediatek: Use ARRAY_SIZE() instead of open-coding it Bart Van Assche
@ 2026-11-20  2:47 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2026-11-20  2:47 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, linux-scsi, kernel test robot, Peter Wang,
	Chaotian Jing, James E.J. Bottomley, Martin K. Petersen,
	Matthias Brugger, AngeloGioacchino Del Regno


Bart,

> The kernel test robot reported the following Coccinelle warning:
>
> drivers/ufs/host/ufs-mediatek.c:1351:32-33: WARNING: Use ARRAY_SIZE

Applied to 7.5/scsi-staging, thanks!

-- 
Martin K. Petersen

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

end of thread, other threads:[~2026-11-20  2:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  0:49 [PATCH] ufs: mediatek: Use ARRAY_SIZE() instead of open-coding it Bart Van Assche
2026-11-20  2:47 ` Martin K. Petersen

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.