Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3678382lfo; Mon, 23 May 2022 11:10:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2/tQjFzfkZaRS0LFBZDU7LidzvHP3JGA76BS1WLaItuMPiLRyUgTSA4KrhXukXi7yRMa/ X-Received: by 2002:a65:6205:0:b0:3f5:d436:5446 with SMTP id d5-20020a656205000000b003f5d4365446mr20673764pgv.532.1653329400100; Mon, 23 May 2022 11:10:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653329400; cv=none; d=google.com; s=arc-20160816; b=qROkfBMPCkTaO+FTacu1Sqa5FL5Uo/sPz4sQqmfc3l/h9WUx0FR2QP2tZEdYXQ9B/p usVZP0u8Sjh2BroxtmUvSegcTH9wjkYqCxMxS5CuVcd/ZZOUHoqezXbYnRGtklP+svEw PjJ+FKprMVFTLfqo4aY2eAorklssD8mgKXpRQSzV05QEZU6eUReOWvO+Mo/YUb8YZ6LV jIDJ1bgBkOtPdYfkufUk3bkSqxXTC0WsVL9Fb30K7a2NDZCN/7ZLeEFKthgi/Ut5foQH YG62T3cAyLEE9lZdxlDedZohr1wCVRu+0JWvwAmAMseEkQKwVojfxt9crEgUnh3wjq35 nvKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G1+CntNnFaEy8mJ6rb90T7CQJ2icSMWU44Ve7pFHYt8=; b=F8nM2UcxVZ11TPvTfqVhZWc8DwrXTo5BVcbPmHu+c28pXST6ADKhpvzFyzAD4UceO5 pxcJHEnHQnqFkQG5IHP1ECUTUb+nP22Df6Vf2cHLzW+rHPlQUtJGRm0RvwRz3FqlRrO/ 0YbRWoWQ1V6MrzXG5T9IfVrVRFEFkGnaPSoXL/9DnxzduHag5L9YBwMco6EOCI0P8EwP uooVRXtekj3UaVkreNmkwsCQrdjo2UCR89bnru7km7DiXHZvrFjfRu+cJNRmTVXLlLST TwlgkIRFpvsiFvUcvSGXXIyXob3DplqEEH+SQRH8wDbzVUrKydEGDUUCTRaBPAtTBODv XGVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c1EeB3GH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b18-20020a170902ed1200b00161f87598d5si10119319pld.573.2022.05.23.11.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:10:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c1EeB3GH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9ACEA14B2CD; Mon, 23 May 2022 11:09:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244316AbiEWSCr (ORCPT + 99 others); Mon, 23 May 2022 14:02:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241255AbiEWRe2 (ORCPT ); Mon, 23 May 2022 13:34:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 767A47CDC6; Mon, 23 May 2022 10:28:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 46AA2608C0; Mon, 23 May 2022 17:28:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46740C385A9; Mon, 23 May 2022 17:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653326889; bh=W89CsubPW/Em66wY0PHx9GzSKhev0KIhivQtzaBnt+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c1EeB3GHF9ynaZs87rOC+Hd02/y6VqF9yVKrfWRBGQgMN6NBWrVdG5daldBwhz9xV iqTn746obFPFDonjORKR1CU+VtVi+AD6NZ+Tvf+UxtcIVe/feBAzqeh/r5jLaZeDR9 S7txDlDg53rf5vAndDg9qpkWDbNnBiijEeffvS2I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vadim Fedorenko , Jonathan Lemon , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.17 089/158] ptp: ocp: have adjtime handle negative delta_ns correctly Date: Mon, 23 May 2022 19:04:06 +0200 Message-Id: <20220523165845.891391295@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165830.581652127@linuxfoundation.org> References: <20220523165830.581652127@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Lemon [ Upstream commit da2172a9bfec858ceeb0271b9d444378490398c8 ] delta_ns is a s64, but it was being passed ptp_ocp_adjtime_coarse as an u64. Also, it turns out that timespec64_add_ns() only handles positive values, so perform the math with set_normalized_timespec(). Fixes: 90f8f4c0e3ce ("ptp: ocp: Add ptp_ocp_adjtime_coarse for large adjustments") Suggested-by: Vadim Fedorenko Signed-off-by: Jonathan Lemon Acked-by: Vadim Fedorenko Link: https://lore.kernel.org/r/20220513225231.1412-1-jonathan.lemon@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/ptp/ptp_ocp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c index 17ad5f0d13b2..6585789ed695 100644 --- a/drivers/ptp/ptp_ocp.c +++ b/drivers/ptp/ptp_ocp.c @@ -625,7 +625,7 @@ __ptp_ocp_adjtime_locked(struct ptp_ocp *bp, u32 adj_val) } static void -ptp_ocp_adjtime_coarse(struct ptp_ocp *bp, u64 delta_ns) +ptp_ocp_adjtime_coarse(struct ptp_ocp *bp, s64 delta_ns) { struct timespec64 ts; unsigned long flags; @@ -634,7 +634,8 @@ ptp_ocp_adjtime_coarse(struct ptp_ocp *bp, u64 delta_ns) spin_lock_irqsave(&bp->lock, flags); err = __ptp_ocp_gettime_locked(bp, &ts, NULL); if (likely(!err)) { - timespec64_add_ns(&ts, delta_ns); + set_normalized_timespec64(&ts, ts.tv_sec, + ts.tv_nsec + delta_ns); __ptp_ocp_settime_locked(bp, &ts); } spin_unlock_irqrestore(&bp->lock, flags); -- 2.35.1