Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7103717rwb; Wed, 23 Nov 2022 02:06:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ltV3H0ecufdMn9ELeJ1pl/SfQ3dTfl7NEVqOYQ4XoTVrXrp5Kn7BIEvmATaTFfWxMihL7 X-Received: by 2002:a17:906:2851:b0:78d:88c7:c1bf with SMTP id s17-20020a170906285100b0078d88c7c1bfmr7136322ejc.299.1669197986218; Wed, 23 Nov 2022 02:06:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669197986; cv=none; d=google.com; s=arc-20160816; b=VjngW3/ApMf0VcdTrkZtx+JOxJsL8AXduhe8RmZhVW4EZYD2UY9UF9/+Lq01BJrG4B NcT8rynI5bPfdIzPBXGS7daJC4yQX1QMc/ViNH1wryZruckBLF9t6qGifrzS10EZ/j6m 9z8h274dRNoeL6aFSVxymD6PSURE0N3NYfqjcQwjxC46Ya6f5vDU2q/KjY9UoOAX6k7p GKS8oGR+v9GUFhI2AvUoXzSCPCmfR263EfECYsrUuWyElWvMLW5vw7jW+/Se4+LEvOwU F14HNml/FpssZje5lnVg8BHETxpZ6o4lKdBTDNiGDj8ZlLegPof1pMGUhJIp+Shj35DO 9IWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=ctXaX1wsxi0J0COBH0p0jnAXJORMAFKcZCzCg0u1tEY=; b=nxN8F22UG0zFbMtmyyrw542vWxn/Eqztxcv+Ok/8n7A/B3GXuLRIdTexrqobxMqasL pd6bj3QQeewO9/eKY9jPDVfHA3yGZeYhgubAXPIcbvQ6c5QfV1idaCAnWfwfHNb6NyUl yqqKjz374Rsg6pcTAuymTSn4BwQ43ubiRXH1kikTO+6KRJpBuGsQuu1SNV4SL4artP5S 6Trmnzr0OQHo7H7TmLNS9QKtrSU0J6IgKlfRD637K2+opAbVGG7Aum155BHZ9m1Ouij9 W4uGLOt1Tiqbp9uJPahZVftMXNeYmW9cwF4azvXHlEfHghOx7XC0MkxiXCK3lKI63aEY DaRA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w13-20020a05640234cd00b0046775196bdesi14968717edc.29.2022.11.23.02.06.04; Wed, 23 Nov 2022 02:06:26 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238265AbiKWJpn (ORCPT + 88 others); Wed, 23 Nov 2022 04:45:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238181AbiKWJpK (ORCPT ); Wed, 23 Nov 2022 04:45:10 -0500 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 877A476148; Wed, 23 Nov 2022 01:42:53 -0800 (PST) Received: by mail-pl1-f176.google.com with SMTP id b21so16140518plc.9; Wed, 23 Nov 2022 01:42:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ctXaX1wsxi0J0COBH0p0jnAXJORMAFKcZCzCg0u1tEY=; b=M4JP5ePbWvzpfXGTnnNCOcaAfLUeqzsd1SEI1L2fhT5zNFqWodRbIETjnL1SzKv95V CUv4CM2puppXvgIrqGW20vAZx44PmShW8hWQuMDsYCfVlELMZQvhiqjbvkSOgH4R/MfE mbnAKS2VB1mm3NCgYYx9t1TvlA7fWGkW8Fc3d0zVCyQ/+UsP4zrtTpdZAYZsHRnATaaG 8buPOnW7YAy4UvfWHH0Mpa3eK8vYivUfXmUv797/hifIIynbN7SMORblAgiYrmiArfdQ kV5Uy9AzTgnF9BnH25qNuJBakXkFGxmanCCPN128ZGcFxaWHyXcDj8Hhx1DwHHgzMYYC xSEg== X-Gm-Message-State: ANoB5pnQwtVluGhZCgkoPZW3gCRQWHzkYRb4loWbXqqD/A8Ik3dwzqOP BeeypttvIqw1xTFCfMjsPpN/Be6fl7NcyTkJwM2PYOB1iRfb2Q== X-Received: by 2002:a17:90a:8a07:b0:20a:c032:da66 with SMTP id w7-20020a17090a8a0700b0020ac032da66mr34830700pjn.19.1669196572798; Wed, 23 Nov 2022 01:42:52 -0800 (PST) MIME-Version: 1.0 References: <20221122154934.13937-1-mailhol.vincent@wanadoo.fr> <20221122201246.0276680f@kernel.org> In-Reply-To: <20221122201246.0276680f@kernel.org> From: Vincent MAILHOL Date: Wed, 23 Nov 2022 18:42:41 +0900 Message-ID: Subject: Re: [RFC PATCH] net: devlink: devlink_nl_info_fill: populate default information To: Jakub Kicinski Cc: Jiri Pirko , netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 On Wed. 23 Nov. 2022 at 13:12, Jakub Kicinski wrote: > On Wed, 23 Nov 2022 00:49:34 +0900 Vincent Mailhol wrote: > > static int > > devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, > > enum devlink_command cmd, u32 portid, > > u32 seq, int flags, struct netlink_ext_ack *extack) > > { > > struct devlink_info_req req = {}; > > + struct device *dev = devlink_to_dev(devlink); > > nit: longest to shortest lines I was not aware of this convention. Thanks for the hint. > > void *hdr; > > int err; > > > > @@ -6707,6 +6733,16 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink, > > if (err) > > goto err_cancel_msg; > > > > + err = devlink_nl_driver_info_get(dev->driver, &req); > > + if (err) > > + goto err_cancel_msg; > > won't this result in repeated attributes, potentially? You are right. It will because nla_put() doesn't check if an attribute already exists and unconditionally reserves new space: https://elixir.bootlin.com/linux/v6.0/source/lib/nlattr.c#L993 > Unlike ethtool which copies data into a struct devlink > adds an attribute each time you request. It does not override. > So we need to extend req with some tracking of whether driver > already put in the info in question I see three solutions: 1/ Do it in the core, clean up all drivers using devlink_info_driver_name_put() and make the function static (i.e. forbid the drivers to set the driver name themselves). N.B. This first solution does not work for devlink_info_serial_number_put() because the core will not always be able to provide a default value (e.g. my code only covers USB devices). 2/ Keep track of which attribute is already set (as you suggested). 3/ Do a function devlink_nl_info_fill_default() and let the drivers choose to either call that function or set the attributes themselves. I would tend to go with a mix of 1/ and 2/. What do you think? > > + if (!strcmp(dev->parent->type->name, "usb_device")) { > > + err = devlink_nl_usb_info_get(to_usb_device(dev->parent), &req); > > + if (err) > > + goto err_cancel_msg; > > + }