Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp249329rwd; Wed, 14 Jun 2023 15:29:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XoqcrO4wO0fWhHEiY76jduSK8SsVBqrvAyXZMsqR2TU4a0M0gsMcWHvVRdKNgfsZFo9KD X-Received: by 2002:a17:906:fe45:b0:974:6de:8a5e with SMTP id wz5-20020a170906fe4500b0097406de8a5emr15114214ejb.40.1686781743009; Wed, 14 Jun 2023 15:29:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1686781742; cv=pass; d=google.com; s=arc-20160816; b=NUe81vQUC/1z5yzdV4LE7iertsDdRqfkiX0xih+r9LpdHBbw688IeIvJej64GfqFqE oR5S831MJOw9dDhreuZqojutJPuQvrcx1cksDkE2agrjSlfbQjpTQD3v/SCxar5nUP0m SGw7/XCzhV8sscilHdY1T0A1zRYe9EwRGigRj6rXkDbzvVyiDWON14/4xP44CvWCVS3F Jv34JWrZM7ILePVuYd1u/otishqHEC9hJYLlztn+3R3WPi13DFa6322w4dw+soWkBpMX hP+itKmBVqjUqY3OfnZCOu/Lh/CGrirrbf9sQ05U35UOtfU5bCEfB757PugbI4YVUGQa IOjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PD6bHiewSN3Ci+VbGmOoIp99tKqbzeYQt6uCW9FkYdA=; b=yWyPN5JsQtq5TrvahPHFqkCZiUovAWkStJULXPIhse+zDF6wFyRsK3yEFucqqf3sy6 hOYWY4qhglA/LcI7iE6vqyDK6o7lqe1QapzgSOh+1x79zb0rbwEGpzj5fcOrdBiMI2OI A0ERU4amiIYe0dqNIlWwCCy4FitU+gk+ePCqTfyUUyM2EWWRQ+jA8/4eBU/ZLpkp8dq3 PHhm3vjw/WGOoySDw+vuN1sRv/t882UvTRbkXXmxaJNM7MmUqpAbo8OO6CZQll7K85bB Cp0/2/kUWzEg20K4HV8Oub1ajRpmhz1C5ojSldomzIAgZTMh5KvX0LpgAApM7mwg5Reb NxIg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=RgIxq2gD; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kl7-20020a170907994700b0097873b70a8bsi6029184ejc.343.2023.06.14.15.28.38; Wed, 14 Jun 2023 15:29:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=RgIxq2gD; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232518AbjFNWRi (ORCPT + 99 others); Wed, 14 Jun 2023 18:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbjFNWRd (ORCPT ); Wed, 14 Jun 2023 18:17:33 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2071.outbound.protection.outlook.com [40.107.7.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3274F2689; Wed, 14 Jun 2023 15:17:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QBUigyxq7u/5/lJg/yszUZg7iOQljI+xmdg7Fko7b727nbng1flVcypVNycHG1hokXRniP/wTKVpOLOkfEE+yqRwSb6IlqLNYmA1uHAYy76/JO3PqSJGt4SltFpfLKAAKrIkJArO/xOxY8KnkYuXxdtAV/5DpPe8vZPf1c1EwD5QAh1pdnmy0b0pT1IR/zGaFJiqKfn6JObx3JhJcFSPW5YPefVxnMi9Og0SIi9y8ZAWZCO1sOMFJPVgAWv/3g94eMr8dC38fOfHVbnc3vk07nAzO1SpSJ8RgOm7LB6reg41WFvT8ms7fs+nOC1HF8bYeRa5d8gE3D2sp1lls7Ra6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PD6bHiewSN3Ci+VbGmOoIp99tKqbzeYQt6uCW9FkYdA=; b=lMqxZe8+UZZBbyezVs3UMudwrSZ0WudRDbpLiMxf6MORuRdXcYswFeGK+AkjXaeNrfF4TrBdYetRZYmvzVB45bzQ3mxkBhxUx8pspLKpgXyI0h3IvHyTpVNCv+f10aFHHpQAAmu1NNkPbK3+BfvHEPUtJQjjGUHH9LUK0giUNit6TMXuNDSlhC3rL09KiZo0UHP9zpUvB7o5CIhuXGnu/AfDpF8Cjbkys8VqqP4SQuAz7yMZw15YfsRR8QceBBGJHFrWis7NvyooNRglPJJH6nvmvQ1ggY8em4PCXWv39QosspiOGrpRrOi+W75DHP9GNMSkmyD6AR2aaDA4t5fsKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PD6bHiewSN3Ci+VbGmOoIp99tKqbzeYQt6uCW9FkYdA=; b=RgIxq2gDu6xtnASz1Lw9fBz4bLfSsam19QQL9khc3lSALRuWdHC74mMQCkRZ9N8zYa/h4yAiXPKhCye4rtTKPcg07S2yuBM9vBjZsKfjL8+lLEojpjPbzBNOA1hrP09MaE8T3pbuzKeSEs7uqwHRL84DWLtsV/Z0xWahMM/Zt2M= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AS8PR04MB8372.eurprd04.prod.outlook.com (2603:10a6:20b:3b3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Wed, 14 Jun 2023 22:17:22 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c40e:d76:fd88:f460]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::c40e:d76:fd88:f460%4]) with mapi id 15.20.6455.045; Wed, 14 Jun 2023 22:17:22 +0000 Date: Thu, 15 Jun 2023 01:17:18 +0300 From: Vladimir Oltean To: Simon Horman Cc: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vinicius Costa Gomes , linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Muhammad Husaini Zulkifli , Peilin Ye , Pedro Tammela , Richard Cochran , Zhengchao Shao , Maxim Georgiev Subject: Re: [PATCH v2 net-next 6/9] net: netdevsim: create a mock-up PTP Hardware Clock driver Message-ID: <20230614221718.cx6yjiwrpik4iesw@skbuf> References: <20230613215440.2465708-1-vladimir.oltean@nxp.com> <20230613215440.2465708-7-vladimir.oltean@nxp.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: AM0PR10CA0088.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:15::41) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AS8PR04MB8372:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cb55c63-7b23-4a8d-0d8a-08db6d252015 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VOtfXrx9bzg8tsOs1Cm2qiymes3hrixhjYXTNdIUBFhG7bmjsULogVeH8MkGo9rLvoXhGsi2dKimZHCMq8xTKUcga5pEVpzqnjorD76X2eOwh8oIy0jJBOLAxJ4lMv8Pa5kc8tLe+fJj+CmGzjADz/o+Hg2joXqvZC6/aWgWC8MEnByjegnupYzuJJyaE5y2WyNFKQuqQvJqHmlfidAycq319YMdPPAZlUaDyUkjXxw9si/2kjTbrR6l56Q9JeEns0yegF+ODD2ihllhFQJVaEsJemk3rBgR26NNPtNHDztpWziiYXZIL9ralZGm4j3U5AKa/98McN6gpRlw4WcYTToscoXW1qUtWoEVOT0CCc4Ju9v9ix/9GCjp7mb61UzhffBdna7yh949VTI2sW4rqwGH6sjU/ziIyLqsCkhd7IWEOvc56RVsZZI9Mwrdbm75UN028TJqofoeJaD4Opx1J/vyb7o8OsUDidC0vqlwDky9DCxU9Pz1J3dC9adsAHs+GZC2FqgMWm05EeYmfmttZWdAiUuQgY1AaaTZhEvfWiAIMu7V4g2EnqYMK7hgq+Cg X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(7916004)(4636009)(39860400002)(136003)(376002)(346002)(366004)(396003)(451199021)(44832011)(2906002)(33716001)(86362001)(7416002)(6486002)(83380400001)(6666004)(186003)(6506007)(26005)(1076003)(9686003)(6512007)(54906003)(6916009)(66946007)(66556008)(4326008)(66476007)(5660300002)(316002)(38100700002)(8676002)(8936002)(41300700001)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?QQ7LnsJlyIZW80hC4wfNq099jmrHEto2pdL9qfOJAKc2ULn3qb34nooKUF/R?= =?us-ascii?Q?04FafX4KNyJiG036XiZsKyTlvICBApJIDO0KktLCnhVhGc6QK2cZxKhOrilq?= =?us-ascii?Q?dlskHjoXt/wCCnPaanmIEV3i9OBqxUi/5hSqHANLHkYbSLvoyr3xpVBXljAH?= =?us-ascii?Q?EoiSk9G2tDE7qoWzyAF0dynVjrICYa09/++/6c63NLB7nx9E7F/dGog7EXl1?= =?us-ascii?Q?qJaQijpvR2Gu4PbaZ1lK1sXtka5gUQvMeyL4SMcJsbChCY8/fjtv5BICC7P1?= =?us-ascii?Q?LZm8nRRKV6KkCu/pVSh9iqkQnBeY9V81Btmlb+Wx582djhLGl3p+51i5T7Nb?= =?us-ascii?Q?lVXGgFcbD8iKi68U6m1FIqJwkPPvbSXqtGFJqQJ5Hq3MugfyDfHRD5Cbh+pf?= =?us-ascii?Q?8pi7FahAEAJKmUcCU6c42Ym57b43eUQzhu0fLvL9QFLH3cHMRbdWY/Mu99tG?= =?us-ascii?Q?fgVA7fjOMPcZZHUBxL6lf1gUmUI0L/gKlAy8+8qZf7sK09u2kFFC34KS3q9n?= =?us-ascii?Q?+xJQMpl24n5wIsJcMtLRqbZM+Xp/V4RSdZRulOJg93N+abFvkTjbwh16kBJo?= =?us-ascii?Q?/PZjiFkdRfCVMD7l2Ng3jDUBvOCX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?= =?us-ascii?Q?yzI7KYvGLCcplaU2fT+j11rdiUy071J7wHPHVVLk1GZ/NTzoj/YAb6ISxJKQ?= =?us-ascii?Q?rHVgXBDuMBt6lupDNpzRLvOqrQTPE+YSokWa5CZWYawwG9oNcu1djOWCF+bP?= =?us-ascii?Q?HQ=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6cb55c63-7b23-4a8d-0d8a-08db6d252015 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2023 22:17:22.4560 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ExzT80Kpz3B94+iSKnAF4ukZgFK/OvJ4hc2nbWicNnJ51ZzypSyaYnE6hRWjZCPiwuKCQE3TJJUgbzDrAemI2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8372 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham 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 Hi Simon, On Wed, Jun 14, 2023 at 03:11:44PM +0200, Simon Horman wrote: > > +#define MOCK_PHC_CC_SHIFT 31 > > +#define MOCK_PHC_CC_MULT (1 << MOCK_PHC_CC_SHIFT) > > Maybe BIT()? Sorry, not everything that is 1 << something has BIT() semantics. This in particular is quite clearly just a multiplier factor expressed as a power of 2. > > +struct mock_phc *mock_phc_create(struct device *dev) > > +{ > > + struct mock_phc *phc; > > + int err; > > + > > + phc = kzalloc(sizeof(*phc), GFP_KERNEL); > > + if (!phc) { > > + err = -ENOMEM; > > + goto out; > > + } > > + > > + phc->info = (struct ptp_clock_info) { > > + .owner = THIS_MODULE, > > + .name = "Mock-up PTP clock", > > + .max_adj = MOCK_PHC_MAX_ADJ_PPB, > > + .adjfine = mock_phc_adjfine, > > + .adjtime = mock_phc_adjtime, > > + .gettime64 = mock_phc_gettime64, > > + .settime64 = mock_phc_settime64, > > + .do_aux_work = mock_phc_refresh, > > + }; > > + > > + phc->cc = (struct cyclecounter) { > > + .read = mock_phc_cc_read, > > + .mask = CYCLECOUNTER_MASK(64), > > + .mult = MOCK_PHC_CC_MULT, > > + .shift = MOCK_PHC_CC_SHIFT, > > + }; > > + > > + spin_lock_init(&phc->lock); > > + timecounter_init(&phc->tc, &phc->cc, 0); > > + > > + phc->clock = ptp_clock_register(&phc->info, dev); > > + if (IS_ERR_OR_NULL(phc->clock)) { > > + err = PTR_ERR_OR_ZERO(phc->clock); > > + goto out_free_phc; > > + } > > + > > + ptp_schedule_worker(phc->clock, MOCK_PHC_REFRESH_INTERVAL); > > + > > + return phc; > > + > > +out_free_phc: > > + kfree(phc); > > +out: > > + return ERR_PTR(err); > > +} > > Smatch complains that ERR_PTR may be passed zero. > Looking at the IS_ERR_OR_NULL block above, this does indeed seem to be the > case. The intention here had something to do with PTP being optional for the caller (netdevsim). Not sure whether the implementation is the best - and in particular whether ERR_PTR(0) is NULL or not. I guess this is what the smatch warning (which I haven't looked at) is saying. > Keeping Smatch happy is one thing - your call - but I do wonder if the > caller of mock_phc_create() handles the NULL case correctly. mock_phc_create() returns a pointer to an opaque data structure - struct mock_phc - and the caller just carries that pointer around to the other API calls exported by the mock_phc module. It doesn't need to care whether the pointer is NULL or not, just the mock_phc module does (and it does handle that part well, at least assuming that the pointer is NULL).