[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ba027737-39df-4541-8fea-1c4cf489b43b@linux.dev>
Date: Thu, 19 Jun 2025 13:15:06 +0100
From: Vadim Fedorenko <vadim.fedorenko@...ux.dev>
To: Paolo Abeni <pabeni@...hat.com>, Ivan Vecera <ivecera@...hat.com>,
netdev@...r.kernel.org
Cc: Prathosh Satish <Prathosh.Satish@...rochip.com>,
Arkadiusz Kubalewski <arkadiusz.kubalewski@...el.com>,
Jiri Pirko <jiri@...nulli.us>, Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>, Conor Dooley
<conor+dt@...nel.org>, "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Simon Horman <horms@...nel.org>, Jonathan Corbet <corbet@....net>,
Jason Gunthorpe <jgg@...pe.ca>, Shannon Nelson <shannon.nelson@....com>,
Dave Jiang <dave.jiang@...el.com>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
Michal Schmidt <mschmidt@...hat.com>, Petr Oros <poros@...hat.com>
Subject: Re: [PATCH net-next v11 13/14] dpll: zl3073x: Add support to get/set
frequency on input pins
On 19/06/2025 12:15, Paolo Abeni wrote:
> 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.
I might be a good idea to use mul_u64_u32_div together with mul_u32_u32?
These macroses will take care of overflow on 32bit platforms as well.
>
> /P
>
Powered by blists - more mailing lists