Re: [PATCH net-next v11 13/14] dpll: zl3073x: Add support to get/set frequency on input pins
From: Paolo Abeni
Date: Thu Jun 19 2025 - 07:15:45 EST
On 6/16/25 10:14 PM, Ivan Vecera wrote:
> +/**
> + * zl3073x_dpll_input_ref_frequency_get - get input reference frequency
> + * @zldpll: pointer to zl3073x_dpll
> + * @ref_id: reference id
> + * @frequency: pointer to variable to store frequency
> + *
> + * Reads frequency of given input reference.
> + *
> + * Return: 0 on success, <0 on error
> + */
> +static int
> +zl3073x_dpll_input_ref_frequency_get(struct zl3073x_dpll *zldpll, u8 ref_id,
> + u32 *frequency)
> +{
> + struct zl3073x_dev *zldev = zldpll->dev;
> + u16 base, mult, num, denom;
> + int rc;
> +
> + guard(mutex)(&zldev->multiop_lock);
> +
> + /* Read reference configuration */
> + rc = zl3073x_mb_op(zldev, ZL_REG_REF_MB_SEM, ZL_REF_MB_SEM_RD,
> + ZL_REG_REF_MB_MASK, BIT(ref_id));
> + if (rc)
> + return rc;
> +
> + /* Read registers to compute resulting frequency */
> + rc = zl3073x_read_u16(zldev, ZL_REG_REF_FREQ_BASE, &base);
> + if (rc)
> + return rc;
> + rc = zl3073x_read_u16(zldev, ZL_REG_REF_FREQ_MULT, &mult);
> + if (rc)
> + return rc;
> + rc = zl3073x_read_u16(zldev, ZL_REG_REF_RATIO_M, &num);
> + if (rc)
> + return rc;
> + rc = zl3073x_read_u16(zldev, ZL_REG_REF_RATIO_N, &denom);
> + if (rc)
> + return rc;
> +
> + /* Sanity check that HW has not returned zero denominator */
> + if (!denom) {
> + dev_err(zldev->dev,
> + "Zero divisor for ref %u frequency got from device\n",
> + ref_id);
> + return -EINVAL;
> + }
> +
> + /* Compute the frequency */
> + *frequency = base * mult * num / denom;
As base, mult, num and denom are u16, the above looks like integer
overflow prone.
I think you should explicitly cast to u64, and possibly use a u64 frequency.
/P