Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp464331rdb; Thu, 30 Nov 2023 09:11:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfO8NuHJ3VDhhNYaU/Eyeu6o/O6DnnedvdIqE3OOaWnX+sgOuXkfDIQ5ZTBql7iohfWiJ5 X-Received: by 2002:a05:6808:2020:b0:3ad:f866:39bd with SMTP id q32-20020a056808202000b003adf86639bdmr218058oiw.27.1701364305512; Thu, 30 Nov 2023 09:11:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701364305; cv=none; d=google.com; s=arc-20160816; b=AtPiV92Bt/uxmbb2Srm5F73Wr0/QqX7JLar5Tm16c2ZixBpJi71plkYwcaiwBbiuQH zu6SEjJ8dtjPj0E1hSrTEYQWj1xfjKlQ1fLnicp0tNZ71VHW1QiS8Nufaj1/P/AdmTcY 0JzwucYtbA+AAfBbCH03ImgV+LwPnU0CwIJnIdnC+8lzmIjqOCp0tl6DmwxM+N1T+X6a UVYtFfErKAuycb6jCJuawYR3ldDlQQorb2wwlD/gNFXwUZc5+Hy9JVodncZun7HKl67Z G8Mgf9aPW9YtzHwreAuB9KPYwqySQOsWY/+LonuXJILjY2LKKbcmmpFoVSAcjhlBAJae 11jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=O8xL81181th/PGuPirbDwSy2lTVC7mVCCPL2mDm1wlc=; fh=ZN/Xum6mwRGCddSqtL2ZsIMT2rwovbu6gtybYSIQFlU=; b=SQD18Qbxniy32IjKtBNx7dHX/hNglUlqvfijaoBYQz6OHncYMGRaihAUQiNv3bfKqH K/XKUl4aYx1En9zU5uzPdmC3TjYLZp9BDJ4DK5M+QSgL2R58nANdN6WzwUnQ6VT0NigH 797TMRICkCgCb3NxPtLaAa6GotCCR+yA6l+Z/Yr6FE9NmDC5i+EJxk+g7uY3y9hTFzns nlMqi7L4aejz9jdsydD4BdmKvAMLOctrEtKw9cb6SE6pUG4ms49BxzzDWSUWmWeaHPRy qbrhBjScWXN7U+mrXcGW5mJiXalvFiInwNmaAVU9qozj069j3ep8s5AqijNk9qf/0Jtu XyMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="nRhBO/OA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id bm1-20020a656e81000000b005c626128e67si1857375pgb.494.2023.11.30.09.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 09:11:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="nRhBO/OA"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6E44F8027F50; Thu, 30 Nov 2023 09:11:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232202AbjK3RL3 (ORCPT + 99 others); Thu, 30 Nov 2023 12:11:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232263AbjK3RLY (ORCPT ); Thu, 30 Nov 2023 12:11:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60435171C for ; Thu, 30 Nov 2023 09:11:30 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9765BC433C7; Thu, 30 Nov 2023 17:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701364290; bh=z8tPq/OZFdLYzHcBmbFrH1eT9NsxQ9H6d+/+FYkxiZw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nRhBO/OAOyR0zL9RuMc2BZ8dbWhnPyzxFlUAWFe1TAis9hnTHvVV0Zsa1391RCgAF vSH2hGxvMlNxIURDzEw/9XWsM2kth1WkWMZnqdH95j8H9Bkvj41RKzX/5U8OqRWuH2 D7Cc6KCrAKtjHyVvisPY9DMDKtCCU6k3B7+RqJbKCQ9HNPooA8w+Elasfm4Vim5zE5 BktKtSyphAWZ279FY0LAZJ+sKtwjgyURUX4rtdgYMU0Th8xs6gmHXgXwLldHIVlEHT 4Urs1HOcQUL4aI9+67wuhzg26rzX2py5kqFsLtbW0DU2cwNpWc7KH6BDwb8dJt32bp nnCwM8Rcj048A== Date: Thu, 30 Nov 2023 17:11:26 +0000 From: Simon Horman To: Min Li Cc: richardcochran@gmail.com, lee@kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Min Li Subject: Re: [PATCH net-next v2 2/2] ptp: add FemtoClock3 Wireless as ptp hardware clock Message-ID: <20231130171126.GH32077@kernel.org> References: <20231129204806.14539-1-lnimi@hotmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 30 Nov 2023 09:11:42 -0800 (PST) On Wed, Nov 29, 2023 at 03:48:06PM -0500, Min Li wrote: > From: Min Li > > The RENESAS FemtoClock3 Wireless is a high-performance jitter attenuator, > frequency translator, and clock synthesizer. The device is comprised of 3 > digital PLLs (DPLL) to track CLKIN inputs and three independent low phase > noise fractional output dividers (FOD) that output low phase noise clocks. > > FemtoClock3 supports one Time Synchronization (Time Sync) channel to enable > an external processor to control the phase and frequency of the Time Sync > channel and to take phase measurements using the TDC. Intended applications > are synchronization using the precision time protocol (PTP) and > synchronization with 0.5 Hz and 1 Hz signals from GNSS. > > Signed-off-by: Min Li Hi Min Li, some minor feedback from my side. ... > diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile ... > +static inline s64 ns2counters(struct idtfc3 *idtfc3, s64 nsec, u32 *sub_ns) > +{ > + s64 sync; > + s32 rem; > + > + if (likely(nsec > 0)) { > + sync = div_u64_rem(nsec, idtfc3->ns_per_sync, &rem); > + *sub_ns = rem; > + } else if (nsec < 0) { > + sync = -div_u64_rem(-nsec - 1, idtfc3->ns_per_sync, &rem) - 1; > + *sub_ns = idtfc3->ns_per_sync - rem - 1; > + } > + > + return sync * idtfc3->ns_per_sync; Perhaps it cannot occur, but if nsec is exactly 0, then sync is uninitialised here. Flagged by clang-17 W=1 build, and Smatch. > +} ... > +static int _idtfc3_settime(struct idtfc3 *idtfc3, const struct timespec64 *ts) > +{ > + s64 offset_ns, now_ns, sync_ns; > + u32 counter, sub_ns; > + int now; > + > + if (timespec64_valid(ts) == false) { > + dev_err(idtfc3->dev, "%s: invalid timespec", __func__); > + return -EINVAL; > + } > + > + now = idtfc3_read_subcounter(idtfc3); > + if (now < 0) > + return now; > + > + offset_ns = (idtfc3->sub_sync_count - now) * idtfc3->ns_per_counter; > + now_ns = timespec64_to_ns(ts); > + sync_ns = ns2counters(idtfc3, offset_ns + now_ns, &sub_ns); sync_ns is set here but otherwise unused. Perhaps the assignment can be dropped and sync_ns removed from this function? As flagged by gcc-13 W=1 build and Smatch. > + > + counter = sub_ns / idtfc3->ns_per_counter; > + return idtfc3_timecounter_update(idtfc3, counter, now_ns); > +} ...