Skip to content

Commit bcd301a

Browse files
nunojsacseci
authored andcommitted
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> (cherry picked from commit 91f00ab)
1 parent d620181 commit bcd301a

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
@@ -1156,7 +1156,7 @@ static int ad9088_clk_register(struct ad9088_phy *phy, const char *name,
11561156
return ret;
11571157

11581158
phy->clks[source] = clk_priv->hw.clk;
1159-
phy->clk_data->hws[phy->clk_data->num++] = &clk_priv->hw;
1159+
phy->clk_data->hws[source] = &clk_priv->hw;
11601160

11611161
return 0;
11621162
}
@@ -5148,6 +5148,11 @@ static int ad9088_probe(struct spi_device *spi)
51485148
if (!phy->clk_data)
51495149
return -ENOMEM;
51505150

5151+
/*
5152+
* Even though we already allocate NUM_AD9088_CLKS, RX_SAMPL_CLK_LINK2 is still
5153+
* not being registered, hence the -1.
5154+
*/
5155+
phy->clk_data->num = NUM_AD9088_CLKS - 1;
51515156
ret = ad9088_clk_register(phy, "-rx_sampl_clk", __clk_get_name(dev_clk), NULL,
51525157
CLK_GET_RATE_NOCACHE | CLK_IGNORE_UNUSED, RX_SAMPL_CLK);
51535158
if (ret)

0 commit comments

Comments
 (0)