Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2895880rwb; Mon, 7 Nov 2022 20:28:23 -0800 (PST) X-Google-Smtp-Source: AMsMyM5X+E1WIRxFeqW1L8LUaOoY7tHDFXuza4RXgSlegbmpmyf4pi0DmrxeMnTkIxOcRfYc7Te8 X-Received: by 2002:a17:902:db02:b0:187:4736:f783 with SMTP id m2-20020a170902db0200b001874736f783mr33471759plx.155.1667881702813; Mon, 07 Nov 2022 20:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667881702; cv=none; d=google.com; s=arc-20160816; b=FY1IJHndLRroq0PWenAIjhKijZwHXuLsz94f5Vv/BOF0stAvSrmeYsVP+qCz6rpvIn PZCH1cgZArhDjpeaNIEeI0cbrhR2y1UEv9RTZwOhMSggXRKLgXKBbpiv0KMTIzsqkr8r /5lIs9QGiTKMe4rxNX0EkdWoBea5p1Uhr72NX4/7v6ZCC9NkChk3ePyzO00E13Es24O0 zEIp2uJFq+ncMLNtDuHc+zAGZNjOMIefwf1bfo8KtPS+VNoV2Dxp46uJcMMYSsyAY29M MwKU4P67dDB9RlCZ5fiXwkH7ti6xAYcBF06sfvnLs9eAfDkTZFQFJneoIACbJo4B4vyi opAw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 12-20020a63060c000000b0046af247a19asi13290298pgg.438.2022.11.07.20.28.11; Mon, 07 Nov 2022 20:28:22 -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 + 90 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 Content-Transfer-Encoding: 8bit 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 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, -- 2.37.4