From patchwork Wed Jun 7 23:14:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13271451 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CFA53B3E0 for ; Wed, 7 Jun 2023 23:14:23 +0000 (UTC) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98DA71FE6 for ; Wed, 7 Jun 2023 16:14:21 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b04706c974so69280005ad.2 for ; Wed, 07 Jun 2023 16:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1686179661; x=1688771661; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7NbZJkoovS7AA6gY+e9BrRffVVRD72j+sh3759fnYJw=; b=aQ6mJwQEaruq0QEUx79w815jt9aFKM+y/P/bNkBhFbsteIiNpc/rWELC/rNqd1MKvc VhQZTOLAe+CxIBOZp0hw039ZU9O/wTKCPFl4d/oQTQalcFIwUcqui4P6mtDY6DNv36Cz kUjq4jX6LY3+oaEZt8W5pIz5xSOXdKXm8YxAE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686179661; x=1688771661; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7NbZJkoovS7AA6gY+e9BrRffVVRD72j+sh3759fnYJw=; b=WbE8t4ARKeVp0PlmVPRnFmZQRAPkngv7g1H+Ch89o1ir/BeoDsMWU3MJDaUPFIbQig ZFh8R97qPzQ6t9fcmPHtRs1npH1SjibbY9EG04NVsitjf+lATzYQyf1/5o2KT8/rNMD/ zTgWUluBuF+m7rYib/X/UeHbHuShrAJdaXuQHlDAdeIqlqy99n6PfNnhNbDZZXvZLr81 TN3BkIdErXmhicVyp5sBKcicR8+EM2c6cbAvIuSHhvJFa10J5OoYyJySTmZLDYeHomER yJMnYSFCW5KLSyM1bGlEOxCDcg+3abivPsg09GL6UZgvv5hV83ZEx5q1817/lOn4g59M +iSQ== X-Gm-Message-State: AC+VfDyoMhq1/vYyI3Wq1cvGZj1nCrXDq1TZDHCUOllM+h5KrmRZlRAC kw6Mcf/kDWis7PQ0S3QQPu7PqKcWpNjee8o2x49Gp2iFqakHXk21l3dY66WfOjffh8jKyMR/z5O fmEIsf598PpMLsC2oG/fOvWpK0RWOpPDdbQ01JP+c8NRnz15CzyW6hG643yWCwJNQWN5yqAFCy8 mzqW57GQ== X-Google-Smtp-Source: ACHHUZ5P1SYvSg4QHGDZ9GaL7pX6B7y5BCYVvjJR/8qJ0aMJBfYO0PkpLGdTfHMABLX6RWjoPuHGVQ== X-Received: by 2002:a17:902:c411:b0:1ac:5717:fd5 with SMTP id k17-20020a170902c41100b001ac57170fd5mr9331279plk.60.1686179660780; Wed, 07 Jun 2023 16:14:20 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id l13-20020a170903244d00b001ae4d4d2676sm16279pls.269.2023.06.07.16.14.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2023 16:14:20 -0700 (PDT) From: Justin Chen To: netdev@vger.kernel.org Cc: bcm-kernel-feedback-list@broadcom.com, florian.fainelli@broadcom.com, Justin Chen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Daniil Tatianin , Ido Schimmel , Marco Bonelli , Wolfram Sang , Jiri Pirko , Gal Pressman , Vincent Mailhol , Kuniyuki Iwashima , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 net-next] ethtool: ioctl: improve error checking for set_wol Date: Wed, 7 Jun 2023 16:14:11 -0700 Message-Id: <1686179653-29750-1-git-send-email-justin.chen@broadcom.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, MIME_HEADER_CTYPE_ONLY,MIME_NO_TEXT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED 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 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-Patchwork-Delegate: kuba@kernel.org The netlink version of set_wol checks for not supported wolopts and avoids setting wol when the correct wolopt is already set. If we do the same with the ioctl version then we can remove these checks from the driver layer. Reviewed-by: Simon Horman Signed-off-by: Justin Chen Reviewed-by: Florian Fainelli --- v2 - Return -EINVAL instead of -EOPNOTSUPP net/ethtool/ioctl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 6bb778e10461..37b582225854 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1436,15 +1436,25 @@ static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) static int ethtool_set_wol(struct net_device *dev, char __user *useraddr) { - struct ethtool_wolinfo wol; + struct ethtool_wolinfo wol, cur_wol; int ret; - if (!dev->ethtool_ops->set_wol) + if (!dev->ethtool_ops->get_wol || !dev->ethtool_ops->set_wol) return -EOPNOTSUPP; + memset(&cur_wol, 0, sizeof(struct ethtool_wolinfo)); + cur_wol.cmd = ETHTOOL_GWOL; + dev->ethtool_ops->get_wol(dev, &cur_wol); + if (copy_from_user(&wol, useraddr, sizeof(wol))) return -EFAULT; + if (wol.wolopts & ~cur_wol.supported) + return -EINVAL; + + if (wol.wolopts == cur_wol.wolopts) + return 0; + ret = dev->ethtool_ops->set_wol(dev, &wol); if (ret) return ret;