Skip to contentSkip to conversation

ufs: mediatek: Use ARRAY_SIZE() instead of open-coding it

PATCH Applied Bart Van Assche 3 participants 3 messages Nov 20 – Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ufs: mediatek: Use ARRAY_SIZE() instead of open-coding it

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.

---
 drivers/ufs/host/ufs-mediatek.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/ufs/host/ufs-mediatek.c +3 -4
index 5b6bff2cf9a2..14d1fcbd3661 100644
@@ -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);
maintainer Applied
#1 lore raw

Bart,

Quoted 3 lines

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!

Signature · 1 line
Martin K. Petersen
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Bart Van Assche
Quoted 20 lines · Bart Van Assche

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

Quoted 7 lines

No functionality has been changed.

Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/

---

Hi Bart,

Thanks for fix this warning.