From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8230230BF2 for ; Thu, 19 Jun 2025 12:15:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335332; cv=none; b=aHV3h2liWtcOyEWo42ItT342b2kIIUlyqvBt3x0WnIPPfcdOhbTkQThOmHsw/zillUXGsdAjIlLaFhFzzP0PN9v5PoL8EThPDJkCH/PZ8Qjg7ceaOSVZVAESO5COX307wmzjWdFa7T7pcyru/UGanKaZ6zZkt1uWbvF6+lbes+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750335332; c=relaxed/simple; bh=1ravPs/FMxL5LuoHuJXK+mU1twHGVx7Ojyt5HQnO1BM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=CUFprJtoSvNYS7pXO+0CcHjnI/0ptoyjoK4JyqSz7jTlWNiA2QS4sSAz5DYORz4y/tJbxBKxSaCvhiTRHsVXX8/f7w30LMeKkdE0hZR59+nVJq5Y1N5h96rsWW4rVfNoEV1T3Lw6hct3g+7GK5QcGUeVM0MCjKWQ3BBu5nyocQE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=hX2FayJz; arc=none smtp.client-ip=95.215.58.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hX2FayJz" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1750335318; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a5tu14SfjOQv5TBx7EfkgfUxq/XAyStwsImnQzyxPqY=; b=hX2FayJz88BPRw7Yx23sBwK2HlaMWc7WrD5xufoIQxieXk3feCCpo6V78k6uSLItgcFPsE x1fCvcVembCR3QIZ/KPkzlmeNaDJQPeBdsqKboeVHFTrRzyFjEidyBPm5dV0OqdzEGubZP xApztwwVir8jr/6tE6Fqgyv28YHcjz0= Date: Thu, 19 Jun 2025 13:15:06 +0100 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH net-next v11 13/14] dpll: zl3073x: Add support to get/set frequency on input pins To: Paolo Abeni , Ivan Vecera , netdev@vger.kernel.org Cc: Prathosh Satish , Arkadiusz Kubalewski , Jiri Pirko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Simon Horman , Jonathan Corbet , Jason Gunthorpe , Shannon Nelson , Dave Jiang , Jonathan Cameron , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Michal Schmidt , Petr Oros References: <20250616201404.1412341-1-ivecera@redhat.com> <20250616201404.1412341-14-ivecera@redhat.com> <72bab3b2-bdd6-43f6-9243-55009f9c1071@redhat.com> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vadim Fedorenko In-Reply-To: <72bab3b2-bdd6-43f6-9243-55009f9c1071@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT 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 >