Yes. the if condition makes sure to return REF_CLK_FREQ_INVAL if freq is not what we expect.+static struct ufs_ref_clk ufs_ref_clk_freqs[] = {Is the if clause really needed?
+ {19200000, REF_CLK_FREQ_19_2_MHZ},
+ {26000000, REF_CLK_FREQ_26_MHZ},
+ {38400000, REF_CLK_FREQ_38_4_MHZ},
+ {52000000, REF_CLK_FREQ_52_MHZ},
+ {0, REF_CLK_FREQ_INVAL},
+};
+
+static inline enum ufs_ref_clk_freq
+ufs_get_bref_clk_from_hz(u32 freq)
+{
+ int i = 0;
+
+ while (ufs_ref_clk_freqs[i].freq_hz != freq) {
+ if (!ufs_ref_clk_freqs[i].freq_hz)
+ return REF_CLK_FREQ_INVAL;
you will return REF_CLK_FREQ_INVAL anyway
Above if condition "if (!ufs_ref_clk_freqs[i].freq_hz)" prevents such overrun
+ i++;You might overrun here if freq is not what you've expected
+ }
+
+ return ufs_ref_clk_freqs[i].val;
+}