summaryrefslogtreecommitdiff
path: root/drivers/clk/sunxi-ng
diff options
context:
space:
mode:
authorJernej Skrabec <jernej.skrabec@siol.net>2019-04-03 18:14:04 +0300
committerMaxime Ripard <maxime.ripard@bootlin.com>2019-04-04 10:32:32 +0300
commit1054e4dd1cbbb7bf5cc836832648f9972134ef67 (patch)
tree74ba5e554dbdf3d6b197bed2bdeff31c437ac904 /drivers/clk/sunxi-ng
parent2abc330c514fe56c570bb1a6318b054b06a4f72e (diff)
downloadlinux-1054e4dd1cbbb7bf5cc836832648f9972134ef67.tar.xz
clk: sunxi-ng: nkmp: Explain why zero width check is needed
Add an explanation why zero width check is needed when generating factor mask using GENMASK() macro. Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
Diffstat (limited to 'drivers/clk/sunxi-ng')
-rw-r--r--drivers/clk/sunxi-ng/ccu_nkmp.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/clk/sunxi-ng/ccu_nkmp.c b/drivers/clk/sunxi-ng/ccu_nkmp.c
index 69dfc6de1c4e..cbcdf664f336 100644
--- a/drivers/clk/sunxi-ng/ccu_nkmp.c
+++ b/drivers/clk/sunxi-ng/ccu_nkmp.c
@@ -186,6 +186,12 @@ static int ccu_nkmp_set_rate(struct clk_hw *hw, unsigned long rate,
ccu_nkmp_find_best(parent_rate, rate, &_nkmp);
+ /*
+ * If width is 0, GENMASK() macro may not generate expected mask (0)
+ * as it falls under undefined behaviour by C standard due to shifts
+ * which are equal or greater than width of left operand. This can
+ * be easily avoided by explicitly checking if width is 0.
+ */
if (nkmp->n.width)
n_mask = GENMASK(nkmp->n.width + nkmp->n.shift - 1,
nkmp->n.shift);