From patchwork Tue Nov 8 03:57:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Mailhol X-Patchwork-Id: 16854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2471798wru; Mon, 7 Nov 2022 20:10:51 -0800 (PST) X-Google-Smtp-Source: AMsMyM6TDg6EpTQl8+IruoiG39UaMZnpnWPE0LkKKuej+hyjI/gI205W83C8RJ+vsf6Tb1RRkXFY X-Received: by 2002:a65:5583:0:b0:461:25fe:e982 with SMTP id j3-20020a655583000000b0046125fee982mr46262780pgs.4.1667880651214; Mon, 07 Nov 2022 20:10:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667880651; cv=none; d=google.com; s=arc-20160816; b=rQ7ucaXfcCzq5RX3OxY3o0NHPLqbyMHyGD6skrQ/a9AJMj2tJ6gmzyamoUfh+8OLKr FIN12UcDJIorOSwSa+ilgJQBZEoASxiYJmvjB4c9TF3i/YdhoMA51aUgVICXzrf+06o6 KdO3iYlQtGxxK2hA16V7WaT7/Pb5TnAAzHNCKWbgPPOQhAv2ITxoYe/T9+Ze9aPYroNX NxXkr8tuSakh22lJhMucO4cVPKi/QtssuQqqwQpOD0Z7uXurwmdDB+LbHAH8L6ux694f cjjVueoUcAIdKc5PzqSiTeHj0uVLTOfrHQbgvYWEGhqdBHUC9DCwnhFO1Sh9x2GG70Rb jlLA== 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 :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=3w2NZSwyPPI/Z7ZkFiZmUgxVMdr3WnPezn9G8jIb89k=; b=n0kl72dXSAiY6NbkKAimk0ikJKxdOZ5hSAoCRiAwAYOfo0hW3KGXKHPC1NAeYc/U9B HAAm2spj3g4xL1WG6hycXZ5kddA2Y1/5dIWW0rG/LnOP1JMUetMdILt08bIWwQN/gMdp nWMwllQhtOT4FCTJur/yayZtOWhmlaiLny1sY0ZHJWesxRy89RlBgFfehPNu9J1U6K4A m70/vO26IvUCg7dsKAc/XKVeOwHReQl7l1PHTlrd+F8luLCEHJ8yukqEa4BMIDTXNHs4 4IMfDauEIdVf2eUxriBuMEYmCI3oyNLOwBefd4U7LD8bcnO0iSgJ4GKpS5OQqOpqiMF0 UHPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=X7mu302r; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mn1-20020a17090b188100b00213193da68csi15504712pjb.139.2022.11.07.20.10.36; Mon, 07 Nov 2022 20:10:51 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=X7mu302r; 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 S233262AbiKHD6Z (ORCPT + 99 others); Mon, 7 Nov 2022 22:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232884AbiKHD6P (ORCPT ); Mon, 7 Nov 2022 22:58:15 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DDDA31F8D; Mon, 7 Nov 2022 19:58:09 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id 4so13118125pli.0; Mon, 07 Nov 2022 19:58:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=3w2NZSwyPPI/Z7ZkFiZmUgxVMdr3WnPezn9G8jIb89k=; b=X7mu302r89riVzCOc5c+QGr3J3ji059SuTRG+TJx6kuVWDrRW3lv3gkTC1uHEyPpyH PHxhlYGHktePLoMIyLJ4LsQEJdnsyZDw5+QbG9MG77UD8wLMi2yQ322T6jcOjm3wIYD9 xxcoPXaBe8lj6/jl2fcEWFiv9HEiTyd7lGLqNHXxSMEeUnqYk5i/EhLMyBrFa4imTFNX ZvJrth5PYo27TsjmYXAwfdifsW92nn597nk4qKi03oboTpck1Nk3+L8uaWOeMgktd4fi cbrPEjgkiST2oGWIRnuFroFS3PGiAA7VwzeuuVKgYCPeXgEuZ45LjmoLlT21LFc2tlRi G2oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3w2NZSwyPPI/Z7ZkFiZmUgxVMdr3WnPezn9G8jIb89k=; b=uXzaVUi58lkypRXSbgtmwvzMhrpt3de4i1Vq9k+rVdSP15gUzTDZG6z+XZRXSXBVsv hpFReGTi4HJeVeMjGkisP4xX0zszL3aE7onNK2iodEreVNZuBtNtalaofoLai/hR/RKR bzyHenMczemuhQCiKG2SHL5s4DVQDqxKKIxcGnh/7mt3x/mqAhQIArGpjMtEcpXyR+nY hZXS+Cl9Bm7D94AfJ8jdTTDpGoYQKRitKR4FuY2nwI/U9D9VdCzm4vBU8Jpj28AzAynL k6B6Bs0uik0Op2GX2n0O7rJZDEuI+dxXo+bAPmMbtsdMQs/re6ec7fYEucO2Q8IpSP83 ccPw== X-Gm-Message-State: ACrzQf2Qkpc+YtkVJflO2VVzbO4VsgaBbnSeifYMSW6uDie95PqTsIgE yqCS1gz/JczhSDg6ziY+NKkx32C2AiosrQ== X-Received: by 2002:a17:90b:1a84:b0:213:e8b5:2d16 with SMTP id ng4-20020a17090b1a8400b00213e8b52d16mr45255481pjb.9.1667879888388; Mon, 07 Nov 2022 19:58:08 -0800 (PST) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id s5-20020a170903200500b00172cb8b97a8sm5785105pla.5.2022.11.07.19.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 19:58:08 -0800 (PST) Sender: Vincent Mailhol From: Vincent Mailhol To: netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Guangbin Huang , Hao Chen , Sean Anderson , Tom Rix , Tonghao Zhang , Wolfram Sang , Marco Bonelli , linux-kernel@vger.kernel.org, Vincent Mailhol Subject: [PATCH net-next v1] ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits Date: Tue, 8 Nov 2022 12:57:54 +0900 Message-Id: <20221108035754.2143-1-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.37.4 MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748899621262008674?= X-GMAIL-MSGID: =?utf-8?q?1748899621262008674?= If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields. However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself. Allow the driver to leave those two fields empty and populate them in such case. This way, the driver can rely on the default values for the name and the bus_info. If the driver provides values, do nothing. Signed-off-by: Vincent Mailhol --- net/ethtool/ioctl.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 57e7238a4136..546f931c3b6c 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -713,15 +713,22 @@ static int ethtool_get_drvinfo(struct net_device *dev, struct ethtool_devlink_compat *rsp) { const struct ethtool_ops *ops = dev->ethtool_ops; + struct device *parent = dev->dev.parent; rsp->info.cmd = ETHTOOL_GDRVINFO; strscpy(rsp->info.version, UTS_RELEASE, sizeof(rsp->info.version)); if (ops->get_drvinfo) { ops->get_drvinfo(dev, &rsp->info); - } else if (dev->dev.parent && dev->dev.parent->driver) { - strscpy(rsp->info.bus_info, dev_name(dev->dev.parent), + if (!rsp->info.bus_info[0] && parent) + strscpy(rsp->info.bus_info, dev_name(parent), + sizeof(rsp->info.bus_info)); + if (!rsp->info.driver[0] && parent && parent->driver) + strscpy(rsp->info.driver, parent->driver->name, + sizeof(rsp->info.driver)); + } else if (parent && parent->driver) { + strscpy(rsp->info.bus_info, dev_name(parent), sizeof(rsp->info.bus_info)); - strscpy(rsp->info.driver, dev->dev.parent->driver->name, + strscpy(rsp->info.driver, parent->driver->name, sizeof(rsp->info.driver)); } else if (dev->rtnl_link_ops) { strscpy(rsp->info.driver, dev->rtnl_link_ops->kind,