Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp221808pxk; Thu, 1 Oct 2020 00:15:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXYCvHS2UExW1zXu/RQnv3MsaQ2aEm45zXedQfS+gyeo6wqNmfI64OCBKts/wDHNtbu8ug X-Received: by 2002:a17:906:4701:: with SMTP id y1mr1361709ejq.341.1601536529866; Thu, 01 Oct 2020 00:15:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601536529; cv=none; d=google.com; s=arc-20160816; b=tLe/LQ3cxKiwS8yBClhKd/vX59TahUH5fSPpoJHQpjqtQ7GlYW7J4vDsrOEMaRAs4x 7vYhlO/tqt6/draPWVLXnaxVRkez+CmOx8kSC8HeQtUW9BN8NxdfNnpD4A0f4lrWZZSU L1ygmqb8XgJPZXKX6RMSV/bBsb0kLgilgus8199W6QX/fP9nZMdNdoLANxIi758lOj3H +n+ACjOJ730HoZXXrQzbf21J1lpPmmGWBJJLw+fM4czG2y5y3aNMgIRw5sonEnaZUFsW XbEAIyyjpuxTwkQUe6ZNGA8ZkuWY3HoXatkj+dQMD4ceGbS3Hz5E+MNN6WqfD0FaogxI CgEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:thread-index :content-transfer-encoding:mime-version:message-id:organization:date :subject:in-reply-to:references:cc:to:from:ironport-sdr:ironport-sdr; bh=/aFRVpqAsqdvrQ6llWsd6xXbrYQQn+i5Yr0MI970ZlI=; b=hvNTLhXWRee8eFQVGzWTflFcujvNWvEGRWi5aJ/LkIAfxuPrO+b6dcxpN0N5W8Ktw+ yXhemthqWYA+b3MRmfsleN85qPeLK/AyGb7PJhHpBvS2zP8rQPKw8zKdKcV5jQZqv4nR A2Q5+X02TeZ9G48QiIceCYBPENwK7Xpfh5rLKumDP46Z3txK6gOcDQ9rCd5Es+CdCuIJ 7sn6jYRPUnJvuKm3VTP3UGtnoGO2bLVHRUU4WUWZlknin35PkHpBsY6sbJSsypPc9e+O a/L7p2/IQdkrJqnjTCqPG3dRtcOLo8aPKaVMlAeXRzNU6T7NewlgAlFZLf0ELaZ5QbRN 0bPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f26si2949989ejc.612.2020.10.01.00.15.07; Thu, 01 Oct 2020 00:15:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730967AbgJAHOK (ORCPT + 99 others); Thu, 1 Oct 2020 03:14:10 -0400 Received: from esa3.mentor.iphmx.com ([68.232.137.180]:49102 "EHLO esa3.mentor.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbgJAHOK (ORCPT ); Thu, 1 Oct 2020 03:14:10 -0400 IronPort-SDR: xhHhcrYDFEl+vS29il0sag8AtnMhCGiXX4GvkpvwgvzJG2xawyMpVRDj7MoDAa/0/6Pjj6Pc15 CVbe1rNqAYq9Rz1nY5BLnDcuipmBe4OWVda4QhY9/2ttOCVR/ufOLLRWazNj1BmDpNmNsyBXxa t9TF2JsLkA/FYIlXjaZdkizw9gXrUUT+lpAi84JRigxHYcVKh2J21wwqukPxH9sR6pzNgdjMzH p3o79s/XU95nbMLvf9J9TJCSsSpeAzkxJg7PvDUNn+fWePjR3n1+1tq7Sfs3zX9cE+BLeDOAV0 6AQ= X-IronPort-AV: E=Sophos;i="5.77,323,1596528000"; d="scan'208";a="53450460" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 30 Sep 2020 23:14:09 -0800 IronPort-SDR: 6qp/5MCh8TZrAUwcXGzSfCbMayY5W5IJffvz4BaVkerN6NCzGdjhHJMnrm4J/AzfNZbvKEylD3 DUGuReh8WZthwG0JyTpwm7pE6WE2AejMfsAp8CEPUK6nk1tcUhIwiB4CuNpEOvHz8xkR71l4Zf xlWgEynqWtqJSu3EjByNqCq8bf58p5j6Xxhn3dt4J9b54YhZE+jKpjAttnwuEWKu2mi8hjlkQe A2mMghnPc+N7WYnK/zMyaCXhVi2X6IXN1SM+QdK1JdRNh53RLvpA5U+MzymHOFcan12v52+++8 FRk= From: Andrew Gabbasov To: Sergei Shtylyov CC: , , , "David S. Miller" , , Julia Lawall , "Behme, Dirk - Bosch" , Eugeniu Rosca References: <20200930192124.25060-1-andrew_gabbasov@mentor.com> In-Reply-To: <20200930192124.25060-1-andrew_gabbasov@mentor.com> Subject: RE: [PATCH net] ravb: Fix bit fields checking in ravb_hwtstamp_get() Date: Thu, 1 Oct 2020 10:13:54 +0300 Organization: Mentor Graphics Corporation Message-ID: <000001d697c2$71651d70$542f5850$@mentor.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHWl179dggpQ/YNgUW3t7t7L6TDlKmCUESw Content-Language: en-us X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-07.mgc.mentorg.com (139.181.222.7) To svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sergei, > -----Original Message----- > From: Gabbasov, Andrew > Sent: Wednesday, September 30, 2020 10:21 PM > To: linux-renesas-soc@vger.kernel.org; netdev@vger.kernel.org; linux- > kernel@vger.kernel.org; Sergei Shtylyov ; David > S. Miller ; geert+renesas@glider.be; Julia Lawall > ; Behme, Dirk - Bosch ; > Eugeniu Rosca ; Gabbasov, Andrew > > Subject: [PATCH net] ravb: Fix bit fields checking in ravb_hwtstamp_get() > > In the function ravb_hwtstamp_get() in ravb_main.c with the existing values > for RAVB_RXTSTAMP_TYPE_V2_L2_EVENT (0x2) and RAVB_RXTSTAMP_TYPE_ALL > (0x6) > > if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_V2_L2_EVENT) > config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; > else if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_ALL) > config.rx_filter = HWTSTAMP_FILTER_ALL; > > if the test on RAVB_RXTSTAMP_TYPE_ALL should be true, it will never be > reached. > > This issue can be verified with 'hwtstamp_config' testing program > (tools/testing/selftests/net/hwtstamp_config.c). Setting filter type to ALL > and subsequent retrieving it gives incorrect value: > > $ hwtstamp_config eth0 OFF ALL > flags = 0 > tx_type = OFF > rx_filter = ALL > $ hwtstamp_config eth0 > flags = 0 > tx_type = OFF > rx_filter = PTP_V2_L2_EVENT > > Correct this by converting if-else's to switch. Earlier you proposed to fix this issue by changing the value of RAVB_RXTSTAMP_TYPE_ALL constant to 0x4. Unfortunately, simple changing of the constant value will not be enough, since the code in ravb_rx() (actually determining if timestamp is needed) u32 get_ts = priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE; [...] get_ts &= (q == RAVB_NC) ? RAVB_RXTSTAMP_TYPE_V2_L2_EVENT : ~RAVB_RXTSTAMP_TYPE_V2_L2_EVENT; will work incorrectly and will need to be fixed too, making this piece of code more complicated. So, it's probably easier and safer to keep the constant value and the code in ravb_rx() intact, and just fix the get ioctl code, where the issue is actually located. Thanks! Best regards, Andrew > > Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper") > Reported-by: Julia Lawall > Signed-off-by: Andrew Gabbasov > --- > drivers/net/ethernet/renesas/ravb_main.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/renesas/ravb_main.c > b/drivers/net/ethernet/renesas/ravb_main.c > index df89d09b253e..c0610b2d3b14 100644 > --- a/drivers/net/ethernet/renesas/ravb_main.c > +++ b/drivers/net/ethernet/renesas/ravb_main.c > @@ -1802,12 +1802,16 @@ static int ravb_hwtstamp_get(struct net_device > *ndev, struct ifreq *req) > config.flags = 0; > config.tx_type = priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON : > HWTSTAMP_TX_OFF; > - if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_V2_L2_EVENT) > + switch (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE) { > + case RAVB_RXTSTAMP_TYPE_V2_L2_EVENT: > config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; > - else if (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE_ALL) > + break; > + case RAVB_RXTSTAMP_TYPE_ALL: > config.rx_filter = HWTSTAMP_FILTER_ALL; > - else > + break; > + default: > config.rx_filter = HWTSTAMP_FILTER_NONE; > + } > > return copy_to_user(req->ifr_data, &config, sizeof(config)) ? > -EFAULT : 0; > -- > 2.21.0