Re: [PATCH v2 1/1] i2c: qcom-geni: Support systems with 32MHz serial engine clock

From: Bjorn Andersson
Date: Thu Sep 26 2024 - 08:48:56 EST


On Thu, Sep 26, 2024 at 01:28:37PM GMT, Vladimir Zapolskiy wrote:
> On 9/26/24 06:43, Manikanta Mylavarapu wrote:
> > diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
[..]
> > +
> > static int geni_i2c_clk_map_idx(struct geni_i2c_dev *gi2c)
> > {
> > int i;
> > - const struct geni_i2c_clk_fld *itr = geni_i2c_clk_map;
> > + const struct geni_i2c_clk_fld *itr;
> > +
> > + if (clk_get_rate(gi2c->se.clk) == 32 * HZ_PER_MHZ)
> > + itr = geni_i2c_clk_map_32mhz;
> > + else
> > + itr = geni_i2c_clk_map_19p2mhz;
> > - for (i = 0; i < ARRAY_SIZE(geni_i2c_clk_map); i++, itr++) {
> > + for (i = 0; i < ARRAY_SIZE(geni_i2c_clk_map_19p2mhz); i++, itr++) {
>
> Struct/data organization here is so weak, that here it's implicitly assumed
> that sizes of two arrays are equal. It could be kept as is of course, just
> pointing to it.
>

Thanks for pointing this out, Vladimir.

I'd prefer we fix it by adding a sentinel value to the arrays - because
this was only spotted due to the rename, the next guy will not be so
lucky.

Regards,
Bjorn

> > if (itr->clk_freq_out == gi2c->clk_freq_out) {
> > gi2c->clk_fld = itr;
> > return 0;
>
> --
> Best wishes,
> Vladimir
>