Skip to content

Commit 91f00ab

Browse files
committed
iio: trx-rf: ad9088: fix __counted_by misuse in ad9088_clk_register()
clk_hw_onecell_data::hws is a flexible array annotated with __counted_by(num). Using hws[num++] to append clocks is, in theory, correct from a sequence point perspective (the post-increment in a subscript is well-defined in C), but it triggers -Wsequence-point warnings with recent GCC versions. More importantly, it violates the __counted_by contract: the array is accessed at index num before the counter is incremented, triggering runtime UBSAN bounds checks. Fix this by indexing hws with the source enum directly (which already indexes into phy->clks[]) and setting clk_data->num once upfront in ad9088_probe(). Signed-off-by: Nuno Sá <nuno.sa@analog.com>
1 parent acce9f0 commit 91f00ab

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/iio/trx-rf/ad9088/ad9088.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ static int ad9088_clk_register(struct ad9088_phy *phy, const char *name,
12221222
return ret;
12231223

12241224
phy->clks[source] = clk_priv->hw.clk;
1225-
phy->clk_data->hws[phy->clk_data->num++] = &clk_priv->hw;
1225+
phy->clk_data->hws[source] = &clk_priv->hw;
12261226

12271227
return 0;
12281228
}
@@ -5215,6 +5215,11 @@ static int ad9088_probe(struct spi_device *spi)
52155215
if (!phy->clk_data)
52165216
return -ENOMEM;
52175217

5218+
/*
5219+
* Even though we already allocate NUM_AD9088_CLKS, RX_SAMPL_CLK_LINK2 is still
5220+
* not being registered, hence the -1.
5221+
*/
5222+
phy->clk_data->num = NUM_AD9088_CLKS - 1;
52185223
ret = ad9088_clk_register(phy, "-rx_sampl_clk", __clk_get_name(dev_clk), NULL,
52195224
CLK_GET_RATE_NOCACHE | CLK_IGNORE_UNUSED, RX_SAMPL_CLK);
52205225
if (ret)

0 commit comments

Comments
 (0)